diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-06-26 12:44:15 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-06-26 12:46:53 -0400 |
| commit | fae82dda00aaba597deae862088f15c9b5255716 (patch) | |
| tree | 242f1b858fbf9ce37d2394cb066d28b089b4ab02 /test/sql | |
| parent | e04594339c19c3cd8b8e0d96ce83e5ded961dbb7 (diff) | |
| download | sqlalchemy-fae82dda00aaba597deae862088f15c9b5255716.tar.gz | |
Return given type when it matches the adaptation
The rules for type coercion between :class:`.Numeric`, :class:`.Integer`,
and date-related types now include additional logic that will attempt
to preserve the settings of the incoming type on the "resolved" type.
Currently the target for this is the ``asdecimal`` flag, so that
a math operation between :class:`.Numeric` or :class:`.Float` and
:class:`.Integer` will preserve the "asdecimal" flag as well as
if the type should be the :class:`.Float` subclass.
Change-Id: Idfaba17220d6db21ca1ca4dcb4c19834cd397817
Fixes: #4018
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_types.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 9107adaca..404d42c7a 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -29,6 +29,8 @@ from sqlalchemy.testing.util import picklers from sqlalchemy.testing.util import round_decimal from sqlalchemy.testing import fixtures from sqlalchemy.testing import mock +from sqlalchemy.sql import column +import operator class AdaptTest(fixtures.TestBase): @@ -2203,8 +2205,6 @@ class ExpressionTest( eq_(expr.type._type_affinity, types.Interval) def test_numerics_coercion(self): - from sqlalchemy.sql import column - import operator for op in (operator.add, operator.mul, operator.truediv, operator.sub): for other in (Numeric(10, 2), Integer): @@ -2219,6 +2219,28 @@ class ExpressionTest( ) assert isinstance(expr.type, types.Numeric) + def test_asdecimal_int_to_numeric(self): + expr = column('a', Integer) * column('b', Numeric(asdecimal=False)) + is_(expr.type.asdecimal, False) + + expr = column('a', Integer) * column('b', Numeric()) + is_(expr.type.asdecimal, True) + + expr = column('a', Integer) * column('b', Float()) + is_(expr.type.asdecimal, False) + assert isinstance(expr.type, Float) + + def test_asdecimal_numeric_to_int(self): + expr = column('a', Numeric(asdecimal=False)) * column('b', Integer) + is_(expr.type.asdecimal, False) + + expr = column('a', Numeric()) * column('b', Integer) + is_(expr.type.asdecimal, True) + + expr = column('a', Float()) * column('b', Integer) + is_(expr.type.asdecimal, False) + assert isinstance(expr.type, Float) + def test_null_comparison(self): eq_( str(column('a', types.NullType()) + column('b', types.NullType())), |
