]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
use connection fixture 8806/head
authorTobias Pfeiffer <tgp@preferred.jp>
Mon, 21 Nov 2022 23:50:02 +0000 (08:50 +0900)
committerTobias Pfeiffer <tgp@preferred.jp>
Mon, 21 Nov 2022 23:50:02 +0000 (08:50 +0900)
test/dialect/test_sqlite.py

index da10220c33e0ae2df088b2ae2ee50d2b93f5a81f..d2c9106d79f8898333e2562fca03b5ff1c1f9d2c 100644 (file)
@@ -2303,57 +2303,54 @@ class ConstraintReflectionTest(fixtures.TestBase):
             ],
         )
 
-    def test_reflect_partial_indexes(self):
-        with testing.db.begin() as conn:
-            conn.exec_driver_sql(
-                "create table foo_with_partial_index (x integer, y integer)"
-            )
-            conn.exec_driver_sql(
-                "create unique index ix_partial on "
-                "foo_with_partial_index (x) where y > 10"
-            )
-            conn.exec_driver_sql(
-                "create unique index ix_no_partial on "
-                "foo_with_partial_index (x)"
-            )
-            conn.exec_driver_sql(
-                "create unique index ix_partial2 on "
-                "foo_with_partial_index (x, y) where "
-                "y = 10 or abs(x) < 5"
-            )
+    def test_reflect_partial_indexes(self, connection):
+        connection.exec_driver_sql(
+            "create table foo_with_partial_index (x integer, y integer)"
+        )
+        connection.exec_driver_sql(
+            "create unique index ix_partial on "
+            "foo_with_partial_index (x) where y > 10"
+        )
+        connection.exec_driver_sql(
+            "create unique index ix_no_partial on "
+            "foo_with_partial_index (x)"
+        )
+        connection.exec_driver_sql(
+            "create unique index ix_partial2 on "
+            "foo_with_partial_index (x, y) where "
+            "y = 10 or abs(x) < 5"
+        )
 
-            inspector = inspect(conn)
-            indexes = inspector.get_indexes("foo_with_partial_index")
-            eq_(
-                indexes,
-                [
-                    {
-                        "unique": 1,
-                        "name": "ix_no_partial",
-                        "column_names": ["x"],
-                        "dialect_options": {},
-                    },
-                    {
-                        "unique": 1,
-                        "name": "ix_partial",
-                        "column_names": ["x"],
-                        "dialect_options": {"sqlite_where": mock.ANY},
-                    },
-                    {
-                        "unique": 1,
-                        "name": "ix_partial2",
-                        "column_names": ["x", "y"],
-                        "dialect_options": {"sqlite_where": mock.ANY},
-                    },
-                ],
-            )
-            assert (
-                indexes[1]["dialect_options"]["sqlite_where"].text == "y > 10"
-            )
-            assert (
-                indexes[2]["dialect_options"]["sqlite_where"].text
-                == "y = 10 or abs(x) < 5"
-            )
+        inspector = inspect(connection)
+        indexes = inspector.get_indexes("foo_with_partial_index")
+        eq_(
+            indexes,
+            [
+                {
+                    "unique": 1,
+                    "name": "ix_no_partial",
+                    "column_names": ["x"],
+                    "dialect_options": {},
+                },
+                {
+                    "unique": 1,
+                    "name": "ix_partial",
+                    "column_names": ["x"],
+                    "dialect_options": {"sqlite_where": mock.ANY},
+                },
+                {
+                    "unique": 1,
+                    "name": "ix_partial2",
+                    "column_names": ["x", "y"],
+                    "dialect_options": {"sqlite_where": mock.ANY},
+                },
+            ],
+        )
+        assert indexes[1]["dialect_options"]["sqlite_where"].text == "y > 10"
+        assert (
+            indexes[2]["dialect_options"]["sqlite_where"].text
+            == "y = 10 or abs(x) < 5"
+        )
 
     def test_unique_constraint_named(self):
         inspector = inspect(testing.db)