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(self, type, payload, expected_data): socket = FakeWritableSocket() self.assertTrue(m2proto.send(socket, type, payload)) self.assertEqual(socket.fake_data(), expected_data)
def test_send_empty(self): socket = FakeWritableSocket() self.assertTrue(m1proto.send(socket, '')) self.assertEqual(socket.fake_data(), b'\0')
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')