Skip to content

Commit 5307f22

Browse files
author
Steve Canny
committed
img: add _JfifMarkers.app0
1 parent 72145fe commit 5307f22

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎docx/image/jpeg.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ def app0(self):
9090
"""
9191
First APP0 marker in image markers.
9292
"""
93-
raise NotImplementedError
93+
for m in self._markers:
94+
if m.marker_code == JPEG_MARKER_CODE.APP0:
95+
return m
96+
raise KeyError('no APP0 marker in image')
9497

9598
@property
9699
def sof(self):

‎tests/image/test_jpeg.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ def it_can_construct_from_a_jfif_stream(self, from_stream_fixture):
8787
_JfifMarkers__init_.assert_called_once_with(marker_lst)
8888
assert isinstance(jfif_markers, _JfifMarkers)
8989

90+
def it_can_find_the_APP0_marker(self, app0_fixture):
91+
jfif_markers, app0_ = app0_fixture
92+
app0 = jfif_markers.app0
93+
assert app0 is app0_
94+
95+
def it_raises_if_it_cant_find_the_APP0_marker(self, no_app0_fixture):
96+
jfif_markers = no_app0_fixture
97+
with pytest.raises(KeyError):
98+
jfif_markers.app0
99+
90100
# fixtures -------------------------------------------------------
91101

92102
@pytest.fixture
@@ -95,6 +105,12 @@ def app0_(self, request):
95105
request, _App0Marker, marker_code=JPEG_MARKER_CODE.APP0
96106
)
97107

108+
@pytest.fixture
109+
def app0_fixture(self, soi_, app0_, eoi_):
110+
markers = (soi_, app0_, eoi_)
111+
jfif_markers = _JfifMarkers(markers)
112+
return jfif_markers, app0_
113+
98114
@pytest.fixture
99115
def eoi_(self, request):
100116
return instance_mock(
@@ -128,6 +144,11 @@ def _MarkerParser_(self, request, marker_parser_):
128144
def markers_all_(self, request, soi_, app0_, sof_, sos_, eoi_):
129145
return [soi_, app0_, sof_, sos_, eoi_]
130146

147+
@pytest.fixture
148+
def no_app0_fixture(self, soi_, eoi_):
149+
markers = (soi_, eoi_)
150+
return _JfifMarkers(markers)
151+
131152
@pytest.fixture
132153
def sof_(self, request):
133154
return instance_mock(

0 commit comments

Comments
 (0)