diff --git a/test/test_message.py b/test/test_message.py index d514ef1..24e06a5 100644 --- a/test/test_message.py +++ b/test/test_message.py @@ -29,6 +29,7 @@ import unittest from simplefix import FixMessage +from simplefix.message import fix_tag, fix_val # NOTE: RHEL6 ships with Python 2.6, which is increasingly difficult to @@ -194,6 +195,13 @@ def test_compare_equal(self): self.assertTrue(a == b) return + def test_compare_not_message(self): + """Test comparison fails against not-FixMessage.""" + msg = FixMessage() + msg.append_pair(1, 1) + self.assertFalse(msg == self) + return + def test_compare_not_equal_extra_field_in_a(self): """Test comparison of extra field in this message""" a = FixMessage() @@ -1025,7 +1033,48 @@ def test_remove_nth(self): self.assertEqual(b'2', msg.get(99999, 2)) return + def test_str(self): + """Test conversion to string.""" + msg = FixMessage() + msg.append_pair(1, 1) + msg.append_pair(2, "foo") + msg.append_pair(3, b"bar") + msg.append_pair(4, 3.1415679) + + buffer = msg.encode(True) + self.assertIsNotNone(buffer) + self.assertEqual(b"1=1\x012=foo\x013=bar\x014=3.1415679\x01", buffer) + return + + def test_tag_bytes(self): + """Test bytes tag value returns bytes.""" + self.assertEqual(b"123", fix_tag(b"123")) + self.assertEqual(bytes, type(fix_tag(b"123"))) + return + def test_tag_str(self): + """Test string tag value returns bytes.""" + self.assertEqual(b"123", fix_tag("123")) + self.assertEqual(bytes, type(fix_tag("123"))) + return + + def test_tag_int(self): + """Test integer tag value returns bytes.""" + self.assertEqual(b"123", fix_tag(123)) + self.assertEqual(bytes, type(fix_tag(123))) + return + + def test_val_bytes(self): + """Test bytes value returns bytes.""" + self.assertEqual(b"123", fix_val(b"123")) + self.assertEqual(bytes, type(fix_val(b"123"))) + return + + def test_val_str(self): + """Test string value returns bytes.""" + self.assertEqual(b"123", fix_val("123")) + self.assertEqual(bytes, type(fix_val("123"))) + return if __name__ == "__main__": unittest.main()