Skip to content

Commit 328f922

Browse files
author
Steve Canny
committed
add _SerializedRelationshipCollection.__iter__()
1 parent 04c8718 commit 328f922

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

opc/pkgreader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def __init__(self):
178178
super(_SerializedRelationshipCollection, self).__init__()
179179
self._srels = []
180180

181+
def __iter__(self):
182+
"""Support iteration, e.g. 'for x in srels:'"""
183+
return self._srels.__iter__()
184+
181185
@staticmethod
182186
def load_from_xml(baseURI, rels_item_xml):
183187
"""

tests/test_pkgreader.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,12 @@ def it_can_load_from_xml(self, oxml_fromstring, _SerializedRelationship_):
238238
oxml_fromstring.assert_called_once_with(rels_item_xml)
239239
assert _SerializedRelationship_.call_args_list == expected_calls
240240
assert isinstance(srels, _SerializedRelationshipCollection)
241+
242+
def it_should_be_iterable(self):
243+
srels = _SerializedRelationshipCollection()
244+
try:
245+
for x in srels:
246+
pass
247+
except TypeError:
248+
msg = "_SerializedRelationshipCollection object is not iterable"
249+
pytest.fail(msg)

0 commit comments

Comments
 (0)