Files
catalyst/tests/test_security_object.py
T
Jonathan Kamens e19f02a2ec BUG: Handle all possible types of Security object __richcmp__ args
A cython __richcmp__ function isn't allowed to assume that its first
argument is the same as the type of the class to which it belongs, so
our code needs to account for either of its two arguments being of the
wrong type.

Furthermore, the correct way for __richcmp__ to handle when it doesn't
know how to do a comparison is to return NotImplemented.
2015-03-10 20:36:52 -04:00

34 lines
1.1 KiB
Python

from unittest import TestCase
from zipline.assets._securities import Security
class TestSecurityRichCmp(TestCase):
def test_lt(self):
self.assertTrue(Security(3) < Security(4))
self.assertFalse(Security(4) < Security(4))
self.assertFalse(Security(5) < Security(4))
def test_le(self):
self.assertTrue(Security(3) <= Security(4))
self.assertTrue(Security(4) <= Security(4))
self.assertFalse(Security(5) <= Security(4))
def test_eq(self):
self.assertFalse(Security(3) == Security(4))
self.assertTrue(Security(4) == Security(4))
self.assertFalse(Security(5) == Security(4))
def test_ge(self):
self.assertFalse(Security(3) >= Security(4))
self.assertTrue(Security(4) >= Security(4))
self.assertTrue(Security(5) >= Security(4))
def test_gt(self):
self.assertFalse(Security(3) > Security(4))
self.assertFalse(Security(4) > Security(4))
self.assertTrue(Security(5) > Security(4))
def test_type_mismatch(self):
self.assertIsNotNone(Security(3) < 'a')
self.assertIsNotNone('a' < Security(3))