Show More
@@ -27,22 +27,6 b' class SessionTestCase(BaseZMQTestCase):' | |||
|
27 | 27 | self.session = ss.Session() |
|
28 | 28 | |
|
29 | 29 | |
|
30 | class MockSocket(zmq.Socket): | |
|
31 | data = None | |
|
32 | ||
|
33 | def __init__(self, *args, **kwargs): | |
|
34 | super(MockSocket,self).__init__(*args,**kwargs) | |
|
35 | self.data = [] | |
|
36 | ||
|
37 | def send_multipart(self, msgparts, *args, **kwargs): | |
|
38 | self.data.extend(msgparts) | |
|
39 | ||
|
40 | def send(self, part, *args, **kwargs): | |
|
41 | self.data.append(part) | |
|
42 | ||
|
43 | def recv_multipart(self, *args, **kwargs): | |
|
44 | return self.data | |
|
45 | ||
|
46 | 30 | class TestSession(SessionTestCase): |
|
47 | 31 | |
|
48 | 32 | def test_msg(self): |
@@ -76,11 +60,16 b' class TestSession(SessionTestCase):' | |||
|
76 | 60 | self.assertEqual(type(new_msg['content']['b']),type(new_msg['content']['b'])) |
|
77 | 61 | |
|
78 | 62 | def test_send(self): |
|
79 |
|
|
|
63 | ctx = zmq.Context.instance() | |
|
64 | A = ctx.socket(zmq.PAIR) | |
|
65 | B = ctx.socket(zmq.PAIR) | |
|
66 | A.bind("inproc://test") | |
|
67 | B.connect("inproc://test") | |
|
80 | 68 | |
|
81 | 69 | msg = self.session.msg('execute', content=dict(a=10)) |
|
82 |
self.session.send( |
|
|
83 | ident, msg_list = self.session.feed_identities(socket.data) | |
|
70 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) | |
|
71 | ||
|
72 | ident, msg_list = self.session.feed_identities(B.recv_multipart()) | |
|
84 | 73 | new_msg = self.session.unserialize(msg_list) |
|
85 | 74 | self.assertEqual(ident[0], b'foo') |
|
86 | 75 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
@@ -91,16 +80,14 b' class TestSession(SessionTestCase):' | |||
|
91 | 80 | self.assertEqual(new_msg['metadata'],msg['metadata']) |
|
92 | 81 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
93 | 82 | |
|
94 | socket.data = [] | |
|
95 | ||
|
96 | 83 | content = msg['content'] |
|
97 | 84 | header = msg['header'] |
|
98 | 85 | parent = msg['parent_header'] |
|
99 | 86 | metadata = msg['metadata'] |
|
100 | 87 | msg_type = header['msg_type'] |
|
101 |
self.session.send( |
|
|
88 | self.session.send(A, None, content=content, parent=parent, | |
|
102 | 89 | header=header, metadata=metadata, ident=b'foo', buffers=[b'bar']) |
|
103 |
ident, msg_list = self.session.feed_identities( |
|
|
90 | ident, msg_list = self.session.feed_identities(B.recv_multipart()) | |
|
104 | 91 | new_msg = self.session.unserialize(msg_list) |
|
105 | 92 | self.assertEqual(ident[0], b'foo') |
|
106 | 93 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
@@ -111,10 +98,8 b' class TestSession(SessionTestCase):' | |||
|
111 | 98 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
112 | 99 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
113 | 100 | |
|
114 | socket.data = [] | |
|
115 | ||
|
116 | self.session.send(socket, msg, ident=b'foo', buffers=[b'bar']) | |
|
117 | ident, new_msg = self.session.recv(socket) | |
|
101 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) | |
|
102 | ident, new_msg = self.session.recv(B) | |
|
118 | 103 | self.assertEqual(ident[0], b'foo') |
|
119 | 104 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
|
120 | 105 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
@@ -124,7 +109,9 b' class TestSession(SessionTestCase):' | |||
|
124 | 109 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
125 | 110 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
126 | 111 | |
|
127 |
|
|
|
112 | A.close() | |
|
113 | B.close() | |
|
114 | ctx.term() | |
|
128 | 115 | |
|
129 | 116 | def test_args(self): |
|
130 | 117 | """initialization arguments for Session""" |
General Comments 0
You need to be logged in to leave comments.
Login now