annotate tests/test-wireproto-framing.py @ 51287:f15cb5111a1e

pytype: move some type comment to proper annotation We support direct type annotations now, while pytype is starting to complains about them.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 19 Dec 2023 21:29:34 +0100
parents 6000f5b25c9b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1 import unittest
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3 from mercurial import (
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
4 util,
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5 wireprotoframing as framing,
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
6 )
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
7
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 ffs = framing.makeframefromhumanstring
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
9
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
10
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
11 class FrameHumanStringTests(unittest.TestCase):
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
12 def testbasic(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
13 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
14 ffs(b'1 1 0 1 0 '), b'\x00\x00\x00\x01\x00\x01\x00\x10'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
15 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
16
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
17 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
18 ffs(b'2 4 0 1 0 '), b'\x00\x00\x00\x02\x00\x04\x00\x10'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
19 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
20
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
21 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
22 ffs(b'2 4 0 1 0 foo'), b'\x03\x00\x00\x02\x00\x04\x00\x10foo'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
23 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
24
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
25 def testcborint(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
26 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
27 ffs(b'1 1 0 1 0 cbor:15'), b'\x01\x00\x00\x01\x00\x01\x00\x10\x0f'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
28 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
29
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
30 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
31 ffs(b'1 1 0 1 0 cbor:42'), b'\x02\x00\x00\x01\x00\x01\x00\x10\x18*'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
32 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
33
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
34 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
35 ffs(b'1 1 0 1 0 cbor:1048576'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
36 b'\x05\x00\x00\x01\x00\x01\x00\x10\x1a' b'\x00\x10\x00\x00',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
37 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
38
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
39 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
40 ffs(b'1 1 0 1 0 cbor:0'), b'\x01\x00\x00\x01\x00\x01\x00\x10\x00'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
41 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
42
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
43 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
44 ffs(b'1 1 0 1 0 cbor:-1'), b'\x01\x00\x00\x01\x00\x01\x00\x10 '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
45 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
46
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
47 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
48 ffs(b'1 1 0 1 0 cbor:-342542'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
49 b'\x05\x00\x00\x01\x00\x01\x00\x10:\x00\x05:\r',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
50 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
51
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
52 def testcborstrings(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
53 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
54 ffs(b"1 1 0 1 0 cbor:b'foo'"),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
55 b'\x04\x00\x00\x01\x00\x01\x00\x10Cfoo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
56 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
57
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
58 def testcborlists(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
59 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
60 ffs(b"1 1 0 1 0 cbor:[None, True, False, 42, b'foo']"),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
61 b'\n\x00\x00\x01\x00\x01\x00\x10\x85\xf6\xf5\xf4' b'\x18*Cfoo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
62 )
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
63
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
64 def testcbordicts(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
65 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
66 ffs(b"1 1 0 1 0 " b"cbor:{b'foo': b'val1', b'bar': b'val2'}"),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
67 b'\x13\x00\x00\x01\x00\x01\x00\x10\xa2' b'CbarDval2CfooDval1',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
68 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
69
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37289
diff changeset
70
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
71 class FrameTests(unittest.TestCase):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
72 def testdataexactframesize(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
73 data = util.bytesio(b'x' * framing.DEFAULT_MAX_FRAME_SIZE)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
74
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
75 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
76 frames = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
77 framing.createcommandframes(stream, 1, b'command', {}, data)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
78 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
79 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
80 frames,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
81 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
82 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
83 b'1 1 stream-begin command-request new|have-data '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
84 b"cbor:{b'name': b'command'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
85 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
86 ffs(b'1 1 0 command-data continuation %s' % data.getvalue()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
87 ffs(b'1 1 0 command-data eos '),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
88 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
89 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
90
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
91 def testdatamultipleframes(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
92 data = util.bytesio(b'x' * (framing.DEFAULT_MAX_FRAME_SIZE + 1))
37285
3ed344546d9e wireproto: start to associate frame generation with a stream
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
93
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
94 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
95 frames = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
96 framing.createcommandframes(stream, 1, b'command', {}, data)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
97 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
98 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
99 frames,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
100 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
101 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
102 b'1 1 stream-begin command-request new|have-data '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
103 b"cbor:{b'name': b'command'}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
104 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
105 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
106 b'1 1 0 command-data continuation %s'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
107 % (b'x' * framing.DEFAULT_MAX_FRAME_SIZE)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
108 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
109 ffs(b'1 1 0 command-data eos x'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
110 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
111 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
112
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
113 def testargsanddata(self):
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
114 data = util.bytesio(b'x' * 100)
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
115
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
116 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
117 frames = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
118 framing.createcommandframes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
119 stream,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
120 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
121 b'command',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
122 {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
123 b'key1': b'key1value',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
124 b'key2': b'key2value',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
125 b'key3': b'key3value',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
126 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
127 data,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
128 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
129 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
130
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
131 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
132 frames,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
133 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
134 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
135 b'1 1 stream-begin command-request new|have-data '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
136 b"cbor:{b'name': b'command', b'args': {b'key1': b'key1value', "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
137 b"b'key2': b'key2value', b'key3': b'key3value'}}"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
138 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
139 ffs(b'1 1 0 command-data eos %s' % data.getvalue()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
140 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
141 )
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
142
37715
1859b9a7ddef cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
143 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
1859b9a7ddef cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
144 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
1859b9a7ddef cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
145 # the regex version.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
146 assertRaisesRegex = ( # camelcase-required
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
147 unittest.TestCase.assertRaisesRegexp
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
148 )
37715
1859b9a7ddef cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
149
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
150 def testtextoutputformattingstringtype(self):
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
151 """Formatting string must be bytes."""
37715
1859b9a7ddef cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
152 with self.assertRaisesRegex(ValueError, 'must use bytes formatting '):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
153 list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
154 framing.createtextoutputframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
155 None, 1, [(b'foo'.decode('ascii'), [], [])]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
156 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
157 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
158
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
159 def testtextoutputargumentbytes(self):
37715
1859b9a7ddef cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
160 with self.assertRaisesRegex(ValueError, 'must use bytes for argument'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
161 list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
162 framing.createtextoutputframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
163 None, 1, [(b'foo', [b'foo'.decode('ascii')], [])]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
164 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
165 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
166
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
167 def testtextoutputlabelbytes(self):
37715
1859b9a7ddef cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents: 37542
diff changeset
168 with self.assertRaisesRegex(ValueError, 'must use bytes for labels'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
169 list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
170 framing.createtextoutputframe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
171 None, 1, [(b'foo', [], [b'foo'.decode('ascii')])]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
172 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
173 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
174
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
175 def testtextoutput1simpleatom(self):
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
176 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
177 val = list(framing.createtextoutputframe(stream, 1, [(b'foo', [], [])]))
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
178
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
179 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
180 val,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
181 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
182 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
183 b'1 1 stream-begin text-output 0 '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
184 b"cbor:[{b'msg': b'foo'}]"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
185 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
186 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
187 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
188
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
189 def testtextoutput2simpleatoms(self):
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
190 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
191 val = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
192 framing.createtextoutputframe(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
193 stream,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
194 1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
195 [
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
196 (b'foo', [], []),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
197 (b'bar', [], []),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
198 ],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
199 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
200 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
201
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
202 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
203 val,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
204 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
205 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
206 b'1 1 stream-begin text-output 0 '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
207 b"cbor:[{b'msg': b'foo'}, {b'msg': b'bar'}]"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
208 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
209 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
210 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
211
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
212 def testtextoutput1arg(self):
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
213 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
214 val = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
215 framing.createtextoutputframe(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
216 stream,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
217 1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
218 [
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
219 (b'foo %s', [b'val1'], []),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
220 ],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
221 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
222 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
223
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
224 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
225 val,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
226 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
227 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
228 b'1 1 stream-begin text-output 0 '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
229 b"cbor:[{b'msg': b'foo %s', b'args': [b'val1']}]"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
230 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
231 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
232 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
233
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
234 def testtextoutput2arg(self):
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
235 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
236 val = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
237 framing.createtextoutputframe(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
238 stream,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
239 1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
240 [
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
241 (b'foo %s %s', [b'val', b'value'], []),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
242 ],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
243 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
244 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
245
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
246 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
247 val,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
248 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
249 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
250 b'1 1 stream-begin text-output 0 '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
251 b"cbor:[{b'msg': b'foo %s %s', b'args': [b'val', b'value']}]"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
252 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
253 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
254 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
255
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
256 def testtextoutput1label(self):
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
257 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
258 val = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
259 framing.createtextoutputframe(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
260 stream,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
261 1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
262 [
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
263 (b'foo', [], [b'label']),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
264 ],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
265 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
266 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
267
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
268 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
269 val,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
270 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
271 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
272 b'1 1 stream-begin text-output 0 '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
273 b"cbor:[{b'msg': b'foo', b'labels': [b'label']}]"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
274 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
275 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
276 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
277
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
278 def testargandlabel(self):
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37285
diff changeset
279 stream = framing.stream(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
280 val = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
281 framing.createtextoutputframe(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
282 stream,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
283 1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
284 [
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
285 (b'foo %s', [b'arg'], [b'label']),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
286 ],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
287 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
288 )
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
289
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
290 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
291 val,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
292 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
293 ffs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
294 b'1 1 stream-begin text-output 0 '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
295 b"cbor:[{b'msg': b'foo %s', b'args': [b'arg'], "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
296 b"b'labels': [b'label']}]"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
297 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
298 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
299 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
300
37060
0a6c5cc09a88 wireproto: define human output side channel frame
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37058
diff changeset
301
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
302 if __name__ == '__main__':
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
303 import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39410
diff changeset
304
37052
8c3c47362934 wireproto: implement basic frame reading and processing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
305 silenttestrunner.main(__name__)