|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +Test suite for docx.image.jpeg 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.jpeg import Jfif, _JfifMarkers |
| 13 | + |
| 14 | +from ..unitutil import class_mock, instance_mock |
| 15 | + |
| 16 | + |
| 17 | +class DescribeJfif(object): |
| 18 | + |
| 19 | + def it_can_construct_from_a_jfif_stream(self, from_stream_fixture): |
| 20 | + # fixture ---------------------- |
| 21 | + (stream_, blob_, filename_, _JfifMarkers_, px_width, px_height, |
| 22 | + horz_dpi, vert_dpi) = from_stream_fixture |
| 23 | + # exercise --------------------- |
| 24 | + jfif = Jfif.from_stream(stream_, blob_, filename_) |
| 25 | + # verify ----------------------- |
| 26 | + _JfifMarkers_.from_stream.assert_called_once_with(stream_) |
| 27 | + assert isinstance(jfif, Jfif) |
| 28 | + assert jfif.px_width == px_width |
| 29 | + assert jfif.px_height == px_height |
| 30 | + assert jfif.horz_dpi == horz_dpi |
| 31 | + assert jfif.vert_dpi == vert_dpi |
| 32 | + |
| 33 | + # fixtures ------------------------------------------------------- |
| 34 | + |
| 35 | + @pytest.fixture |
| 36 | + def blob_(self, request): |
| 37 | + return instance_mock(request, bytes) |
| 38 | + |
| 39 | + @pytest.fixture |
| 40 | + def filename_(self, request): |
| 41 | + return instance_mock(request, str) |
| 42 | + |
| 43 | + @pytest.fixture |
| 44 | + def from_stream_fixture( |
| 45 | + self, stream_, blob_, filename_, _JfifMarkers_, jfif_markers_): |
| 46 | + px_width, px_height = 111, 222 |
| 47 | + horz_dpi, vert_dpi = 333, 444 |
| 48 | + jfif_markers_.sof.px_width = px_width |
| 49 | + jfif_markers_.sof.px_height = px_height |
| 50 | + jfif_markers_.app0.horz_dpi = horz_dpi |
| 51 | + jfif_markers_.app0.vert_dpi = vert_dpi |
| 52 | + return ( |
| 53 | + stream_, blob_, filename_, _JfifMarkers_, px_width, px_height, |
| 54 | + horz_dpi, vert_dpi |
| 55 | + ) |
| 56 | + |
| 57 | + @pytest.fixture |
| 58 | + def _JfifMarkers_(self, request, jfif_markers_): |
| 59 | + _JfifMarkers_ = class_mock(request, 'docx.image.jpeg._JfifMarkers') |
| 60 | + _JfifMarkers_.from_stream.return_value = jfif_markers_ |
| 61 | + return _JfifMarkers_ |
| 62 | + |
| 63 | + @pytest.fixture |
| 64 | + def jfif_markers_(self, request): |
| 65 | + return instance_mock(request, _JfifMarkers) |
| 66 | + |
| 67 | + @pytest.fixture |
| 68 | + def stream_(self, request): |
| 69 | + return instance_mock(request, BytesIO) |
0 commit comments