From: Mike Bayer Date: Thu, 20 Jan 2022 17:26:36 +0000 (-0500) Subject: repair broken truediv test suite; memusage X-Git-Tag: rel_2_0_0b1~527^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=867235e4902c91531095676e3a413d935181b0bd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git repair broken truediv test suite; memusage the truediv test suite didn't have __backend__ so wasn't running for every DB except in the main build. Repaired this as well as truediv support to preserve the right-hand side type when casting to numeric, if the right type is already a numeric type. also fixed a memusage test that relies on savepoints so was not running under gerrit runs. Change-Id: I3be223fdf697af9c1ed61b70d621f57cbbb7a92b --- diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index af39f06729..8a3f264255 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1932,7 +1932,13 @@ class SQLCompiler(Compiled): # TODO: would need a fast cast again here, # unless we want to use an implicit cast like "+ 0.0" + self.process( - elements.Cast(binary.right, sqltypes.Numeric()), **kw + elements.Cast( + binary.right, + binary.right.type + if binary.right.type._type_affinity is sqltypes.Numeric + else sqltypes.Numeric(), + ), + **kw, ) ) else: diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 796de5d939..c51a666907 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -533,6 +533,8 @@ class CastTypeDecoratorTest(_LiteralRoundTripFixture, fixtures.TestBase): class TrueDivTest(fixtures.TestBase): + __backend__ = True + @testing.combinations( ("15", "10", 1.5), ("-15", "10", -1.5), @@ -576,13 +578,29 @@ class TrueDivTest(fixtures.TestBase): eq_( connection.scalar( select( - literal_column(left, type_=Numeric()) - / literal_column(right, type_=Numeric()) + literal_column(left, type_=Numeric(10, 2)) + / literal_column(right, type_=Numeric(10, 2)) ) ), decimal.Decimal(expected), ) + @testing.combinations( + ("5.52", "2.4", 2.3), argnames="left, right, expected" + ) + def test_truediv_float(self, connection, left, right, expected): + """test #4926""" + + eq_( + connection.scalar( + select( + literal_column(left, type_=Float()) + / literal_column(right, type_=Float()) + ) + ), + expected, + ) + @testing.combinations( ("5.52", "2.4", "2.0"), argnames="left, right, expected" ) diff --git a/test/aaa_profiling/test_memusage.py b/test/aaa_profiling/test_memusage.py index 10ec4d3079..2b806baf7a 100644 --- a/test/aaa_profiling/test_memusage.py +++ b/test/aaa_profiling/test_memusage.py @@ -458,7 +458,7 @@ class MemUsageWBackendTest(fixtures.MappedTest, EnsureZeroed): @testing.emits_warning("Compiled statement cache for lazy loader.*") @testing.crashes("sqlite", ":memory: connection not suitable here") def test_orm_many_engines(self): - metadata = MetaData(self.engine) + metadata = MetaData() table1 = Table( "mytable", @@ -485,7 +485,7 @@ class MemUsageWBackendTest(fixtures.MappedTest, EnsureZeroed): Column("col3", Integer, ForeignKey("mytable.col1")), ) - metadata.create_all() + metadata.create_all(self.engine) m1 = self.mapper_registry.map_imperatively( A, diff --git a/test/orm/test_deprecations.py b/test/orm/test_deprecations.py index e8d75ac48c..97ee97bc08 100644 --- a/test/orm/test_deprecations.py +++ b/test/orm/test_deprecations.py @@ -1843,7 +1843,6 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): q2 = q.values(func.count(User.name)) assert next(q2) == (4,) - @testing.fails_on("mssql", "FIXME: unknown") def test_values_specific_order_by(self): User = self.classes.User diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index c273dbbf87..d20037e921 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -2244,7 +2244,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): (value_tbl.c.val2 - value_tbl.c.val1) / value_tbl.c.val1, ), "SELECT values.id, (values.val2 - values.val1) " - "/ CAST(values.val1 AS NUMERIC) AS anon_1 FROM values", + "/ CAST(values.val1 AS FLOAT) AS anon_1 FROM values", ) self.assert_compile( @@ -2253,7 +2253,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ), "SELECT values.id FROM values WHERE " "(values.val2 - values.val1) / " - "CAST(values.val1 AS NUMERIC) > :param_1", + "CAST(values.val1 AS FLOAT) > :param_1", ) self.assert_compile( @@ -2264,8 +2264,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): > 2.0, ), "SELECT values.id FROM values WHERE " - "(values.val1 / CAST((values.val2 - values.val1) AS NUMERIC)) " - "/ CAST(values.val1 AS NUMERIC) > :param_1", + "(values.val1 / CAST((values.val2 - values.val1) AS FLOAT)) " + "/ CAST(values.val1 AS FLOAT) > :param_1", ) def test_percent_chars(self):