More tests for range coercion

This commit is contained in:
Konsta Vesterinen
2014-01-14 10:47:46 +02:00
parent 209043e54c
commit bb54360ce2
2 changed files with 27 additions and 5 deletions

View File

@@ -36,13 +36,19 @@ class RangeComparator(types.TypeEngine.Comparator):
@classmethod @classmethod
def coerce_arg(cls, func): def coerce_arg(cls, func):
def operation(self, other, **kwargs): def operation(self, other, **kwargs):
if other is None: coerced_types = (
self.type.interval_class.type,
tuple,
list,
str,
unicode
)
if isinstance(other, coerced_types):
other = self.type.interval_class(other)
return getattr(types.TypeEngine.Comparator, func)( return getattr(types.TypeEngine.Comparator, func)(
self, other, **kwargs self, other, **kwargs
) )
return getattr(types.TypeEngine.Comparator, func)(
self, self.type.interval_class(other), **kwargs
)
return operation return operation
@@ -144,6 +150,10 @@ class IntRangeType(RangeType):
) )
print total print total
# '30-140' # '30-140'
Good reading:
http://wiki.postgresql.org/images/f/f0/Range-types.pdf
""" """
impl = INT4RANGE impl = INT4RANGE

View File

@@ -98,6 +98,18 @@ class TestIntRangeTypeOnPostgres(NumberRangeTestCase):
) )
assert query.count() assert query.count()
def test_eq_with_query_arg(self):
self.create_building([1, 3])
query = (
self.session.query(self.Building)
.filter(
self.Building.persons_at_night ==
self.session.query(
self.Building.persons_at_night)
).order_by(self.Building.persons_at_night).limit(1)
)
assert query.count()
@mark.parametrize( @mark.parametrize(
'number_range', 'number_range',
( (