|
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 _Chunks, Png, _PngParser |
| 15 | +from docx.image.png import _Chunks, _ChunkParser, Png, _PngParser |
16 | 16 |
|
17 | 17 | from ..unitutil import ( |
18 | 18 | initializer_mock, class_mock, instance_mock, method_mock, test_file |
@@ -251,7 +251,7 @@ def stream_rdr_(self, request): |
251 | 251 | return instance_mock(request, StreamReader) |
252 | 252 |
|
253 | 253 |
|
254 | | -class DescribePngParser(object): |
| 254 | +class Describe_PngParser(object): |
255 | 255 |
|
256 | 256 | def it_can_parse_the_headers_of_a_PNG_stream(self, parse_fixture): |
257 | 257 | stream_, _Chunks_, _PngParser__init_, chunks_ = parse_fixture |
@@ -283,3 +283,45 @@ def _PngParser__init_(self, request): |
283 | 283 | @pytest.fixture |
284 | 284 | def stream_(self, request): |
285 | 285 | return instance_mock(request, BytesIO) |
| 286 | + |
| 287 | + |
| 288 | +class Describe_Chunks(object): |
| 289 | + |
| 290 | + def it_can_construct_from_a_stream(self, from_stream_fixture): |
| 291 | + stream_, _ChunkParser_, chunk_parser_, _Chunks__init_, chunk_lst = ( |
| 292 | + from_stream_fixture |
| 293 | + ) |
| 294 | + chunks = _Chunks.from_stream(stream_) |
| 295 | + _ChunkParser_.from_stream.assert_called_once_with(stream_) |
| 296 | + chunk_parser_.iter_chunks.assert_called_once_with() |
| 297 | + _Chunks__init_.assert_called_once_with(chunk_lst) |
| 298 | + assert isinstance(chunks, _Chunks) |
| 299 | + |
| 300 | + # fixtures ------------------------------------------------------- |
| 301 | + |
| 302 | + @pytest.fixture |
| 303 | + def from_stream_fixture( |
| 304 | + self, stream_, _ChunkParser_, chunk_parser_, _Chunks__init_): |
| 305 | + chunk_lst = [1, 2] |
| 306 | + chunk_parser_.iter_chunks.return_value = iter(chunk_lst) |
| 307 | + return ( |
| 308 | + stream_, _ChunkParser_, chunk_parser_, _Chunks__init_, chunk_lst |
| 309 | + ) |
| 310 | + |
| 311 | + @pytest.fixture |
| 312 | + def _ChunkParser_(self, request, chunk_parser_): |
| 313 | + _ChunkParser_ = class_mock(request, 'docx.image.png._ChunkParser') |
| 314 | + _ChunkParser_.from_stream.return_value = chunk_parser_ |
| 315 | + return _ChunkParser_ |
| 316 | + |
| 317 | + @pytest.fixture |
| 318 | + def chunk_parser_(self, request): |
| 319 | + return instance_mock(request, _ChunkParser) |
| 320 | + |
| 321 | + @pytest.fixture |
| 322 | + def _Chunks__init_(self, request): |
| 323 | + return initializer_mock(request, _Chunks) |
| 324 | + |
| 325 | + @pytest.fixture |
| 326 | + def stream_(self, request): |
| 327 | + return instance_mock(request, BytesIO) |
0 commit comments