def test_send_empty(self): socket = FakeWritableSocket() self.assertTrue(m1proto.send(socket, '')) self.assertEqual(socket.fake_data(), b'\0')
def test_send_error_after_first_byte(self): socket = FakeWritableSocket(1) self.assertFalse(m1proto.send(socket, 'abcde'))
def test_send_error_with_partial_paload(self): socket = FakeWritableSocket(3) self.assertFalse(m1proto.send(socket, 'abcde'))
def test_send_error(self): socket = FakeWritableSocket(0) 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')