mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-29 17:35:15 +08:00
e19f02a2ec
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.
34 lines
1.1 KiB
Python
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))
|