##// END OF EJS Templates
tests: add all missing b prefixes in reactor tests...
Augie Fackler -
r37700:cb71e0f9 default
parent child Browse files
Show More
@@ -437,5 +437,7 b' test-username-newline.t'
437 437 test-verify.t
438 438 test-websub.t
439 439 test-win32text.t
440 test-wireproto-clientreactor.py
440 441 test-wireproto-framing.py
442 test-wireproto-serverreactor.py
441 443 test-xdg.t
@@ -28,16 +28,16 b' class SingleSendTests(unittest.TestCase)'
28 28 reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True)
29 29
30 30 request, action, meta = reactor.callcommand(b'foo', {})
31 self.assertEqual(request.state, 'pending')
32 self.assertEqual(action, 'noop')
31 self.assertEqual(request.state, b'pending')
32 self.assertEqual(action, b'noop')
33 33
34 34 action, meta = reactor.flushcommands()
35 self.assertEqual(action, 'sendframes')
35 self.assertEqual(action, b'sendframes')
36 36
37 for frame in meta['framegen']:
38 self.assertEqual(request.state, 'sending')
37 for frame in meta[b'framegen']:
38 self.assertEqual(request.state, b'sending')
39 39
40 self.assertEqual(request.state, 'sent')
40 self.assertEqual(request.state, b'sent')
41 41
42 42 with self.assertRaisesRegexp(error.ProgrammingError,
43 43 'cannot issue new commands'):
@@ -54,51 +54,51 b' class NoBufferTests(unittest.TestCase):'
54 54
55 55 request, action, meta = reactor.callcommand(b'command1', {})
56 56 self.assertEqual(request.requestid, 1)
57 self.assertEqual(action, 'sendframes')
57 self.assertEqual(action, b'sendframes')
58 58
59 self.assertEqual(request.state, 'pending')
59 self.assertEqual(request.state, b'pending')
60 60
61 for frame in meta['framegen']:
62 self.assertEqual(request.state, 'sending')
61 for frame in meta[b'framegen']:
62 self.assertEqual(request.state, b'sending')
63 63
64 self.assertEqual(request.state, 'sent')
64 self.assertEqual(request.state, b'sent')
65 65
66 66 action, meta = reactor.flushcommands()
67 self.assertEqual(action, 'noop')
67 self.assertEqual(action, b'noop')
68 68
69 69 # And we can send another command.
70 70 request, action, meta = reactor.callcommand(b'command2', {})
71 71 self.assertEqual(request.requestid, 3)
72 self.assertEqual(action, 'sendframes')
72 self.assertEqual(action, b'sendframes')
73 73
74 for frame in meta['framegen']:
75 self.assertEqual(request.state, 'sending')
74 for frame in meta[b'framegen']:
75 self.assertEqual(request.state, b'sending')
76 76
77 self.assertEqual(request.state, 'sent')
77 self.assertEqual(request.state, b'sent')
78 78
79 79 class BadFrameRecvTests(unittest.TestCase):
80 80 def testoddstream(self):
81 81 reactor = framing.clientreactor()
82 82
83 83 action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo'))
84 self.assertEqual(action, 'error')
85 self.assertEqual(meta['message'],
86 'received frame with odd numbered stream ID: 1')
84 self.assertEqual(action, b'error')
85 self.assertEqual(meta[b'message'],
86 b'received frame with odd numbered stream ID: 1')
87 87
88 88 def testunknownstream(self):
89 89 reactor = framing.clientreactor()
90 90
91 91 action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo'))
92 self.assertEqual(action, 'error')
93 self.assertEqual(meta['message'],
94 'received frame on unknown stream without beginning '
95 'of stream flag set')
92 self.assertEqual(action, b'error')
93 self.assertEqual(meta[b'message'],
94 b'received frame on unknown stream without beginning '
95 b'of stream flag set')
96 96
97 97 def testunhandledframetype(self):
98 98 reactor = framing.clientreactor(buffersends=False)
99 99
100 100 request, action, meta = reactor.callcommand(b'foo', {})
101 for frame in meta['framegen']:
101 for frame in meta[b'framegen']:
102 102 pass
103 103
104 104 with self.assertRaisesRegexp(error.ProgrammingError,
@@ -111,19 +111,19 b' class StreamTests(unittest.TestCase):'
111 111
112 112 request, action, meta = reactor.callcommand(b'foo', {})
113 113
114 self.assertEqual(action, 'sendframes')
115 for f in meta['framegen']:
114 self.assertEqual(action, b'sendframes')
115 for f in meta[b'framegen']:
116 116 pass
117 117
118 118 action, meta = sendframe(
119 119 reactor,
120 120 ffs(b'%d 0 stream-begin 4 0 foo' % request.requestid))
121 self.assertEqual(action, 'responsedata')
121 self.assertEqual(action, b'responsedata')
122 122
123 123 action, meta = sendframe(
124 124 reactor,
125 125 ffs(b'%d 0 0 4 eos bar' % request.requestid))
126 self.assertEqual(action, 'responsedata')
126 self.assertEqual(action, b'responsedata')
127 127
128 128 if __name__ == '__main__':
129 129 import silenttestrunner
@@ -62,16 +62,16 b' class ServerReactorTests(unittest.TestCa'
62 62 stream = framing.stream(1)
63 63 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {}))
64 64 self.assertEqual(len(results), 1)
65 self.assertaction(results[0], 'runcommand')
65 self.assertaction(results[0], b'runcommand')
66 66 self.assertEqual(results[0][1], {
67 'requestid': 1,
68 'command': b'mycommand',
69 'args': {},
70 'data': None,
67 b'requestid': 1,
68 b'command': b'mycommand',
69 b'args': {},
70 b'data': None,
71 71 })
72 72
73 73 result = reactor.oninputeof()
74 self.assertaction(result, 'noop')
74 self.assertaction(result, b'noop')
75 75
76 76 def test1argument(self):
77 77 reactor = makereactor()
@@ -79,12 +79,12 b' class ServerReactorTests(unittest.TestCa'
79 79 results = list(sendcommandframes(reactor, stream, 41, b'mycommand',
80 80 {b'foo': b'bar'}))
81 81 self.assertEqual(len(results), 1)
82 self.assertaction(results[0], 'runcommand')
82 self.assertaction(results[0], b'runcommand')
83 83 self.assertEqual(results[0][1], {
84 'requestid': 41,
85 'command': b'mycommand',
86 'args': {b'foo': b'bar'},
87 'data': None,
84 b'requestid': 41,
85 b'command': b'mycommand',
86 b'args': {b'foo': b'bar'},
87 b'data': None,
88 88 })
89 89
90 90 def testmultiarguments(self):
@@ -93,12 +93,12 b' class ServerReactorTests(unittest.TestCa'
93 93 results = list(sendcommandframes(reactor, stream, 1, b'mycommand',
94 94 {b'foo': b'bar', b'biz': b'baz'}))
95 95 self.assertEqual(len(results), 1)
96 self.assertaction(results[0], 'runcommand')
96 self.assertaction(results[0], b'runcommand')
97 97 self.assertEqual(results[0][1], {
98 'requestid': 1,
99 'command': b'mycommand',
100 'args': {b'foo': b'bar', b'biz': b'baz'},
101 'data': None,
98 b'requestid': 1,
99 b'command': b'mycommand',
100 b'args': {b'foo': b'bar', b'biz': b'baz'},
101 b'data': None,
102 102 })
103 103
104 104 def testsimplecommanddata(self):
@@ -107,13 +107,13 b' class ServerReactorTests(unittest.TestCa'
107 107 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {},
108 108 util.bytesio(b'data!')))
109 109 self.assertEqual(len(results), 2)
110 self.assertaction(results[0], 'wantframe')
111 self.assertaction(results[1], 'runcommand')
110 self.assertaction(results[0], b'wantframe')
111 self.assertaction(results[1], b'runcommand')
112 112 self.assertEqual(results[1][1], {
113 'requestid': 1,
114 'command': b'mycommand',
115 'args': {},
116 'data': b'data!',
113 b'requestid': 1,
114 b'command': b'mycommand',
115 b'args': {},
116 b'data': b'data!',
117 117 })
118 118
119 119 def testmultipledataframes(self):
@@ -129,13 +129,13 b' class ServerReactorTests(unittest.TestCa'
129 129 results = list(sendframes(reactor, frames))
130 130 self.assertEqual(len(results), 4)
131 131 for i in range(3):
132 self.assertaction(results[i], 'wantframe')
133 self.assertaction(results[3], 'runcommand')
132 self.assertaction(results[i], b'wantframe')
133 self.assertaction(results[3], b'runcommand')
134 134 self.assertEqual(results[3][1], {
135 'requestid': 1,
136 'command': b'mycommand',
137 'args': {},
138 'data': b'data1data2data3',
135 b'requestid': 1,
136 b'command': b'mycommand',
137 b'args': {},
138 b'data': b'data1data2data3',
139 139 })
140 140
141 141 def testargumentanddata(self):
@@ -150,32 +150,32 b' class ServerReactorTests(unittest.TestCa'
150 150 reactor = makereactor()
151 151 results = list(sendframes(reactor, frames))
152 152
153 self.assertaction(results[-1], 'runcommand')
153 self.assertaction(results[-1], b'runcommand')
154 154 self.assertEqual(results[-1][1], {
155 'requestid': 1,
156 'command': b'command',
157 'args': {
155 b'requestid': 1,
156 b'command': b'command',
157 b'args': {
158 158 b'key': b'val',
159 159 b'foo': b'bar',
160 160 },
161 'data': b'value1value2',
161 b'data': b'value1value2',
162 162 })
163 163
164 164 def testnewandcontinuation(self):
165 165 result = self._sendsingleframe(makereactor(),
166 166 ffs(b'1 1 stream-begin command-request new|continuation '))
167 self.assertaction(result, 'error')
167 self.assertaction(result, b'error')
168 168 self.assertEqual(result[1], {
169 'message': b'received command request frame with both new and '
169 b'message': b'received command request frame with both new and '
170 170 b'continuation flags set',
171 171 })
172 172
173 173 def testneithernewnorcontinuation(self):
174 174 result = self._sendsingleframe(makereactor(),
175 175 ffs(b'1 1 stream-begin command-request 0 '))
176 self.assertaction(result, 'error')
176 self.assertaction(result, b'error')
177 177 self.assertEqual(result[1], {
178 'message': b'received command request frame with neither new nor '
178 b'message': b'received command request frame with neither new nor '
179 179 b'continuation flags set',
180 180 })
181 181
@@ -183,9 +183,9 b' class ServerReactorTests(unittest.TestCa'
183 183 """Command data frame when not running a command is an error."""
184 184 result = self._sendsingleframe(makereactor(),
185 185 ffs(b'1 1 stream-begin command-data 0 ignored'))
186 self.assertaction(result, 'error')
186 self.assertaction(result, b'error')
187 187 self.assertEqual(result[1], {
188 'message': b'expected command request frame; got 3',
188 b'message': b'expected command request frame; got 3',
189 189 })
190 190
191 191 def testunexpectedcommanddatareceiving(self):
@@ -196,10 +196,10 b' class ServerReactorTests(unittest.TestCa'
196 196 ffs(b'1 1 0 command-data eos ignored'),
197 197 ]))
198 198
199 self.assertaction(results[0], 'wantframe')
200 self.assertaction(results[1], 'error')
199 self.assertaction(results[0], b'wantframe')
200 self.assertaction(results[1], b'error')
201 201 self.assertEqual(results[1][1], {
202 'message': b'received command data frame for request that is not '
202 b'message': b'received command data frame for request that is not '
203 203 b'expecting data: 1',
204 204 })
205 205
@@ -212,28 +212,28 b' class ServerReactorTests(unittest.TestCa'
212 212 reactor, ffs(b'1 1 stream-begin command-request new '
213 213 b"cbor:{b'name': b'command'}")))
214 214 result = reactor.onbytesresponseready(outstream, 1, b'response1')
215 self.assertaction(result, 'sendframes')
216 list(result[1]['framegen'])
215 self.assertaction(result, b'sendframes')
216 list(result[1][b'framegen'])
217 217 results.append(self._sendsingleframe(
218 218 reactor, ffs(b'1 1 stream-begin command-request new '
219 219 b"cbor:{b'name': b'command'}")))
220 220 result = reactor.onbytesresponseready(outstream, 1, b'response2')
221 self.assertaction(result, 'sendframes')
222 list(result[1]['framegen'])
221 self.assertaction(result, b'sendframes')
222 list(result[1][b'framegen'])
223 223 results.append(self._sendsingleframe(
224 224 reactor, ffs(b'1 1 stream-begin command-request new '
225 225 b"cbor:{b'name': b'command'}")))
226 226 result = reactor.onbytesresponseready(outstream, 1, b'response3')
227 self.assertaction(result, 'sendframes')
228 list(result[1]['framegen'])
227 self.assertaction(result, b'sendframes')
228 list(result[1][b'framegen'])
229 229
230 230 for i in range(3):
231 self.assertaction(results[i], 'runcommand')
231 self.assertaction(results[i], b'runcommand')
232 232 self.assertEqual(results[i][1], {
233 'requestid': 1,
234 'command': b'command',
235 'args': {},
236 'data': None,
233 b'requestid': 1,
234 b'command': b'command',
235 b'args': {},
236 b'data': None,
237 237 })
238 238
239 239 def testconflictingrequestid(self):
@@ -245,10 +245,10 b' class ServerReactorTests(unittest.TestCa'
245 245 b"cbor:{b'name': b'command1'}"),
246 246 ]))
247 247
248 self.assertaction(results[0], 'wantframe')
249 self.assertaction(results[1], 'error')
248 self.assertaction(results[0], b'wantframe')
249 self.assertaction(results[1], b'error')
250 250 self.assertEqual(results[1][1], {
251 'message': b'request with ID 1 already received',
251 b'message': b'request with ID 1 already received',
252 252 })
253 253
254 254 def testinterleavedcommands(self):
@@ -277,25 +277,25 b' class ServerReactorTests(unittest.TestCa'
277 277 ]))
278 278
279 279 self.assertEqual([t[0] for t in results], [
280 'wantframe',
281 'wantframe',
282 'wantframe',
283 'wantframe',
284 'runcommand',
285 'runcommand',
280 b'wantframe',
281 b'wantframe',
282 b'wantframe',
283 b'wantframe',
284 b'runcommand',
285 b'runcommand',
286 286 ])
287 287
288 288 self.assertEqual(results[4][1], {
289 'requestid': 3,
290 'command': 'command3',
291 'args': {b'biz': b'baz', b'key': b'val'},
292 'data': None,
289 b'requestid': 3,
290 b'command': b'command3',
291 b'args': {b'biz': b'baz', b'key': b'val'},
292 b'data': None,
293 293 })
294 294 self.assertEqual(results[5][1], {
295 'requestid': 1,
296 'command': 'command1',
297 'args': {b'foo': b'bar', b'key1': b'val'},
298 'data': None,
295 b'requestid': 1,
296 b'command': b'command1',
297 b'args': {b'foo': b'bar', b'key1': b'val'},
298 b'data': None,
299 299 })
300 300
301 301 def testmissingcommanddataframe(self):
@@ -309,8 +309,8 b' class ServerReactorTests(unittest.TestCa'
309 309 ]
310 310 results = list(sendframes(makereactor(), frames))
311 311 self.assertEqual(len(results), 2)
312 self.assertaction(results[0], 'wantframe')
313 self.assertaction(results[1], 'runcommand')
312 self.assertaction(results[0], b'wantframe')
313 self.assertaction(results[1], b'runcommand')
314 314
315 315 def testmissingcommanddataframeflags(self):
316 316 frames = [
@@ -320,10 +320,10 b' class ServerReactorTests(unittest.TestCa'
320 320 ]
321 321 results = list(sendframes(makereactor(), frames))
322 322 self.assertEqual(len(results), 2)
323 self.assertaction(results[0], 'wantframe')
324 self.assertaction(results[1], 'error')
323 self.assertaction(results[0], b'wantframe')
324 self.assertaction(results[1], b'error')
325 325 self.assertEqual(results[1][1], {
326 'message': b'command data frame without flags',
326 b'message': b'command data frame without flags',
327 327 })
328 328
329 329 def testframefornonreceivingrequest(self):
@@ -335,9 +335,9 b' class ServerReactorTests(unittest.TestCa'
335 335 b"cbor:{b'name': b'command3'}"),
336 336 ffs(b'5 1 0 command-data eos ignored'),
337 337 ]))
338 self.assertaction(results[2], 'error')
338 self.assertaction(results[2], b'error')
339 339 self.assertEqual(results[2][1], {
340 'message': b'received frame for request that is not receiving: 5',
340 b'message': b'received frame for request that is not receiving: 5',
341 341 })
342 342
343 343 def testsimpleresponse(self):
@@ -348,8 +348,8 b' class ServerReactorTests(unittest.TestCa'
348 348
349 349 outstream = reactor.makeoutputstream()
350 350 result = reactor.onbytesresponseready(outstream, 1, b'response')
351 self.assertaction(result, 'sendframes')
352 self.assertframesequal(result[1]['framegen'], [
351 self.assertaction(result, b'sendframes')
352 self.assertframesequal(result[1][b'framegen'], [
353 353 b'1 2 stream-begin bytes-response eos response',
354 354 ])
355 355
@@ -364,8 +364,8 b' class ServerReactorTests(unittest.TestCa'
364 364
365 365 outstream = reactor.makeoutputstream()
366 366 result = reactor.onbytesresponseready(outstream, 1, first + second)
367 self.assertaction(result, 'sendframes')
368 self.assertframesequal(result[1]['framegen'], [
367 self.assertaction(result, b'sendframes')
368 self.assertframesequal(result[1][b'framegen'], [
369 369 b'1 2 stream-begin bytes-response continuation %s' % first,
370 370 b'1 2 0 bytes-response eos %s' % second,
371 371 ])
@@ -377,8 +377,8 b' class ServerReactorTests(unittest.TestCa'
377 377
378 378 outstream = reactor.makeoutputstream()
379 379 result = reactor.onapplicationerror(outstream, 1, b'some message')
380 self.assertaction(result, 'sendframes')
381 self.assertframesequal(result[1]['framegen'], [
380 self.assertaction(result, b'sendframes')
381 self.assertframesequal(result[1][b'framegen'], [
382 382 b'1 2 stream-begin error-response application some message',
383 383 ])
384 384
@@ -389,14 +389,14 b' class ServerReactorTests(unittest.TestCa'
389 389 results = list(sendcommandframes(reactor, instream, 1, b'mycommand',
390 390 {}))
391 391 self.assertEqual(len(results), 1)
392 self.assertaction(results[0], 'runcommand')
392 self.assertaction(results[0], b'runcommand')
393 393
394 394 outstream = reactor.makeoutputstream()
395 395 result = reactor.onbytesresponseready(outstream, 1, b'response')
396 self.assertaction(result, 'noop')
396 self.assertaction(result, b'noop')
397 397 result = reactor.oninputeof()
398 self.assertaction(result, 'sendframes')
399 self.assertframesequal(result[1]['framegen'], [
398 self.assertaction(result, b'sendframes')
399 self.assertframesequal(result[1][b'framegen'], [
400 400 b'1 2 stream-begin bytes-response eos response',
401 401 ])
402 402
@@ -408,12 +408,12 b' class ServerReactorTests(unittest.TestCa'
408 408
409 409 outstream = reactor.makeoutputstream()
410 410 result = reactor.onbytesresponseready(outstream, 1, b'response1')
411 self.assertaction(result, 'noop')
411 self.assertaction(result, b'noop')
412 412 result = reactor.onbytesresponseready(outstream, 3, b'response2')
413 self.assertaction(result, 'noop')
413 self.assertaction(result, b'noop')
414 414 result = reactor.oninputeof()
415 self.assertaction(result, 'sendframes')
416 self.assertframesequal(result[1]['framegen'], [
415 self.assertaction(result, b'sendframes')
416 self.assertframesequal(result[1][b'framegen'], [
417 417 b'1 2 stream-begin bytes-response eos response1',
418 418 b'3 2 0 bytes-response eos response2'
419 419 ])
@@ -432,8 +432,8 b' class ServerReactorTests(unittest.TestCa'
432 432 reactor.onbytesresponseready(outstream, 5, b'response5')
433 433
434 434 result = reactor.oninputeof()
435 self.assertaction(result, 'sendframes')
436 self.assertframesequal(result[1]['framegen'], [
435 self.assertaction(result, b'sendframes')
436 self.assertframesequal(result[1][b'framegen'], [
437 437 b'3 2 stream-begin bytes-response eos response3',
438 438 b'1 2 0 bytes-response eos response1',
439 439 b'5 2 0 bytes-response eos response5',
@@ -446,9 +446,9 b' class ServerReactorTests(unittest.TestCa'
446 446 list(sendcommandframes(reactor, stream, 1, b'command1', {}))
447 447 results = list(sendcommandframes(reactor, stream, 1, b'command1', {}))
448 448
449 self.assertaction(results[0], 'error')
449 self.assertaction(results[0], b'error')
450 450 self.assertEqual(results[0][1], {
451 'message': b'request with ID 1 is already active',
451 b'message': b'request with ID 1 is already active',
452 452 })
453 453
454 454 def testduplicaterequestonactivecommandnosend(self):
@@ -463,9 +463,9 b' class ServerReactorTests(unittest.TestCa'
463 463 # perspective of the reactor, the command is still active.
464 464
465 465 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
466 self.assertaction(results[0], 'error')
466 self.assertaction(results[0], b'error')
467 467 self.assertEqual(results[0][1], {
468 'message': b'request with ID 1 is already active',
468 b'message': b'request with ID 1 is already active',
469 469 })
470 470
471 471 def testduplicaterequestaftersend(self):
@@ -475,10 +475,10 b' class ServerReactorTests(unittest.TestCa'
475 475 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
476 476 outstream = reactor.makeoutputstream()
477 477 res = reactor.onbytesresponseready(outstream, 1, b'response')
478 list(res[1]['framegen'])
478 list(res[1][b'framegen'])
479 479
480 480 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
481 self.assertaction(results[0], 'runcommand')
481 self.assertaction(results[0], b'runcommand')
482 482
483 483 if __name__ == '__main__':
484 484 import silenttestrunner
General Comments 0
You need to be logged in to leave comments. Login now