##// END OF EJS Templates
pyzmq-2.1.3 related testing adjustments
MinRK -
Show More
@@ -16,3 +16,8 b''
16 # from .remotefunction import *
16 # from .remotefunction import *
17 # from .view import *
17 # from .view import *
18
18
19 import zmq
20
21 if zmq.__version__ < '2.1.3':
22 raise ImportError("IPython.zmq.parallel requires pyzmq/0MQ >= 2.1.3, you appear to have %s"%zmq.__version__)
23
@@ -284,7 +284,7 b' class Client(HasTraits):'
284 ):
284 ):
285 super(Client, self).__init__(debug=debug, profile=profile)
285 super(Client, self).__init__(debug=debug, profile=profile)
286 if context is None:
286 if context is None:
287 context = zmq.Context()
287 context = zmq.Context.instance()
288 self._context = context
288 self._context = context
289
289
290
290
@@ -976,6 +976,10 b' class Client(HasTraits):'
976 returns actual result(s) of f(*args, **kwargs)
976 returns actual result(s) of f(*args, **kwargs)
977 if multiple targets:
977 if multiple targets:
978 list of results, matching `targets`
978 list of results, matching `targets`
979 track : bool
980 whether to track non-copying sends.
981 [default False]
982
979 targets : int,list of ints, 'all', None
983 targets : int,list of ints, 'all', None
980 Specify the destination of the job.
984 Specify the destination of the job.
981 if None:
985 if None:
@@ -986,34 +990,37 b' class Client(HasTraits):'
986 Run on each specified engine
990 Run on each specified engine
987 if int:
991 if int:
988 Run on single engine
992 Run on single engine
989
993 Note:
994 that if `balanced=True`, and `targets` is specified,
995 then the load-balancing will be limited to balancing
996 among `targets`.
997
990 balanced : bool, default None
998 balanced : bool, default None
991 whether to load-balance. This will default to True
999 whether to load-balance. This will default to True
992 if targets is unspecified, or False if targets is specified.
1000 if targets is unspecified, or False if targets is specified.
993
1001
994 The following arguments are only used when balanced is True:
1002 If `balanced` and `targets` are both specified, the task will
1003 be assigne to *one* of the targets by the scheduler.
1004
1005 The following arguments are only used when balanced is True:
1006
995 after : Dependency or collection of msg_ids
1007 after : Dependency or collection of msg_ids
996 Only for load-balanced execution (targets=None)
1008 Only for load-balanced execution (targets=None)
997 Specify a list of msg_ids as a time-based dependency.
1009 Specify a list of msg_ids as a time-based dependency.
998 This job will only be run *after* the dependencies
1010 This job will only be run *after* the dependencies
999 have been met.
1011 have been met.
1000
1012
1001 follow : Dependency or collection of msg_ids
1013 follow : Dependency or collection of msg_ids
1002 Only for load-balanced execution (targets=None)
1014 Only for load-balanced execution (targets=None)
1003 Specify a list of msg_ids as a location-based dependency.
1015 Specify a list of msg_ids as a location-based dependency.
1004 This job will only be run on an engine where this dependency
1016 This job will only be run on an engine where this dependency
1005 is met.
1017 is met.
1006
1018
1007 timeout : float/int or None
1019 timeout : float/int or None
1008 Only for load-balanced execution (targets=None)
1020 Only for load-balanced execution (targets=None)
1009 Specify an amount of time (in seconds) for the scheduler to
1021 Specify an amount of time (in seconds) for the scheduler to
1010 wait for dependencies to be met before failing with a
1022 wait for dependencies to be met before failing with a
1011 DependencyTimeout.
1023 DependencyTimeout.
1012 track : bool
1013 whether to track non-copying sends.
1014 [default False]
1015
1016 after,follow,timeout only used if `balanced=True`.
1017
1024
1018 Returns
1025 Returns
1019 -------
1026 -------
@@ -1022,7 +1029,7 b' class Client(HasTraits):'
1022 return AsyncResult wrapping msg_ids
1029 return AsyncResult wrapping msg_ids
1023 output of AsyncResult.get() is identical to that of `apply(...block=True)`
1030 output of AsyncResult.get() is identical to that of `apply(...block=True)`
1024 else:
1031 else:
1025 if single target:
1032 if single target (or balanced):
1026 return result of `f(*args, **kwargs)`
1033 return result of `f(*args, **kwargs)`
1027 else:
1034 else:
1028 return list of results, matching `targets`
1035 return list of results, matching `targets`
@@ -69,8 +69,9 b' class ClusterTestCase(BaseZMQTestCase):'
69 def connect_client(self):
69 def connect_client(self):
70 """connect a client with my Context, and track its sockets for cleanup"""
70 """connect a client with my Context, and track its sockets for cleanup"""
71 c = Client(profile='iptest',context=self.context)
71 c = Client(profile='iptest',context=self.context)
72 for name in filter(lambda n:n.endswith('socket'), dir(c)):
72
73 self.sockets.append(getattr(c, name))
73 # for name in filter(lambda n:n.endswith('socket'), dir(c)):
74 # self.sockets.append(getattr(c, name))
74 return c
75 return c
75
76
76 def assertRaisesRemote(self, etype, f, *args, **kwargs):
77 def assertRaisesRemote(self, etype, f, *args, **kwargs):
@@ -100,6 +101,6 b' class ClusterTestCase(BaseZMQTestCase):'
100 BaseZMQTestCase.tearDown(self)
101 BaseZMQTestCase.tearDown(self)
101 # this will be superfluous when pyzmq merges PR #88
102 # this will be superfluous when pyzmq merges PR #88
102 self.context.term()
103 self.context.term()
103 print tempfile.TemporaryFile().fileno(),
104 # print tempfile.TemporaryFile().fileno(),
104 sys.stdout.flush()
105 # sys.stdout.flush()
105 No newline at end of file
106
@@ -1,7 +1,6 b''
1 import time
1 import time
2 from tempfile import mktemp
2 from tempfile import mktemp
3
3
4 import nose.tools as nt
5 import zmq
4 import zmq
6
5
7 from IPython.zmq.parallel import client as clientmod
6 from IPython.zmq.parallel import client as clientmod
@@ -65,7 +64,7 b' class TestClient(ClusterTestCase):'
65 v = self.client[-1]
64 v = self.client[-1]
66 self.assert_(isinstance(v, DirectView))
65 self.assert_(isinstance(v, DirectView))
67 self.assertEquals(v.targets, targets[-1])
66 self.assertEquals(v.targets, targets[-1])
68 nt.assert_raises(TypeError, lambda : self.client[None])
67 self.assertRaises(TypeError, lambda : self.client[None])
69
68
70 def test_view_cache(self):
69 def test_view_cache(self):
71 """test that multiple view requests return the same object"""
70 """test that multiple view requests return the same object"""
@@ -179,6 +178,7 b' class TestClient(ClusterTestCase):'
179 """test getting results from the Hub."""
178 """test getting results from the Hub."""
180 c = clientmod.Client(profile='iptest')
179 c = clientmod.Client(profile='iptest')
181 self.add_engines(1)
180 self.add_engines(1)
181 t = c.ids[-1]
182 ar = c.apply(wait, (1,), block=False, targets=t)
182 ar = c.apply(wait, (1,), block=False, targets=t)
183 # give the monitor time to notice the message
183 # give the monitor time to notice the message
184 time.sleep(.25)
184 time.sleep(.25)
@@ -2,8 +2,6 b''
2
2
3 from unittest import TestCase
3 from unittest import TestCase
4
4
5 import nose.tools as nt
6
7 from IPython.testing.parametric import parametric
5 from IPython.testing.parametric import parametric
8 from IPython.utils import newserialized as ns
6 from IPython.utils import newserialized as ns
9 from IPython.utils.pickleutil import can, uncan, CannedObject, CannedFunction
7 from IPython.utils.pickleutil import can, uncan, CannedObject, CannedFunction
@@ -14,12 +12,12 b' class CanningTestCase(TestCase):'
14 def test_canning(self):
12 def test_canning(self):
15 d = dict(a=5,b=6)
13 d = dict(a=5,b=6)
16 cd = can(d)
14 cd = can(d)
17 nt.assert_true(isinstance(cd, dict))
15 self.assertTrue(isinstance(cd, dict))
18
16
19 def test_canned_function(self):
17 def test_canned_function(self):
20 f = lambda : 7
18 f = lambda : 7
21 cf = can(f)
19 cf = can(f)
22 nt.assert_true(isinstance(cf, CannedFunction))
20 self.assertTrue(isinstance(cf, CannedFunction))
23
21
24 @parametric
22 @parametric
25 def test_can_roundtrip(cls):
23 def test_can_roundtrip(cls):
@@ -32,17 +30,17 b' class CanningTestCase(TestCase):'
32 return map(cls.run_roundtrip, objs)
30 return map(cls.run_roundtrip, objs)
33
31
34 @classmethod
32 @classmethod
35 def run_roundtrip(cls, obj):
33 def run_roundtrip(self, obj):
36 o = uncan(can(obj))
34 o = uncan(can(obj))
37 nt.assert_equals(obj, o)
35 assert o == obj, "failed assertion: %r == %r"%(o,obj)
38
36
39 def test_serialized_interfaces(self):
37 def test_serialized_interfaces(self):
40
38
41 us = {'a':10, 'b':range(10)}
39 us = {'a':10, 'b':range(10)}
42 s = ns.serialize(us)
40 s = ns.serialize(us)
43 uus = ns.unserialize(s)
41 uus = ns.unserialize(s)
44 nt.assert_true(isinstance(s, ns.SerializeIt))
42 self.assertTrue(isinstance(s, ns.SerializeIt))
45 nt.assert_equals(uus, us)
43 self.assertEquals(uus, us)
46
44
47 def test_pickle_serialized(self):
45 def test_pickle_serialized(self):
48 obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
46 obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
@@ -51,16 +49,16 b' class CanningTestCase(TestCase):'
51 firstData = originalSer.getData()
49 firstData = originalSer.getData()
52 firstTD = originalSer.getTypeDescriptor()
50 firstTD = originalSer.getTypeDescriptor()
53 firstMD = originalSer.getMetadata()
51 firstMD = originalSer.getMetadata()
54 nt.assert_equals(firstTD, 'pickle')
52 self.assertEquals(firstTD, 'pickle')
55 nt.assert_equals(firstMD, {})
53 self.assertEquals(firstMD, {})
56 unSerialized = ns.UnSerializeIt(originalSer)
54 unSerialized = ns.UnSerializeIt(originalSer)
57 secondObj = unSerialized.getObject()
55 secondObj = unSerialized.getObject()
58 for k, v in secondObj.iteritems():
56 for k, v in secondObj.iteritems():
59 nt.assert_equals(obj[k], v)
57 self.assertEquals(obj[k], v)
60 secondSer = ns.SerializeIt(ns.UnSerialized(secondObj))
58 secondSer = ns.SerializeIt(ns.UnSerialized(secondObj))
61 nt.assert_equals(firstData, secondSer.getData())
59 self.assertEquals(firstData, secondSer.getData())
62 nt.assert_equals(firstTD, secondSer.getTypeDescriptor() )
60 self.assertEquals(firstTD, secondSer.getTypeDescriptor() )
63 nt.assert_equals(firstMD, secondSer.getMetadata())
61 self.assertEquals(firstMD, secondSer.getMetadata())
64
62
65 @skip_without('numpy')
63 @skip_without('numpy')
66 def test_ndarray_serialized(self):
64 def test_ndarray_serialized(self):
@@ -69,21 +67,21 b' class CanningTestCase(TestCase):'
69 unSer1 = ns.UnSerialized(a)
67 unSer1 = ns.UnSerialized(a)
70 ser1 = ns.SerializeIt(unSer1)
68 ser1 = ns.SerializeIt(unSer1)
71 td = ser1.getTypeDescriptor()
69 td = ser1.getTypeDescriptor()
72 nt.assert_equals(td, 'ndarray')
70 self.assertEquals(td, 'ndarray')
73 md = ser1.getMetadata()
71 md = ser1.getMetadata()
74 nt.assert_equals(md['shape'], a.shape)
72 self.assertEquals(md['shape'], a.shape)
75 nt.assert_equals(md['dtype'], a.dtype.str)
73 self.assertEquals(md['dtype'], a.dtype.str)
76 buff = ser1.getData()
74 buff = ser1.getData()
77 nt.assert_equals(buff, numpy.getbuffer(a))
75 self.assertEquals(buff, numpy.getbuffer(a))
78 s = ns.Serialized(buff, td, md)
76 s = ns.Serialized(buff, td, md)
79 final = ns.unserialize(s)
77 final = ns.unserialize(s)
80 nt.assert_equals(numpy.getbuffer(a), numpy.getbuffer(final))
78 self.assertEquals(numpy.getbuffer(a), numpy.getbuffer(final))
81 nt.assert_true((a==final).all())
79 self.assertTrue((a==final).all())
82 nt.assert_equals(a.dtype.str, final.dtype.str)
80 self.assertEquals(a.dtype.str, final.dtype.str)
83 nt.assert_equals(a.shape, final.shape)
81 self.assertEquals(a.shape, final.shape)
84 # test non-copying:
82 # test non-copying:
85 a[2] = 1e9
83 a[2] = 1e9
86 nt.assert_true((a==final).all())
84 self.assertTrue((a==final).all())
87
85
88
86
89 No newline at end of file
87
General Comments 0
You need to be logged in to leave comments. Login now