]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
repair broken truediv test suite; memusage
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jan 2022 17:26:36 +0000 (12:26 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jan 2022 18:25:11 +0000 (13:25 -0500)
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

lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/testing/suite/test_types.py
test/aaa_profiling/test_memusage.py
test/orm/test_deprecations.py
test/sql/test_compiler.py

index af39f06729b102c9a1f4380c87db2493cfb3eec7..8a3f264255f26bbb06f232948db2cb8b69343690 100644 (file)
@@ -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:
index 796de5d939f79ed47d728bea722c50191f487d27..c51a666907180670c9230fd412710136cc7ae371 100644 (file)
@@ -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"
     )
index 10ec4d30795265124924a240ef114cc45e5e696c..2b806baf7af2c20e12308de5351ef1aad74f2552 100644 (file)
@@ -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,
index e8d75ac48cd97fb474099c4ffcfe6eb2ca3038d4..97ee97bc08576c4a406d1ff7bdba48d1aa0f3cd2 100644 (file)
@@ -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
 
index c273dbbf8767e70f56b41c9a14b879d4b387ae29..d20037e9219e5f695bda3d0a7558073073d464eb 100644 (file)
@@ -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):