summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/fixtures.py8
-rw-r--r--lib/sqlalchemy/testing/suite/test_cte.py23
-rw-r--r--lib/sqlalchemy/testing/suite/test_deprecations.py22
-rw-r--r--lib/sqlalchemy/testing/suite/test_results.py28
-rw-r--r--lib/sqlalchemy/testing/suite/test_rowcount.py12
-rw-r--r--lib/sqlalchemy/testing/suite/test_select.py193
-rw-r--r--lib/sqlalchemy/testing/suite/test_update_delete.py20
7 files changed, 145 insertions, 161 deletions
diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py
index 4f6083401..e5e6c42fc 100644
--- a/lib/sqlalchemy/testing/fixtures.py
+++ b/lib/sqlalchemy/testing/fixtures.py
@@ -135,7 +135,8 @@ class TablesTest(TestBase):
def _setup_once_inserts(cls):
if cls.run_inserts == "once":
cls._load_fixtures()
- cls.insert_data()
+ with cls.bind.begin() as conn:
+ cls.insert_data(conn)
@classmethod
def _setup_once_tables(cls):
@@ -157,7 +158,8 @@ class TablesTest(TestBase):
def _setup_each_inserts(self):
if self.run_inserts == "each":
self._load_fixtures()
- self.insert_data()
+ with self.bind.begin() as conn:
+ self.insert_data(conn)
def _teardown_each_tables(self):
if self.run_define_tables == "each":
@@ -224,7 +226,7 @@ class TablesTest(TestBase):
return {}
@classmethod
- def insert_data(cls):
+ def insert_data(cls, connection):
pass
def sql_count_(self, count, fn):
diff --git a/lib/sqlalchemy/testing/suite/test_cte.py b/lib/sqlalchemy/testing/suite/test_cte.py
index fab457606..1ee6cac10 100644
--- a/lib/sqlalchemy/testing/suite/test_cte.py
+++ b/lib/sqlalchemy/testing/suite/test_cte.py
@@ -36,18 +36,17 @@ class CTETest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "data": "d1", "parent_id": None},
- {"id": 2, "data": "d2", "parent_id": 1},
- {"id": 3, "data": "d3", "parent_id": 1},
- {"id": 4, "data": "d4", "parent_id": 3},
- {"id": 5, "data": "d5", "parent_id": 3},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "data": "d1", "parent_id": None},
+ {"id": 2, "data": "d2", "parent_id": 1},
+ {"id": 3, "data": "d3", "parent_id": 1},
+ {"id": 4, "data": "d4", "parent_id": 3},
+ {"id": 5, "data": "d5", "parent_id": 3},
+ ],
+ )
def test_select_nonrecursive_round_trip(self):
some_table = self.tables.some_table
diff --git a/lib/sqlalchemy/testing/suite/test_deprecations.py b/lib/sqlalchemy/testing/suite/test_deprecations.py
index 126d82fe9..8c25616a8 100644
--- a/lib/sqlalchemy/testing/suite/test_deprecations.py
+++ b/lib/sqlalchemy/testing/suite/test_deprecations.py
@@ -1,4 +1,3 @@
-from .. import config
from .. import fixtures
from ..assertions import eq_
from ..schema import Column
@@ -23,17 +22,16 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "x": 1, "y": 2},
- {"id": 2, "x": 2, "y": 3},
- {"id": 3, "x": 3, "y": 4},
- {"id": 4, "x": 4, "y": 5},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "x": 1, "y": 2},
+ {"id": 2, "x": 2, "y": 3},
+ {"id": 3, "x": 3, "y": 4},
+ {"id": 4, "x": 4, "y": 5},
+ ],
+ )
def _assert_result(self, conn, select, result, params=()):
eq_(conn.execute(select, params).fetchall(), result)
diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py
index 0cff7b61d..2eb986c74 100644
--- a/lib/sqlalchemy/testing/suite/test_results.py
+++ b/lib/sqlalchemy/testing/suite/test_results.py
@@ -1,6 +1,5 @@
import datetime
-from .. import config
from .. import engines
from .. import fixtures
from ..assertions import eq_
@@ -37,21 +36,20 @@ class RowFetchTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.plain_pk.insert(),
- [
- {"id": 1, "data": "d1"},
- {"id": 2, "data": "d2"},
- {"id": 3, "data": "d3"},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.plain_pk.insert(),
+ [
+ {"id": 1, "data": "d1"},
+ {"id": 2, "data": "d2"},
+ {"id": 3, "data": "d3"},
+ ],
+ )
- conn.execute(
- cls.tables.has_dates.insert(),
- [{"id": 1, "today": datetime.datetime(2006, 5, 12, 12, 0, 0)}],
- )
+ connection.execute(
+ cls.tables.has_dates.insert(),
+ [{"id": 1, "today": datetime.datetime(2006, 5, 12, 12, 0, 0)}],
+ )
def test_via_attr(self, connection):
row = connection.execute(
diff --git a/lib/sqlalchemy/testing/suite/test_rowcount.py b/lib/sqlalchemy/testing/suite/test_rowcount.py
index ae189bc79..06945ff2a 100644
--- a/lib/sqlalchemy/testing/suite/test_rowcount.py
+++ b/lib/sqlalchemy/testing/suite/test_rowcount.py
@@ -6,7 +6,6 @@ from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import testing
from sqlalchemy import text
-from sqlalchemy.testing import config
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
@@ -33,7 +32,7 @@ class RowCountTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
+ def insert_data(cls, connection):
cls.data = data = [
("Angela", "A"),
("Andrew", "A"),
@@ -47,11 +46,10 @@ class RowCountTest(fixtures.TablesTest):
]
employees_table = cls.tables.employees
- with config.db.begin() as conn:
- conn.execute(
- employees_table.insert(),
- [{"name": n, "department": d} for n, d in data],
- )
+ connection.execute(
+ employees_table.insert(),
+ [{"name": n, "department": d} for n, d in data],
+ )
def test_basic(self):
employees_table = self.tables.employees
diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py
index 23f78961f..c1f77a7c1 100644
--- a/lib/sqlalchemy/testing/suite/test_select.py
+++ b/lib/sqlalchemy/testing/suite/test_select.py
@@ -41,15 +41,14 @@ class CollateTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "data": "collate data1"},
- {"id": 2, "data": "collate data2"},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "data": "collate data1"},
+ {"id": 2, "data": "collate data2"},
+ ],
+ )
def _assert_result(self, select, result):
with config.db.connect() as conn:
@@ -91,16 +90,15 @@ class OrderByLabelTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "x": 1, "y": 2, "q": "q1", "p": "p3"},
- {"id": 2, "x": 2, "y": 3, "q": "q2", "p": "p2"},
- {"id": 3, "x": 3, "y": 4, "q": "q3", "p": "p1"},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "x": 1, "y": 2, "q": "q1", "p": "p3"},
+ {"id": 2, "x": 2, "y": 3, "q": "q2", "p": "p2"},
+ {"id": 3, "x": 3, "y": 4, "q": "q3", "p": "p1"},
+ ],
+ )
def _assert_result(self, select, result):
with config.db.connect() as conn:
@@ -165,17 +163,16 @@ class LimitOffsetTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "x": 1, "y": 2},
- {"id": 2, "x": 2, "y": 3},
- {"id": 3, "x": 3, "y": 4},
- {"id": 4, "x": 4, "y": 5},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "x": 1, "y": 2},
+ {"id": 2, "x": 2, "y": 3},
+ {"id": 3, "x": 3, "y": 4},
+ {"id": 4, "x": 4, "y": 5},
+ ],
+ )
def _assert_result(self, select, result, params=()):
with config.db.connect() as conn:
@@ -323,22 +320,21 @@ class JoinTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.a.insert(),
- [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.a.insert(),
+ [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}],
+ )
- conn.execute(
- cls.tables.b.insert(),
- [
- {"id": 1, "a_id": 1},
- {"id": 2, "a_id": 1},
- {"id": 4, "a_id": 2},
- {"id": 5, "a_id": 3},
- ],
- )
+ connection.execute(
+ cls.tables.b.insert(),
+ [
+ {"id": 1, "a_id": 1},
+ {"id": 2, "a_id": 1},
+ {"id": 4, "a_id": 2},
+ {"id": 5, "a_id": 3},
+ ],
+ )
def test_inner_join_fk(self):
a, b = self.tables("a", "b")
@@ -420,17 +416,16 @@ class CompoundSelectTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "x": 1, "y": 2},
- {"id": 2, "x": 2, "y": 3},
- {"id": 3, "x": 3, "y": 4},
- {"id": 4, "x": 4, "y": 5},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "x": 1, "y": 2},
+ {"id": 2, "x": 2, "y": 3},
+ {"id": 3, "x": 3, "y": 4},
+ {"id": 4, "x": 4, "y": 5},
+ ],
+ )
def _assert_result(self, select, result, params=()):
with config.db.connect() as conn:
@@ -565,17 +560,16 @@ class PostCompileParamsTest(
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "x": 1, "y": 2, "z": "z1"},
- {"id": 2, "x": 2, "y": 3, "z": "z2"},
- {"id": 3, "x": 3, "y": 4, "z": "z3"},
- {"id": 4, "x": 4, "y": 5, "z": "z4"},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "x": 1, "y": 2, "z": "z1"},
+ {"id": 2, "x": 2, "y": 3, "z": "z2"},
+ {"id": 3, "x": 3, "y": 4, "z": "z3"},
+ {"id": 4, "x": 4, "y": 5, "z": "z4"},
+ ],
+ )
def test_compile(self):
table = self.tables.some_table
@@ -683,17 +677,16 @@ class ExpandingBoundInTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "x": 1, "y": 2, "z": "z1"},
- {"id": 2, "x": 2, "y": 3, "z": "z2"},
- {"id": 3, "x": 3, "y": 4, "z": "z3"},
- {"id": 4, "x": 4, "y": 5, "z": "z4"},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "x": 1, "y": 2, "z": "z1"},
+ {"id": 2, "x": 2, "y": 3, "z": "z2"},
+ {"id": 3, "x": 3, "y": 4, "z": "z3"},
+ {"id": 4, "x": 4, "y": 5, "z": "z4"},
+ ],
+ )
def _assert_result(self, select, result, params=()):
with config.db.connect() as conn:
@@ -885,23 +878,22 @@ class LikeFunctionsTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.some_table.insert(),
- [
- {"id": 1, "data": "abcdefg"},
- {"id": 2, "data": "ab/cdefg"},
- {"id": 3, "data": "ab%cdefg"},
- {"id": 4, "data": "ab_cdefg"},
- {"id": 5, "data": "abcde/fg"},
- {"id": 6, "data": "abcde%fg"},
- {"id": 7, "data": "ab#cdefg"},
- {"id": 8, "data": "ab9cdefg"},
- {"id": 9, "data": "abcde#fg"},
- {"id": 10, "data": "abcd9fg"},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.some_table.insert(),
+ [
+ {"id": 1, "data": "abcdefg"},
+ {"id": 2, "data": "ab/cdefg"},
+ {"id": 3, "data": "ab%cdefg"},
+ {"id": 4, "data": "ab_cdefg"},
+ {"id": 5, "data": "abcde/fg"},
+ {"id": 6, "data": "abcde%fg"},
+ {"id": 7, "data": "ab#cdefg"},
+ {"id": 8, "data": "ab9cdefg"},
+ {"id": 9, "data": "abcde#fg"},
+ {"id": 10, "data": "abcd9fg"},
+ ],
+ )
def _test(self, expr, expected):
some_table = self.tables.some_table
@@ -997,12 +989,11 @@ class ComputedColumnTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.begin() as conn:
- conn.execute(
- cls.tables.square.insert(),
- [{"id": 1, "side": 10}, {"id": 10, "side": 42}],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.square.insert(),
+ [{"id": 1, "side": 10}, {"id": 10, "side": 42}],
+ )
def test_select_all(self):
with config.db.connect() as conn:
diff --git a/lib/sqlalchemy/testing/suite/test_update_delete.py b/lib/sqlalchemy/testing/suite/test_update_delete.py
index 6003a0994..f7e6da98e 100644
--- a/lib/sqlalchemy/testing/suite/test_update_delete.py
+++ b/lib/sqlalchemy/testing/suite/test_update_delete.py
@@ -1,4 +1,3 @@
-from .. import config
from .. import fixtures
from ..assertions import eq_
from ..schema import Column
@@ -21,16 +20,15 @@ class SimpleUpdateDeleteTest(fixtures.TablesTest):
)
@classmethod
- def insert_data(cls):
- with config.db.connect() as conn:
- conn.execute(
- cls.tables.plain_pk.insert(),
- [
- {"id": 1, "data": "d1"},
- {"id": 2, "data": "d2"},
- {"id": 3, "data": "d3"},
- ],
- )
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.plain_pk.insert(),
+ [
+ {"id": 1, "data": "d1"},
+ {"id": 2, "data": "d2"},
+ {"id": 3, "data": "d3"},
+ ],
+ )
def test_update(self, connection):
t = self.tables.plain_pk