More tests for range coercion
This commit is contained in:
@@ -36,12 +36,18 @@ 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 = (
|
||||||
return getattr(types.TypeEngine.Comparator, func)(
|
self.type.interval_class.type,
|
||||||
self, other, **kwargs
|
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, self.type.interval_class(other), **kwargs
|
self, 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
|
||||||
|
@@ -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',
|
||||||
(
|
(
|
||||||
|
Reference in New Issue
Block a user