Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Problem: CUDS.iter is broken. #294

Merged
merged 2 commits into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion simphony/cuds/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ def iter(self, component_type):
------
iterator over the components of the given type
"""
for component in self._store.itervalues():
values = None
if issubclass(component_type, (ABCParticles, ABCLattice, ABCMesh)):
values = self._dataset_store.iter_datasets()
else:
values = self._store.itervalues()

for component in values:
if isinstance(component, component_type):
yield component

Expand Down
23 changes: 19 additions & 4 deletions simphony/cuds/tests/test_cuds.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_get_names(self):
[self.dummpy_component1.name,
self.dummpy_component2.name])

def test_iter(self):
def test_iter_with_dataset(self):
p1 = Particle()
p2 = Particle()
p3 = Particle()
Expand All @@ -100,11 +100,26 @@ def test_iter(self):
ps2.add_particles([p3, p4])
self.cuds.add(ps1)
self.cuds.add(ps2)

cuds_list = []
for item in self.cuds.iter(Particles):
self.assertIn(item, [ps1, ps2])
cuds_list.append(item)

self.assertTrue(len(cuds_list), 2)

for cuds in cuds_list:
self.assertIsInstance(cuds, Particles)
self.assertIn(cuds, [ps1, ps2])

def test_iter_with_component(self):
self.cuds.add(self.dummpy_component1)
self.cuds.add(self.dummpy_component2)

component_list = []
for item in self.cuds.iter(type(self.dummpy_component1)):
self.assertIn(item, [self.dummpy_component1,
self.dummpy_component2])
component_list.append(item)

self.assertTrue(len(component_list), 2)
for cmp in component_list:
self.assertIn(cmp, [self.dummpy_component1,
self.dummpy_component2])