def test_accept_message(self): self.req.on_enq() self.req._last_recv_data = codec.encode([records.HeaderRecord() .to_astm()])[0] self.assertEqual(self.req.on_message(), constants.ACK) self.assertTrue(self.req.dispatcher.was_called) self.assertFalse(self.req._chunks)
def test_accept_message(self): self.req.on_enq() self.req._last_recv_data = codec.encode( [records.HeaderRecord().to_astm()])[0] self.assertEqual(self.req.on_message(), constants.ACK) self.assertTrue(self.req.dispatcher.was_called) self.assertFalse(self.req._chunks)
def test_join_chunks_on_last_one(self): self.req.on_enq() self.req.is_chunked_transfer = False self.req._chunks = [b''] self.req._last_recv_data = codec.encode( [records.HeaderRecord().to_astm()])[0] self.assertEqual(self.req.on_message(), constants.ACK) self.assertFalse(self.req._chunks)
def test_encode_chunky(self): recs = [['foo', 1], ['bar', 24], ['baz', [1, 2, 3], 'boo']] res = codec.encode(recs, size=14) self.assertTrue(isinstance(res, list)) self.assertEqual(len(res), 4) self.assertEqual(res[0], f('{STX}1foo|1{CR}b{ETB}A8{CRLF}')) self.assertEqual(len(res[0]), 14) self.assertEqual(res[1], f('{STX}2ar|24{CR}b{ETB}6D{CRLF}')) self.assertEqual(len(res[1]), 14) self.assertEqual(res[2], f('{STX}3az|1^2^{ETB}C0{CRLF}')) self.assertEqual(len(res[2]), 14) self.assertEqual(res[3], f('{STX}43|boo{CR}{ETX}33{CRLF}')) self.assertLessEqual(len(res[3]), 14)
def test_encode_chunky(self): recs = [["foo", 1], ["bar", 24], ["baz", [1, 2, 3], "boo"]] res = codec.encode(recs, size=14) self.assertTrue(isinstance(res, list)) self.assertEqual(len(res), 4) self.assertEqual(res[0], f("{STX}1foo|1{CR}b{ETB}A8{CRLF}")) self.assertEqual(len(res[0]), 14) self.assertEqual(res[1], f("{STX}2ar|24{CR}b{ETB}6D{CRLF}")) self.assertEqual(len(res[1]), 14) self.assertEqual(res[2], f("{STX}3az|1^2^{ETB}C0{CRLF}")) self.assertEqual(len(res[2]), 14) self.assertEqual(res[3], f("{STX}43|boo{CR}{ETX}33{CRLF}")) self.assertLessEqual(len(res[3]), 14)
def test_join_chunks(self): recs = [['foo', '1'], ['bar', '24'], ['baz', ['1', '2', '3'], 'boo']] chunks = codec.encode(recs, size=14) msg = codec.join(chunks) self.assertEqual(codec.decode(msg), recs)
def test_decode_chunks(self): recs = [['foo', 1], ['bar', 24], ['baz', [1, 2, 3], 'boo']] res = codec.encode(recs, size=14) for item in res: codec.decode(item)
def test_encode(self): msg = f('{STX}1A|B|C|D{CR}{ETX}BF{CRLF}') seq, data, cs = codec.decode_message(msg, 'ascii') self.assertEqual([msg], codec.encode(data, 'ascii'))
def test_join_chunks(self): recs = [["foo", "1"], ["bar", "24"], ["baz", ["1", "2", "3"], "boo"]] chunks = codec.encode(recs, size=14) msg = codec.join(chunks) self.assertEqual(codec.decode(msg), recs)
def test_decode_chunks(self): recs = [["foo", 1], ["bar", 24], ["baz", [1, 2, 3], "boo"]] res = codec.encode(recs, size=14) for item in res: codec.decode(item)
def test_encode(self): msg = f("{STX}1A|B|C|D{CR}{ETX}BF{CRLF}") seq, data, cs = codec.decode_message(msg, "ascii") self.assertEqual([msg], codec.encode(data, "ascii"))
def recv(self, size): return codec.encode([records.HeaderRecord().to_astm()])[0]