Skip to content

Commit 2b14ad4

Browse files
author
Steve Canny
committed
img: add _MarkerFinder.from_stream()
1 parent b7d39cd commit 2b14ad4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

docx/image/jpeg.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,16 @@ class _MarkerFinder(object):
139139
"""
140140
Service class that knows how to find the next JFIF marker in a stream.
141141
"""
142+
def __init__(self, stream):
143+
super(_MarkerFinder, self).__init__()
144+
self._stream = stream
145+
142146
@classmethod
143147
def from_stream(cls, stream):
144148
"""
145149
Return a |_MarkerFinder| instance to find JFIF markers in *stream*.
146150
"""
147-
raise NotImplementedError
151+
return cls(stream)
148152

149153
def next(self, start):
150154
"""

tests/image/test_jpeg.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,29 @@ def stream_(self, request):
151151
return instance_mock(request, BytesIO)
152152

153153

154+
class Describe_MarkerFinder(object):
155+
156+
def it_can_construct_from_a_stream(self, from_stream_fixture):
157+
stream_, _MarkerFinder__init_ = from_stream_fixture
158+
marker_finder = _MarkerFinder.from_stream(stream_)
159+
_MarkerFinder__init_.assert_called_once_with(stream_)
160+
assert isinstance(marker_finder, _MarkerFinder)
161+
162+
# fixtures -------------------------------------------------------
163+
164+
@pytest.fixture
165+
def from_stream_fixture(self, stream_, _MarkerFinder__init_):
166+
return stream_, _MarkerFinder__init_
167+
168+
@pytest.fixture
169+
def _MarkerFinder__init_(self, request):
170+
return initializer_mock(request, _MarkerFinder)
171+
172+
@pytest.fixture
173+
def stream_(self, request):
174+
return instance_mock(request, BytesIO)
175+
176+
154177
class Describe_MarkerParser(object):
155178

156179
def it_can_construct_from_a_jfif_stream(self, from_stream_fixture):

0 commit comments

Comments
 (0)