|
12 | 12 | from docx.image.constants import MIME_TYPE, TAG |
13 | 13 | from docx.image.exceptions import InvalidImageStreamError |
14 | 14 | from docx.image.helpers import BIG_ENDIAN, StreamReader |
15 | | -from docx.image.png import Png, _PngParser |
| 15 | +from docx.image.png import _Chunks, Png, _PngParser |
16 | 16 |
|
17 | 17 | from ..unitutil import ( |
18 | 18 | initializer_mock, class_mock, instance_mock, method_mock, test_file |
@@ -249,3 +249,37 @@ def stream_(self, request): |
249 | 249 | @pytest.fixture |
250 | 250 | def stream_rdr_(self, request): |
251 | 251 | return instance_mock(request, StreamReader) |
| 252 | + |
| 253 | + |
| 254 | +class DescribePngParser(object): |
| 255 | + |
| 256 | + def it_can_parse_the_headers_of_a_PNG_stream(self, parse_fixture): |
| 257 | + stream_, _Chunks_, _PngParser__init_, chunks_ = parse_fixture |
| 258 | + png_parser = _PngParser.parse(stream_) |
| 259 | + _Chunks_.from_stream.assert_called_once_with(stream_) |
| 260 | + _PngParser__init_.assert_called_once_with(chunks_) |
| 261 | + assert isinstance(png_parser, _PngParser) |
| 262 | + |
| 263 | + # fixtures ------------------------------------------------------- |
| 264 | + |
| 265 | + @pytest.fixture |
| 266 | + def _Chunks_(self, request, chunks_): |
| 267 | + _Chunks_ = class_mock(request, 'docx.image.png._Chunks') |
| 268 | + _Chunks_.from_stream.return_value = chunks_ |
| 269 | + return _Chunks_ |
| 270 | + |
| 271 | + @pytest.fixture |
| 272 | + def chunks_(self, request): |
| 273 | + return instance_mock(request, _Chunks) |
| 274 | + |
| 275 | + @pytest.fixture |
| 276 | + def parse_fixture(self, stream_, _Chunks_, _PngParser__init_, chunks_): |
| 277 | + return stream_, _Chunks_, _PngParser__init_, chunks_ |
| 278 | + |
| 279 | + @pytest.fixture |
| 280 | + def _PngParser__init_(self, request): |
| 281 | + return initializer_mock(request, _PngParser) |
| 282 | + |
| 283 | + @pytest.fixture |
| 284 | + def stream_(self, request): |
| 285 | + return instance_mock(request, BytesIO) |
0 commit comments