63 ffs(b'1 command-name have-args|have-data command'), |
63 ffs(b'1 command-name have-args|have-data command'), |
64 ffs(br'1 command-argument 0 \x04\x00\x09\x00key1key1value'), |
64 ffs(br'1 command-argument 0 \x04\x00\x09\x00key1key1value'), |
65 ffs(br'1 command-argument 0 \x04\x00\x09\x00key2key2value'), |
65 ffs(br'1 command-argument 0 \x04\x00\x09\x00key2key2value'), |
66 ffs(br'1 command-argument eoa \x04\x00\x09\x00key3key3value'), |
66 ffs(br'1 command-argument eoa \x04\x00\x09\x00key3key3value'), |
67 ffs(b'1 command-data eos %s' % data.getvalue()), |
67 ffs(b'1 command-data eos %s' % data.getvalue()), |
|
68 ]) |
|
69 |
|
70 def testtextoutputexcessiveargs(self): |
|
71 """At most 255 formatting arguments are allowed.""" |
|
72 with self.assertRaisesRegexp(ValueError, |
|
73 'cannot use more than 255 formatting'): |
|
74 args = [b'x' for i in range(256)] |
|
75 list(framing.createtextoutputframe(1, [(b'bleh', args, [])])) |
|
76 |
|
77 def testtextoutputexcessivelabels(self): |
|
78 """At most 255 labels are allowed.""" |
|
79 with self.assertRaisesRegexp(ValueError, |
|
80 'cannot use more than 255 labels'): |
|
81 labels = [b'l' for i in range(256)] |
|
82 list(framing.createtextoutputframe(1, [(b'bleh', [], labels)])) |
|
83 |
|
84 def testtextoutputformattingstringtype(self): |
|
85 """Formatting string must be bytes.""" |
|
86 with self.assertRaisesRegexp(ValueError, 'must use bytes formatting '): |
|
87 list(framing.createtextoutputframe(1, [ |
|
88 (b'foo'.decode('ascii'), [], [])])) |
|
89 |
|
90 def testtextoutputargumentbytes(self): |
|
91 with self.assertRaisesRegexp(ValueError, 'must use bytes for argument'): |
|
92 list(framing.createtextoutputframe(1, [ |
|
93 (b'foo', [b'foo'.decode('ascii')], [])])) |
|
94 |
|
95 def testtextoutputlabelbytes(self): |
|
96 with self.assertRaisesRegexp(ValueError, 'must use bytes for labels'): |
|
97 list(framing.createtextoutputframe(1, [ |
|
98 (b'foo', [], [b'foo'.decode('ascii')])])) |
|
99 |
|
100 def testtextoutputtoolongformatstring(self): |
|
101 with self.assertRaisesRegexp(ValueError, |
|
102 'formatting string cannot be longer than'): |
|
103 list(framing.createtextoutputframe(1, [ |
|
104 (b'x' * 65536, [], [])])) |
|
105 |
|
106 def testtextoutputtoolongargumentstring(self): |
|
107 with self.assertRaisesRegexp(ValueError, |
|
108 'argument string cannot be longer than'): |
|
109 list(framing.createtextoutputframe(1, [ |
|
110 (b'bleh', [b'x' * 65536], [])])) |
|
111 |
|
112 def testtextoutputtoolonglabelstring(self): |
|
113 with self.assertRaisesRegexp(ValueError, |
|
114 'label string cannot be longer than'): |
|
115 list(framing.createtextoutputframe(1, [ |
|
116 (b'bleh', [], [b'x' * 65536])])) |
|
117 |
|
118 def testtextoutput1simpleatom(self): |
|
119 val = list(framing.createtextoutputframe(1, [ |
|
120 (b'foo', [], [])])) |
|
121 |
|
122 self.assertEqual(val, [ |
|
123 ffs(br'1 text-output 0 \x03\x00\x00\x00foo'), |
|
124 ]) |
|
125 |
|
126 def testtextoutput2simpleatoms(self): |
|
127 val = list(framing.createtextoutputframe(1, [ |
|
128 (b'foo', [], []), |
|
129 (b'bar', [], []), |
|
130 ])) |
|
131 |
|
132 self.assertEqual(val, [ |
|
133 ffs(br'1 text-output 0 \x03\x00\x00\x00foo\x03\x00\x00\x00bar'), |
|
134 ]) |
|
135 |
|
136 def testtextoutput1arg(self): |
|
137 val = list(framing.createtextoutputframe(1, [ |
|
138 (b'foo %s', [b'val1'], []), |
|
139 ])) |
|
140 |
|
141 self.assertEqual(val, [ |
|
142 ffs(br'1 text-output 0 \x06\x00\x00\x01\x04\x00foo %sval1'), |
|
143 ]) |
|
144 |
|
145 def testtextoutput2arg(self): |
|
146 val = list(framing.createtextoutputframe(1, [ |
|
147 (b'foo %s %s', [b'val', b'value'], []), |
|
148 ])) |
|
149 |
|
150 self.assertEqual(val, [ |
|
151 ffs(br'1 text-output 0 \x09\x00\x00\x02\x03\x00\x05\x00' |
|
152 br'foo %s %svalvalue'), |
|
153 ]) |
|
154 |
|
155 def testtextoutput1label(self): |
|
156 val = list(framing.createtextoutputframe(1, [ |
|
157 (b'foo', [], [b'label']), |
|
158 ])) |
|
159 |
|
160 self.assertEqual(val, [ |
|
161 ffs(br'1 text-output 0 \x03\x00\x01\x00\x05foolabel'), |
|
162 ]) |
|
163 |
|
164 def testargandlabel(self): |
|
165 val = list(framing.createtextoutputframe(1, [ |
|
166 (b'foo %s', [b'arg'], [b'label']), |
|
167 ])) |
|
168 |
|
169 self.assertEqual(val, [ |
|
170 ffs(br'1 text-output 0 \x06\x00\x01\x01\x05\x03\x00foo %slabelarg'), |
68 ]) |
171 ]) |
69 |
172 |
70 class ServerReactorTests(unittest.TestCase): |
173 class ServerReactorTests(unittest.TestCase): |
71 def _sendsingleframe(self, reactor, s): |
174 def _sendsingleframe(self, reactor, s): |
72 results = list(sendframes(reactor, [ffs(s)])) |
175 results = list(sendframes(reactor, [ffs(s)])) |