Show More
@@ -27,22 +27,6 b' class SessionTestCase(BaseZMQTestCase):' | |||||
27 | self.session = ss.Session() |
|
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 | class TestSession(SessionTestCase): |
|
30 | class TestSession(SessionTestCase): | |
47 |
|
31 | |||
48 | def test_msg(self): |
|
32 | def test_msg(self): | |
@@ -76,11 +60,16 b' class TestSession(SessionTestCase):' | |||||
76 | self.assertEqual(type(new_msg['content']['b']),type(new_msg['content']['b'])) |
|
60 | self.assertEqual(type(new_msg['content']['b']),type(new_msg['content']['b'])) | |
77 |
|
61 | |||
78 | def test_send(self): |
|
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 | msg = self.session.msg('execute', content=dict(a=10)) |
|
69 | msg = self.session.msg('execute', content=dict(a=10)) | |
82 |
self.session.send( |
|
70 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) | |
83 | ident, msg_list = self.session.feed_identities(socket.data) |
|
71 | ||
|
72 | ident, msg_list = self.session.feed_identities(B.recv_multipart()) | |||
84 | new_msg = self.session.unserialize(msg_list) |
|
73 | new_msg = self.session.unserialize(msg_list) | |
85 | self.assertEqual(ident[0], b'foo') |
|
74 | self.assertEqual(ident[0], b'foo') | |
86 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
|
75 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) | |
@@ -91,16 +80,14 b' class TestSession(SessionTestCase):' | |||||
91 | self.assertEqual(new_msg['metadata'],msg['metadata']) |
|
80 | self.assertEqual(new_msg['metadata'],msg['metadata']) | |
92 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
81 | self.assertEqual(new_msg['buffers'],[b'bar']) | |
93 |
|
82 | |||
94 | socket.data = [] |
|
|||
95 |
|
||||
96 | content = msg['content'] |
|
83 | content = msg['content'] | |
97 | header = msg['header'] |
|
84 | header = msg['header'] | |
98 | parent = msg['parent_header'] |
|
85 | parent = msg['parent_header'] | |
99 | metadata = msg['metadata'] |
|
86 | metadata = msg['metadata'] | |
100 | msg_type = header['msg_type'] |
|
87 | msg_type = header['msg_type'] | |
101 |
self.session.send( |
|
88 | self.session.send(A, None, content=content, parent=parent, | |
102 | header=header, metadata=metadata, ident=b'foo', buffers=[b'bar']) |
|
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 | new_msg = self.session.unserialize(msg_list) |
|
91 | new_msg = self.session.unserialize(msg_list) | |
105 | self.assertEqual(ident[0], b'foo') |
|
92 | self.assertEqual(ident[0], b'foo') | |
106 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
|
93 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) | |
@@ -111,10 +98,8 b' class TestSession(SessionTestCase):' | |||||
111 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
98 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) | |
112 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
99 | self.assertEqual(new_msg['buffers'],[b'bar']) | |
113 |
|
100 | |||
114 | socket.data = [] |
|
101 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) | |
115 |
|
102 | ident, new_msg = self.session.recv(B) | ||
116 | self.session.send(socket, msg, ident=b'foo', buffers=[b'bar']) |
|
|||
117 | ident, new_msg = self.session.recv(socket) |
|
|||
118 | self.assertEqual(ident[0], b'foo') |
|
103 | self.assertEqual(ident[0], b'foo') | |
119 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
|
104 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) | |
120 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
|
105 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) | |
@@ -124,7 +109,9 b' class TestSession(SessionTestCase):' | |||||
124 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
109 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) | |
125 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
110 | self.assertEqual(new_msg['buffers'],[b'bar']) | |
126 |
|
111 | |||
127 |
|
|
112 | A.close() | |
|
113 | B.close() | |||
|
114 | ctx.term() | |||
128 |
|
115 | |||
129 | def test_args(self): |
|
116 | def test_args(self): | |
130 | """initialization arguments for Session""" |
|
117 | """initialization arguments for Session""" |
General Comments 0
You need to be logged in to leave comments.
Login now