This commit is contained in:
Chris Withers 2013-05-26 14:20:21 -07:00
commit faf7ff4d2f
2 changed files with 15 additions and 0 deletions

View File

@ -121,6 +121,8 @@ class Range(object):
return self._bounds is not None
def __eq__(self, other):
if not isinstance(other, Range):
return False
return (self._lower == other._lower
and self._upper == other._upper
and self._bounds == other._bounds)

View File

@ -1212,6 +1212,19 @@ class RangeTestCase(unittest.TestCase):
assert_not_equal(Range(10, 20), Range(11, 20))
assert_not_equal(Range(10, 20, '[)'), Range(10, 20, '[]'))
def test_eq_wrong_type(self):
from psycopg2.extras import Range
self.assertFalse(Range(10, 20)==())
def test_eq_subclass(self):
from psycopg2.extras import Range, NumericRange
class IntRange(NumericRange): pass
class PositiveIntRange(IntRange): pass
self.assertTrue(Range(10, 20)==IntRange(10, 20))
self.assertTrue(PositiveIntRange(10, 20)==IntRange(10, 20))
def test_not_ordered(self):
from psycopg2.extras import Range
self.assertRaises(TypeError, lambda: Range(empty=True) < Range(0,4))