##// END OF EJS Templates
Parallel: Support get/set of nested objects in view (e.g. dv['a.b'])
Bradley M. Froehle -
Show More
@@ -675,4 +675,22 b' class TestView(ClusterTestCase, ParametricTestCase):'
675 drank = amr.get(5)
675 drank = amr.get(5)
676 self.assertEqual(drank, [ r*2 for r in ranks ])
676 self.assertEqual(drank, [ r*2 for r in ranks ])
677
677
678 def test_nested_getitem_setitem(self):
679 """get and set with view['a.b']"""
680 view = self.client[-1]
681 view.execute('\n'.join([
682 'class A(object): pass',
683 'a = A()',
684 'a.b = 128',
685 ]), block=True)
686 ra = pmod.Reference('a')
687
688 r = view.apply_sync(lambda x: x.b, ra)
689 self.assertEqual(r, 128)
690 self.assertEqual(view['a.b'], 128)
691
692 view['a.b'] = 0
678
693
694 r = view.apply_sync(lambda x: x.b, ra)
695 self.assertEqual(r, 0)
696 self.assertEqual(view['a.b'], 0)
@@ -229,21 +229,24 b' def interactive(f):'
229 @interactive
229 @interactive
230 def _push(**ns):
230 def _push(**ns):
231 """helper method for implementing `client.push` via `client.apply`"""
231 """helper method for implementing `client.push` via `client.apply`"""
232 globals().update(ns)
232 user_ns = globals()
233 tmp = '_IP_PUSH_TMP_'
234 while tmp in user_ns:
235 tmp = tmp + '_'
236 try:
237 for name, value in ns.iteritems():
238 user_ns[tmp] = value
239 exec "%s = %s" % (name, tmp) in user_ns
240 finally:
241 user_ns.pop(tmp, None)
233
242
234 @interactive
243 @interactive
235 def _pull(keys):
244 def _pull(keys):
236 """helper method for implementing `client.pull` via `client.apply`"""
245 """helper method for implementing `client.pull` via `client.apply`"""
237 user_ns = globals()
238 if isinstance(keys, (list,tuple, set)):
246 if isinstance(keys, (list,tuple, set)):
239 for key in keys:
247 return map(lambda key: eval(key, globals()), keys)
240 if key not in user_ns:
241 raise NameError("name '%s' is not defined"%key)
242 return map(user_ns.get, keys)
243 else:
248 else:
244 if keys not in user_ns:
249 return eval(keys, globals())
245 raise NameError("name '%s' is not defined"%keys)
246 return user_ns.get(keys)
247
250
248 @interactive
251 @interactive
249 def _execute(code):
252 def _execute(code):
General Comments 0
You need to be logged in to leave comments. Login now