|
17 | 17 | _App0Marker, _App1Marker, Exif, Jfif, _JfifMarkers, Jpeg, _Marker, |
18 | 18 | _MarkerFactory, _MarkerFinder, _MarkerParser, _SofMarker |
19 | 19 | ) |
| 20 | +from docx.image.tiff import Tiff |
20 | 21 |
|
21 | | -from ..unitutil import class_mock, initializer_mock, instance_mock |
| 22 | +from ..unitutil import ( |
| 23 | + initializer_mock, class_mock, instance_mock, method_mock |
| 24 | +) |
22 | 25 |
|
23 | 26 |
|
24 | 27 | class DescribeJpeg(object): |
@@ -347,6 +350,66 @@ def from_stream_fixture(self, request, _App0Marker__init_): |
347 | 350 | ) |
348 | 351 |
|
349 | 352 |
|
| 353 | +class Describe_App1Marker(object): |
| 354 | + |
| 355 | + def it_can_construct_from_a_stream_and_offset(self, from_stream_fixture): |
| 356 | + (stream, marker_code, offset, _App1Marker__init_, length, |
| 357 | + _tiff_from_exif_segment_, horz_dpi, vert_dpi) = from_stream_fixture |
| 358 | + app1_marker = _App1Marker.from_stream(stream, marker_code, offset) |
| 359 | + _tiff_from_exif_segment_.assert_called_once_with( |
| 360 | + stream, offset, length |
| 361 | + ) |
| 362 | + _App1Marker__init_.assert_called_once_with( |
| 363 | + marker_code, offset, length, horz_dpi, vert_dpi |
| 364 | + ) |
| 365 | + assert isinstance(app1_marker, _App1Marker) |
| 366 | + |
| 367 | + def it_can_construct_from_non_Exif_APP1_segment(self, non_Exif_fixture): |
| 368 | + stream, marker_code, offset = non_Exif_fixture[:3] |
| 369 | + _App1Marker__init_, length = non_Exif_fixture[3:] |
| 370 | + app1_marker = _App1Marker.from_stream(stream, marker_code, offset) |
| 371 | + _App1Marker__init_.assert_called_once_with( |
| 372 | + marker_code, offset, length, 72, 72 |
| 373 | + ) |
| 374 | + assert isinstance(app1_marker, _App1Marker) |
| 375 | + |
| 376 | + # fixtures ------------------------------------------------------- |
| 377 | + |
| 378 | + @pytest.fixture |
| 379 | + def _App1Marker__init_(self, request): |
| 380 | + return initializer_mock(request, _App1Marker) |
| 381 | + |
| 382 | + @pytest.fixture |
| 383 | + def from_stream_fixture( |
| 384 | + self, request, _App1Marker__init_, _tiff_from_exif_segment_): |
| 385 | + bytes_ = b'\x00\x42Exif\x00\x00' |
| 386 | + stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN) |
| 387 | + marker_code, offset, length = JPEG_MARKER_CODE.APP1, 0, 66 |
| 388 | + horz_dpi, vert_dpi = 42, 24 |
| 389 | + return ( |
| 390 | + stream_reader, marker_code, offset, _App1Marker__init_, length, |
| 391 | + _tiff_from_exif_segment_, horz_dpi, vert_dpi |
| 392 | + ) |
| 393 | + |
| 394 | + @pytest.fixture |
| 395 | + def non_Exif_fixture(self, request, _App1Marker__init_): |
| 396 | + bytes_ = b'\x00\x42Foobar' |
| 397 | + stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN) |
| 398 | + marker_code, offset, length = JPEG_MARKER_CODE.APP1, 0, 66 |
| 399 | + return stream_reader, marker_code, offset, _App1Marker__init_, length |
| 400 | + |
| 401 | + @pytest.fixture |
| 402 | + def tiff_(self, request): |
| 403 | + return instance_mock(request, Tiff, horz_dpi=42, vert_dpi=24) |
| 404 | + |
| 405 | + @pytest.fixture |
| 406 | + def _tiff_from_exif_segment_(self, request, tiff_): |
| 407 | + return method_mock( |
| 408 | + request, _App1Marker, '_tiff_from_exif_segment', |
| 409 | + return_value=tiff_ |
| 410 | + ) |
| 411 | + |
| 412 | + |
350 | 413 | class Describe_SofMarker(object): |
351 | 414 |
|
352 | 415 | def it_can_construct_from_a_stream_and_offset(self, from_stream_fixture): |
|
0 commit comments