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