def setUp(self): self.client = katcp.DeviceClient('localhost', 0) self.assertFalse(self.client._received_protocol_info.isSet()) self.v4_build_state = Message.inform('build-state', 'blah-5.21a3') self.v4_version = Message.inform('version', '7.3') self.v5_version_connect_mid = Message.inform( 'version-connect', 'katcp-protocol', '5.0-I') self.v5_version_connect_nomid = Message.inform( 'version-connect', 'katcp-protocol', '5.0')
def setUp(self): self.client = katcp.DeviceClient('localhost', 0) self.assertFalse(self.client._received_protocol_info.isSet()) self.v4_build_state = Message.inform('build-state', 'blah-5.21a3') self.v4_version = Message.inform('version', '7.3') self.v5_version_connect_mid = Message.inform('version-connect', 'katcp-protocol', '5.0-I') self.v5_version_connect_nomid = Message.inform('version-connect', 'katcp-protocol', '5.0')
def test_equality(self): class AlwaysEqual(object): def __eq__(self, other): return True msg = Message.inform("foo", "a", "b") assert msg == Message.inform("foo", "a", "b") assert msg != Message.request("foo", "a", "b") assert msg != Message.inform("bar", "a", "b") assert msg != Message.inform("foo", "a", "b", "c") assert msg != Message.reply("foo", "a", "b") assert msg != 3 assert msg == AlwaysEqual()
def test_inform_attributes(self): """Test inform message attributes.""" msg = Message.inform('hello', 'world', mid=1) self.assertEqual(msg.mtype, Message.INFORM) self.assertEqual(msg.name, 'hello') self.assertEqual(msg.arguments, [b'world']) self.assertEqual(msg.mid, b'1')
def test_send_message(self): """Test send_message method.""" self.client.send_message(Message.inform("random-inform")) msgs = self.server.until_messages(1).result(timeout=1) self._assert_msgs_equal(msgs, [ r"#random-inform", ])
def test_inform_version_connect(self): # Test that the inform handler doesn't screw up with a non-katcp related # version-connect inform. self.client.handle_message( Message.inform('version-connect', 'not-katcp', '5.71a3')) # Should not raise any errors, but should also not set the protocol # infor received flag. self.assertFalse(self.client._received_protocol_info.isSet())
def test_send_message(self): """Test send_message method.""" self.client.send_message(Message.inform("random-inform")) msgs = self.server.until_messages(1).result(timeout=1) self._assert_msgs_equal(msgs, [ r"#random-inform", ])
def test_inform_version_connect(self): # Test that the inform handler doesn't screw up with a non-katcp related # version-connect inform. self.client.handle_message(Message.inform( 'version-connect', 'not-katcp', '5.71a3')) # Should not raise any errors, but should also not set the protocol # infor received flag. self.assertFalse(self.client._received_protocol_info.isSet())
def test_inform(self): """Test inform method.""" self.assertEqual(bytes(Message.inform("foo")), b"#foo") self.assertEqual(bytes(Message.inform("foo", mid=123)), b"#foo[123]") self.assertEqual(bytes(Message.inform("foo", "a", "b", mid=123)), b"#foo[123] a b")