mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 10:23:43 +03:00
cater for comparison of subclasses
This commit is contained in:
parent
b6a9e0ffaf
commit
28276e3eb1
|
@ -121,7 +121,7 @@ class Range(object):
|
|||
return self._bounds is not None
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, self.__class__):
|
||||
if not isinstance(other, Range):
|
||||
return False
|
||||
return (self._lower == other._lower
|
||||
and self._upper == other._upper
|
||||
|
|
|
@ -1216,6 +1216,15 @@ class RangeTestCase(unittest.TestCase):
|
|||
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))
|
||||
|
|
Loading…
Reference in New Issue
Block a user