|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +Test suite for docx.image.tiff module |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import absolute_import, print_function |
| 8 | + |
| 9 | +import pytest |
| 10 | + |
| 11 | +from docx.compat import BytesIO |
| 12 | +from docx.image.tiff import Tiff, _TiffParser |
| 13 | + |
| 14 | +from ..unitutil import class_mock, initializer_mock, instance_mock |
| 15 | + |
| 16 | + |
| 17 | +class DescribeTiff(object): |
| 18 | + |
| 19 | + def it_can_construct_from_a_tiff_stream(self, from_stream_fixture): |
| 20 | + (stream_, blob_, filename_, _TiffParser_, Tiff__init_, px_width, |
| 21 | + px_height, horz_dpi, vert_dpi) = from_stream_fixture |
| 22 | + tiff = Tiff.from_stream(stream_, blob_, filename_) |
| 23 | + _TiffParser_.parse.assert_called_once_with(stream_) |
| 24 | + Tiff__init_.assert_called_once_with( |
| 25 | + blob_, filename_, px_width, px_height, horz_dpi, vert_dpi |
| 26 | + ) |
| 27 | + assert isinstance(tiff, Tiff) |
| 28 | + |
| 29 | + # fixtures ------------------------------------------------------- |
| 30 | + |
| 31 | + @pytest.fixture |
| 32 | + def blob_(self, request): |
| 33 | + return instance_mock(request, bytes) |
| 34 | + |
| 35 | + @pytest.fixture |
| 36 | + def filename_(self, request): |
| 37 | + return instance_mock(request, str) |
| 38 | + |
| 39 | + @pytest.fixture |
| 40 | + def from_stream_fixture( |
| 41 | + self, stream_, blob_, filename_, _TiffParser_, tiff_parser_, |
| 42 | + Tiff__init_): |
| 43 | + px_width, px_height = 111, 222 |
| 44 | + horz_dpi, vert_dpi = 333, 444 |
| 45 | + tiff_parser_.px_width = px_width |
| 46 | + tiff_parser_.px_height = px_height |
| 47 | + tiff_parser_.horz_dpi = horz_dpi |
| 48 | + tiff_parser_.vert_dpi = vert_dpi |
| 49 | + return ( |
| 50 | + stream_, blob_, filename_, _TiffParser_, Tiff__init_, px_width, |
| 51 | + px_height, horz_dpi, vert_dpi |
| 52 | + ) |
| 53 | + |
| 54 | + @pytest.fixture |
| 55 | + def Tiff__init_(self, request): |
| 56 | + return initializer_mock(request, Tiff) |
| 57 | + |
| 58 | + @pytest.fixture |
| 59 | + def _TiffParser_(self, request, tiff_parser_): |
| 60 | + _TiffParser_ = class_mock(request, 'docx.image.tiff._TiffParser') |
| 61 | + _TiffParser_.parse.return_value = tiff_parser_ |
| 62 | + return _TiffParser_ |
| 63 | + |
| 64 | + @pytest.fixture |
| 65 | + def tiff_parser_(self, request): |
| 66 | + return instance_mock(request, _TiffParser) |
| 67 | + |
| 68 | + @pytest.fixture |
| 69 | + def stream_(self, request): |
| 70 | + return instance_mock(request, BytesIO) |
0 commit comments