##// END OF EJS Templates
fix iteration over Client...
MinRK -
Show More
@@ -921,7 +921,16 b' class Client(HasTraits):'
921 raise TypeError("key by int/slice/iterable of ints only, not %s"%(type(key)))
921 raise TypeError("key by int/slice/iterable of ints only, not %s"%(type(key)))
922 else:
922 else:
923 return self.direct_view(key)
923 return self.direct_view(key)
924
924
925 def __iter__(self):
926 """Since we define getitem, Client is iterable
927
928 but unless we also define __iter__, it won't work correctly unless engine IDs
929 start at zero and are continuous.
930 """
931 for eid in self.ids:
932 yield self.direct_view(eid)
933
925 #--------------------------------------------------------------------------
934 #--------------------------------------------------------------------------
926 # Begin public methods
935 # Begin public methods
927 #--------------------------------------------------------------------------
936 #--------------------------------------------------------------------------
@@ -41,6 +41,11 b' class TestClient(ClusterTestCase):'
41 self.add_engines(2)
41 self.add_engines(2)
42 self.assertEqual(len(self.client.ids), n+2)
42 self.assertEqual(len(self.client.ids), n+2)
43
43
44 def test_iter(self):
45 self.minimum_engines(4)
46 engine_ids = [ view.targets for view in self.client ]
47 self.assertEqual(engine_ids, self.client.ids)
48
44 def test_view_indexing(self):
49 def test_view_indexing(self):
45 """test index access for views"""
50 """test index access for views"""
46 self.minimum_engines(4)
51 self.minimum_engines(4)
General Comments 0
You need to be logged in to leave comments. Login now