Skip to content

Commit

Permalink
Test coverage for new functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
da4089 committed Feb 16, 2018
1 parent a491ba4 commit 0ea15c2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

0 comments on commit 0ea15c2

Please sign in to comment.