Add reversed operators to PYSON expressions

review8201002
issue4856
This commit is contained in:
Nicolas Évrard
2015-07-07 12:48:28 +02:00
parent 7459aab3d1
commit 03d2e3fa9a
3 changed files with 11 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add reversed operators to PYSON expressions
* Use CURRENT_TIMESTAMP instead of now
* Use Constraint instance in ModelSQL._sql_constraints
* Only return default record if no domain supplied on ModelSingleton search
+4
View File
@@ -56,6 +56,8 @@ class PYSON(object):
else:
return And(self, other)
__rand__ = __and__
def __or__(self, other):
if (isinstance(other, PYSON)
and other.types() != set([bool])):
@@ -68,6 +70,8 @@ class PYSON(object):
else:
return Or(self, other)
__ror__ = __or__
def __eq__(self, other):
return Equal(self, other)
+6
View File
@@ -33,6 +33,12 @@ class PYSONTestCase(unittest.TestCase):
self.assertEqual(repr(pyson.Eval('test', 'foo')),
"Eval('test', 'foo')")
self.assertIsInstance(~pyson.Eval('test', False), pyson.Not)
self.assertIsInstance(pyson.Eval('test', False) & True, pyson.And)
self.assertIsInstance(True & pyson.Eval('test', False), pyson.And)
self.assertIsInstance(pyson.Eval('test', False) | False, pyson.Or)
self.assertIsInstance(False | pyson.Eval('test', False), pyson.Or)
def test0020Not(self):
'Test pyson.Not'
self.assertEqual(pyson.Not(True).pyson(), {