def test_send_error_after_second_byte(self): socket = FakeWritableSocket(2) self.assertFalse(m2proto.send(socket, 0, 'abcde'))
def test_send_error_with_partial_payload(self): socket = FakeWritableSocket(4) self.assertFalse(m2proto.send(socket, 0, 'abcde'))
def __test_send(self, type, payload, expected_data): socket = FakeWritableSocket() self.assertTrue(m2proto.send(socket, type, payload)) self.assertEqual(socket.fake_data(), expected_data)
def test_send_error(self): socket = FakeWritableSocket(0) self.assertFalse(m2proto.send(socket, 0, 'abcde'))
def test_send_empty(self): socket = FakeWritableSocket() self.assertTrue(m1proto.send(socket, '')) self.assertEqual(socket.fake_data(), b'\0')
def __test_send_raises(self, type, payload, expected_exception): socket = FakeWritableSocket() with self.assertRaises(expected_exception): m2proto.send(socket, type, payload) self.assertEqual(socket.fake_data(), b'')
def test_send_error_after_first_byte(self): socket = FakeWritableSocket(1) self.assertFalse(m1proto.send(socket, 'abcde'))
def test_send_too_big(self): socket = FakeWritableSocket() with self.assertRaises(m1proto.PayloadTooBig): m1proto.send(socket, 'x' * 256) self.assertEqual(socket.fake_data(), b'')
def test_send_max(self): socket = FakeWritableSocket() self.assertTrue(m1proto.send(socket, 'x' * 255)) self.assertEqual(socket.fake_data(), b'\xFF' + (b'x' * 255))
def test_send_unicode(self): socket = FakeWritableSocket() self.assertTrue(m1proto.send(socket, '\xA0')) self.assertEqual(socket.fake_data(), b'\x02\xC2\xA0')
def test_send_ascii(self): socket = FakeWritableSocket() self.assertTrue(m1proto.send(socket, 'abc')) self.assertEqual(socket.fake_data(), b'\x03abc')