Add support for rsfhit and lshift operators

This commit is contained in:
Konsta Vesterinen
2014-01-16 17:08:12 +02:00
parent b3f259a089
commit 9d8f2badf0
2 changed files with 40 additions and 0 deletions

View File

@@ -162,6 +162,14 @@ class RangeComparator(types.TypeEngine.Comparator):
other = map(self.coerce_arg, other)
return super(RangeComparator, self).notin_(other)
def __rshift__(self, other, **kwargs):
other = self.coerce_arg(other)
return self.op('>>')(other)
def __lshift__(self, other, **kwargs):
other = self.coerce_arg(other)
return self.op('<<')(other)
def contains(self, other, **kwargs):
other = self.coerce_arg(other)
return self.op('@>')(other)

View File

@@ -114,6 +114,38 @@ class TestIntRangeTypeOnPostgres(NumberRangeTestCase):
)
assert query.count()
@mark.parametrize(
'number_range',
(
[1, 3],
'1 - 3',
(0, 4),
)
)
def test_rshift_operator(self, number_range):
self.create_building([5, 6])
query = (
self.session.query(self.Building)
.filter(self.Building.persons_at_night >> number_range)
)
assert query.count()
@mark.parametrize(
'number_range',
(
[1, 3],
'1 - 3',
(0, 4),
)
)
def test_lshift_operator(self, number_range):
self.create_building([-1, 0])
query = (
self.session.query(self.Building)
.filter(self.Building.persons_at_night << number_range)
)
assert query.count()
@mark.parametrize(
'number_range',
(