Show More
@@ -100,9 +100,9 b' def uncan(obj, g=None):' | |||
|
100 | 100 | elif isinstance(obj, CannedObject): |
|
101 | 101 | return obj.getObject(g) |
|
102 | 102 | elif isinstance(obj,dict): |
|
103 | return uncanDict(obj) | |
|
103 | return uncanDict(obj, g) | |
|
104 | 104 | elif isinstance(obj, (list,tuple)): |
|
105 | return uncanSequence(obj) | |
|
105 | return uncanSequence(obj, g) | |
|
106 | 106 | else: |
|
107 | 107 | return obj |
|
108 | 108 |
@@ -201,7 +201,7 b' class TaskRejectError(KernelError):' | |||
|
201 | 201 | """ |
|
202 | 202 | |
|
203 | 203 | |
|
204 |
class CompositeError( |
|
|
204 | class CompositeError(RemoteError): | |
|
205 | 205 | """Error for representing possibly multiple errors on engines""" |
|
206 | 206 | def __init__(self, message, elist): |
|
207 | 207 | Exception.__init__(self, *(message, elist)) |
@@ -215,7 +215,7 b' class CompositeError(KernelError):' | |||
|
215 | 215 | if not ei: |
|
216 | 216 | return '[Engine Exception]' |
|
217 | 217 | else: |
|
218 |
return '[% |
|
|
218 | return '[%s:%s]: ' % (ei['engineid'], ei['method']) | |
|
219 | 219 | |
|
220 | 220 | def _get_traceback(self, ev): |
|
221 | 221 | try: |
@@ -256,10 +256,7 b' class CompositeError(KernelError):' | |||
|
256 | 256 | except: |
|
257 | 257 | raise IndexError("an exception with index %i does not exist"%excid) |
|
258 | 258 | else: |
|
259 | try: | |
|
260 | raise RemoteError(en, ev, etb, ei) | |
|
261 | except: | |
|
262 | et,ev,tb = sys.exc_info() | |
|
259 | raise RemoteError(en, ev, etb, ei) | |
|
263 | 260 | |
|
264 | 261 | |
|
265 | 262 | def collect_exceptions(rdict_or_list, method='unspecified'): |
@@ -290,6 +287,6 b" def collect_exceptions(rdict_or_list, method='unspecified'):" | |||
|
290 | 287 | # instance (e in this case) |
|
291 | 288 | try: |
|
292 | 289 | raise CompositeError(msg, elist) |
|
293 |
except CompositeError |
|
|
290 | except CompositeError as e: | |
|
294 | 291 | raise e |
|
295 | 292 |
@@ -8,9 +8,10 b' from zmq.tests import BaseZMQTestCase' | |||
|
8 | 8 | |
|
9 | 9 | from IPython.external.decorator import decorator |
|
10 | 10 | |
|
11 | from IPython.zmq.parallel import error | |
|
12 | from IPython.zmq.parallel.client import Client | |
|
11 | 13 | from IPython.zmq.parallel.ipcluster import launch_process |
|
12 | 14 | from IPython.zmq.parallel.entry_point import select_random_ports |
|
13 | from IPython.zmq.parallel.client import Client | |
|
14 | 15 | from IPython.zmq.parallel.tests import processes,add_engine |
|
15 | 16 | |
|
16 | 17 | # simple tasks for use in apply tests |
@@ -70,6 +71,16 b' class ClusterTestCase(BaseZMQTestCase):' | |||
|
70 | 71 | self.sockets.append(getattr(c, name)) |
|
71 | 72 | return c |
|
72 | 73 | |
|
74 | def assertRaisesRemote(self, etype, f, *args, **kwargs): | |
|
75 | try: | |
|
76 | f(*args, **kwargs) | |
|
77 | except error.CompositeError as e: | |
|
78 | e.raise_exception() | |
|
79 | except error.RemoteError as e: | |
|
80 | self.assertEquals(etype.__name__, e.ename, "Should have raised %r, but raised %r"%(e.ename, etype.__name__)) | |
|
81 | else: | |
|
82 | self.fail("should have raised a RemoteError") | |
|
83 | ||
|
73 | 84 | def setUp(self): |
|
74 | 85 | BaseZMQTestCase.setUp(self) |
|
75 | 86 | self.client = self.connect_client() |
@@ -44,10 +44,13 b' class TestClient(ClusterTestCase):' | |||
|
44 | 44 | v = self.client[:-3] |
|
45 | 45 | self.assert_(isinstance(v, DirectView)) |
|
46 | 46 | self.assertEquals(v.targets, targets[:-3]) |
|
47 | v = self.client[-1] | |
|
48 | self.assert_(isinstance(v, DirectView)) | |
|
49 | self.assertEquals(v.targets, targets[-1]) | |
|
47 | 50 | nt.assert_raises(TypeError, lambda : self.client[None]) |
|
48 | 51 | |
|
49 | 52 | def test_view_cache(self): |
|
50 | """test blocking and non-blocking behavior""" | |
|
53 | """test that multiple view requests return the same object""" | |
|
51 | 54 | v = self.client[:2] |
|
52 | 55 | v2 =self.client[:2] |
|
53 | 56 | self.assertTrue(v is v2) |
@@ -65,6 +68,7 b' class TestClient(ClusterTestCase):' | |||
|
65 | 68 | # self.client.push() |
|
66 | 69 | |
|
67 | 70 | def test_push_pull(self): |
|
71 | """test pushing and pulling""" | |
|
68 | 72 | data = dict(a=10, b=1.05, c=range(10), d={'e':(1,2),'f':'hi'}) |
|
69 | 73 | self.add_engines(4) |
|
70 | 74 | push = self.client.push |
@@ -89,6 +93,7 b' class TestClient(ClusterTestCase):' | |||
|
89 | 93 | self.assertEquals(r, nengines*[[10,20]]) |
|
90 | 94 | |
|
91 | 95 | def test_push_pull_function(self): |
|
96 | "test pushing and pulling functions" | |
|
92 | 97 | def testf(x): |
|
93 | 98 | return 2.0*x |
|
94 | 99 | |
@@ -112,6 +117,18 b' class TestClient(ClusterTestCase):' | |||
|
112 | 117 | execute("def g(x): return x*x", targets=0) |
|
113 | 118 | r = pull(('testf','g'),targets=0) |
|
114 | 119 | self.assertEquals((r[0](10),r[1](10)), (testf(10), 100)) |
|
115 |
|
|
|
120 | ||
|
121 | def test_push_function_globals(self): | |
|
122 | """test that pushed functions have access to globals""" | |
|
123 | def geta(): | |
|
124 | return a | |
|
125 | self.add_engines(1) | |
|
126 | v = self.client[-1] | |
|
127 | v.block=True | |
|
128 | v['f'] = geta | |
|
129 | self.assertRaisesRemote(NameError, v.execute, 'b=f()') | |
|
130 | v.execute('a=5') | |
|
131 | v.execute('b=f()') | |
|
132 | self.assertEquals(v['b'], 5) | |
|
116 | 133 | |
|
117 | 134 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now