Skip to content

Commit e080a7d

Browse files
author
Steve Canny
committed
img: add _JfifMarkers.sof
1 parent 5307f22 commit e080a7d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

docx/image/jpeg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ def sof(self):
100100
"""
101101
First start of frame (SOFn) marker in this sequence.
102102
"""
103-
raise NotImplementedError
103+
for m in self._markers:
104+
if m.marker_code in JPEG_MARKER_CODE.SOF_MARKER_CODES:
105+
return m
106+
raise KeyError('no start of frame (SOFn) marker in image')
104107

105108

106109
class _MarkerParser(object):

tests/image/test_jpeg.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def it_raises_if_it_cant_find_the_APP0_marker(self, no_app0_fixture):
9797
with pytest.raises(KeyError):
9898
jfif_markers.app0
9999

100+
def it_can_find_the_SOF_marker(self, sof_fixture):
101+
jfif_markers, sof_ = sof_fixture
102+
sof = jfif_markers.sof
103+
assert sof is sof_
104+
105+
def it_raises_if_it_cant_find_the_SOF_marker(self, no_sof_fixture):
106+
jfif_markers = no_sof_fixture
107+
with pytest.raises(KeyError):
108+
jfif_markers.sof
109+
100110
# fixtures -------------------------------------------------------
101111

102112
@pytest.fixture
@@ -149,12 +159,23 @@ def no_app0_fixture(self, soi_, eoi_):
149159
markers = (soi_, eoi_)
150160
return _JfifMarkers(markers)
151161

162+
@pytest.fixture
163+
def no_sof_fixture(self, soi_, eoi_):
164+
markers = (soi_, eoi_)
165+
return _JfifMarkers(markers)
166+
152167
@pytest.fixture
153168
def sof_(self, request):
154169
return instance_mock(
155170
request, _SofMarker, marker_code=JPEG_MARKER_CODE.SOF0
156171
)
157172

173+
@pytest.fixture
174+
def sof_fixture(self, soi_, sof_, eoi_):
175+
markers = (soi_, sof_, eoi_)
176+
jfif_markers = _JfifMarkers(markers)
177+
return jfif_markers, sof_
178+
158179
@pytest.fixture
159180
def soi_(self, request):
160181
return instance_mock(

0 commit comments

Comments
 (0)