Skip to content

Commit 9e0b5de

Browse files
authored
Merge pull request #78 from azavea/rde/fix/walk
Fix issue with iteration of children in catalog.walk
2 parents a5cdd64 + 4c04151 commit 9e0b5de

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

pystac/catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def walk(self):
475475
items = self.get_items()
476476

477477
yield (self, children, items)
478-
for child in children:
478+
for child in self.get_children():
479479
yield from child.walk()
480480

481481
def _object_links(self):

tests/test_catalog.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@ def test_clear_children_removes_from_cache(self):
104104
self.assertEqual(len(children), 1)
105105
self.assertEqual(children[0].description, 'test3')
106106

107+
def test_walk_iterates_correctly(self):
108+
catalogs = [
109+
TestCases.test_case_1(),
110+
TestCases.test_case_2(),
111+
TestCases.test_case_3()
112+
]
113+
114+
def test_catalog(cat):
115+
expected_catalog_iterations = 1
116+
actual_catalog_iterations = 0
117+
with self.subTest(title='Testing catalog {}'.format(cat.id)):
118+
for root, children, items in cat.walk():
119+
actual_catalog_iterations += 1
120+
expected_catalog_iterations += len(
121+
list(root.get_children()))
122+
123+
self.assertEqual(set([c.id for c in root.get_children()]),
124+
set([c.id for c in children]),
125+
'Children unequal')
126+
self.assertEqual(set([c.id for c in root.get_items()]),
127+
set([c.id for c in items]),
128+
'Items unequal')
129+
130+
self.assertEqual(actual_catalog_iterations,
131+
expected_catalog_iterations)
132+
133+
for cat in catalogs:
134+
test_catalog(cat)
135+
107136
def test_clone_generates_correct_links(self):
108137
catalogs = [
109138
TestCases.test_case_1(),

0 commit comments

Comments
 (0)