diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-01 10:35:30 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-01 12:34:41 -0400 |
| commit | 919b8bc4acf8de4720e8fff5077557f366fb3fb0 (patch) | |
| tree | fd515dc511a722b8a464c2c851cb59ddb4bda907 /test/sql | |
| parent | 65680b2343ef421a62582e23e2b35293732933ad (diff) | |
| download | sqlalchemy-919b8bc4acf8de4720e8fff5077557f366fb3fb0.tar.gz | |
Ensure custom ops have consistent typing behavior, boolean support
Refined the behavior of :meth:`.Operators.op` such that in all cases,
if the :paramref:`.Operators.op.is_comparison` flag is set to True,
the return type of the resulting expression will be
:class:`.Boolean`, and if the flag is False, the return type of the
resulting expression will be the same type as that of the left-hand
expression, which is the typical default behavior of other operators.
Also added a new parameter :paramref:`.Operators.op.return_type` as well
as a helper method :meth:`.Operators.bool_op`.
Change-Id: Ifc8553cd4037d741b84b70a9702cbd530f1a9de0
Fixes: #4063
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_operators.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index c18f9f9be..61295467d 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -2631,8 +2631,37 @@ class CustomOpTest(fixtures.TestBase): assert operators.is_comparison(op1) assert not operators.is_comparison(op2) - expr = c.op('$', is_comparison=True)(None) - is_(expr.type, sqltypes.BOOLEANTYPE) + def test_return_types(self): + some_return_type = sqltypes.DECIMAL() + + for typ in [ + sqltypes.NULLTYPE, + Integer(), + ARRAY(String), + String(50), + Boolean(), + DateTime(), + sqltypes.JSON(), + postgresql.ARRAY(Integer), + sqltypes.Numeric(5, 2), + ]: + c = column('x', typ) + expr = c.op('$', is_comparison=True)(None) + is_(expr.type, sqltypes.BOOLEANTYPE) + + c = column('x', typ) + expr = c.bool_op('$')(None) + is_(expr.type, sqltypes.BOOLEANTYPE) + + expr = c.op('$')(None) + is_(expr.type, typ) + + expr = c.op('$', return_type=some_return_type)(None) + is_(expr.type, some_return_type) + + expr = c.op( + '$', is_comparison=True, return_type=some_return_type)(None) + is_(expr.type, some_return_type) class TupleTypingTest(fixtures.TestBase): |
