summaryrefslogtreecommitdiff
path: root/test/aaa_profiling
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-01-04 15:18:25 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-05 23:46:02 -0500
commit6fccdf4a285d5332ef49f23dc18c3ce45501d78b (patch)
treed276e13e8960f00dc088c40908e4991248cc8639 /test/aaa_profiling
parent640cd8a70f8a664b7834c5f74ec322fdea644043 (diff)
downloadsqlalchemy-6fccdf4a285d5332ef49f23dc18c3ce45501d78b.tar.gz
remove more bound metadata
in Iae6ab95938a7e92b6d42086aec534af27b5577d3 I missed that the "bind" was being stuck onto the MetaData in TablesTest, which led thousands of ORM tests to still use bound metadata. Keep looking for bound metadata. standardize all ORM tests on a single means of getting a Session when the Session API isn't the thing we are directly testing, using a new function fixture_session() that replaces create_session() and uses modern defaults. Change-Id: Iaf71206e9ee568151496d8bc213a069504bf65ef
Diffstat (limited to 'test/aaa_profiling')
-rw-r--r--test/aaa_profiling/test_memusage.py51
-rw-r--r--test/aaa_profiling/test_orm.py51
-rw-r--r--test/aaa_profiling/test_resultset.py4
3 files changed, 54 insertions, 52 deletions
diff --git a/test/aaa_profiling/test_memusage.py b/test/aaa_profiling/test_memusage.py
index 7858e697d..75a4f51cf 100644
--- a/test/aaa_profiling/test_memusage.py
+++ b/test/aaa_profiling/test_memusage.py
@@ -38,6 +38,7 @@ from sqlalchemy.sql.visitors import replacement_traverse
from sqlalchemy.testing import engines
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
from sqlalchemy.testing.util import gc_collect
@@ -535,7 +536,7 @@ class MemUsageWBackendTest(EnsureZeroed):
@testing.emits_warning("Compiled statement cache for.*")
def test_many_updates(self):
- metadata = MetaData(self.engine)
+ metadata = MetaData()
wide_table = Table(
"t",
@@ -551,8 +552,8 @@ class MemUsageWBackendTest(EnsureZeroed):
mapper(Wide, wide_table, _compiled_cache_size=10)
- metadata.create_all()
- with Session() as session:
+ metadata.create_all(self.engine)
+ with Session(self.engine) as session:
w1 = Wide()
session.add(w1)
session.commit()
@@ -561,7 +562,7 @@ class MemUsageWBackendTest(EnsureZeroed):
@profile_memory()
def go():
- with Session() as session:
+ with Session(self.engine) as session:
w1 = session.query(Wide).first()
x = counter[0]
dec = 10
@@ -578,7 +579,7 @@ class MemUsageWBackendTest(EnsureZeroed):
try:
go()
finally:
- metadata.drop_all()
+ metadata.drop_all(self.engine)
@testing.requires.savepoints
@testing.provide_metadata
@@ -1031,7 +1032,7 @@ class MemUsageWBackendTest(EnsureZeroed):
t2_mapper = mapper(T2, t2)
t1_mapper.add_property("bar", relationship(t2_mapper))
- s1 = Session()
+ s1 = fixture_session()
# this causes the path_registry to be invoked
s1.query(t1_mapper)._compile_context()
@@ -1151,7 +1152,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
@assert_cycles()
def go():
@@ -1163,7 +1164,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
@assert_cycles()
def go():
@@ -1223,7 +1224,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
u1 = aliased(User)
@@ -1248,7 +1249,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
def generate():
objects = s.query(User).filter(User.id == 7).all()
@@ -1264,7 +1265,7 @@ class CycleTest(_fixtures.FixtureTest):
def test_orm_objects_from_query_w_selectinload(self):
User, Address = self.classes("User", "Address")
- s = Session()
+ s = fixture_session()
def generate():
objects = s.query(User).options(selectinload(User.addresses)).all()
@@ -1328,7 +1329,7 @@ class CycleTest(_fixtures.FixtureTest):
def test_orm_objects_from_query_w_joinedload(self):
User, Address = self.classes("User", "Address")
- s = Session()
+ s = fixture_session()
def generate():
objects = s.query(User).options(joinedload(User.addresses)).all()
@@ -1344,7 +1345,7 @@ class CycleTest(_fixtures.FixtureTest):
def test_query_filtered(self):
User, Address = self.classes("User", "Address")
- s = Session()
+ s = fixture_session()
@assert_cycles()
def go():
@@ -1355,7 +1356,7 @@ class CycleTest(_fixtures.FixtureTest):
def test_query_joins(self):
User, Address = self.classes("User", "Address")
- s = Session()
+ s = fixture_session()
# cycles here are due to ClauseElement._cloned_set, others
# as of cache key
@@ -1368,7 +1369,7 @@ class CycleTest(_fixtures.FixtureTest):
def test_query_joinedload(self):
User, Address = self.classes("User", "Address")
- s = Session()
+ s = fixture_session()
def generate():
s.query(User).options(joinedload(User.addresses)).all()
@@ -1388,7 +1389,7 @@ class CycleTest(_fixtures.FixtureTest):
@assert_cycles()
def go():
- str(users.join(addresses))
+ str(users.join(addresses).compile(testing.db))
go()
@@ -1400,7 +1401,7 @@ class CycleTest(_fixtures.FixtureTest):
@assert_cycles(7)
def go():
s = select(users).select_from(users.join(addresses))
- state = s._compile_state_factory(s, s.compile())
+ state = s._compile_state_factory(s, s.compile(testing.db))
state.froms
go()
@@ -1410,7 +1411,7 @@ class CycleTest(_fixtures.FixtureTest):
@assert_cycles()
def go():
- str(orm_join(User, Address, User.addresses))
+ str(orm_join(User, Address, User.addresses).compile(testing.db))
go()
@@ -1418,7 +1419,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
@assert_cycles()
def go():
@@ -1430,7 +1431,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
@assert_cycles()
def go():
@@ -1442,7 +1443,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@@ -1460,7 +1461,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@@ -1475,7 +1476,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@@ -1491,7 +1492,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@@ -1507,7 +1508,7 @@ class CycleTest(_fixtures.FixtureTest):
User, Address = self.classes("User", "Address")
configure_mappers()
- s = Session()
+ s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
diff --git a/test/aaa_profiling/test_orm.py b/test/aaa_profiling/test_orm.py
index 547672961..f163078d8 100644
--- a/test/aaa_profiling/test_orm.py
+++ b/test/aaa_profiling/test_orm.py
@@ -20,6 +20,7 @@ from sqlalchemy.orm import sessionmaker
from sqlalchemy.testing import config
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import profiling
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -100,8 +101,8 @@ class MergeTest(NoCache, fixtures.MappedTest):
def test_merge_no_load(self):
Parent = self.classes.Parent
- sess = sessionmaker()()
- sess2 = sessionmaker()()
+ sess = fixture_session()
+ sess2 = fixture_session()
p1 = sess.query(Parent).get(1)
p1.children
@@ -129,8 +130,8 @@ class MergeTest(NoCache, fixtures.MappedTest):
def test_merge_load(self):
Parent = self.classes.Parent
- sess = sessionmaker()()
- sess2 = sessionmaker()()
+ sess = fixture_session()
+ sess2 = fixture_session()
p1 = sess.query(Parent).get(1)
p1.children
@@ -228,7 +229,7 @@ class LoadManyToOneFromIdentityTest(NoCache, fixtures.MappedTest):
def test_many_to_one_load_no_identity(self):
Parent = self.classes.Parent
- sess = Session()
+ sess = fixture_session()
parents = sess.query(Parent).all()
@profiling.function_call_count(variance=0.2)
@@ -241,7 +242,7 @@ class LoadManyToOneFromIdentityTest(NoCache, fixtures.MappedTest):
def test_many_to_one_load_identity(self):
Parent, Child = self.classes.Parent, self.classes.Child
- sess = Session()
+ sess = fixture_session()
parents = sess.query(Parent).all()
children = sess.query(Child).all()
children # strong reference
@@ -335,7 +336,7 @@ class MergeBackrefsTest(NoCache, fixtures.MappedTest):
self.classes.C,
self.classes.D,
)
- s = Session()
+ s = fixture_session()
for a in [
A(
id=i,
@@ -398,7 +399,7 @@ class DeferOptionsTest(NoCache, fixtures.MappedTest):
def test_baseline(self):
# as of [ticket:2778], this is at 39025
A = self.classes.A
- s = Session()
+ s = fixture_session()
s.query(A).all()
@profiling.function_call_count(variance=0.10)
@@ -406,7 +407,7 @@ class DeferOptionsTest(NoCache, fixtures.MappedTest):
# with [ticket:2778], this goes from 50805 to 32817,
# as it should be fewer function calls than the baseline
A = self.classes.A
- s = Session()
+ s = fixture_session()
s.query(A).options(
*[defer(letter) for letter in ["x", "y", "z", "p", "q", "r"]]
).all()
@@ -546,7 +547,7 @@ class SessionTest(NoCache, fixtures.MappedTest):
Parent(children=[Child() for j in range(10)]) for i in range(10)
]
- sess = Session()
+ sess = fixture_session()
sess.add_all(obj)
sess.flush()
@@ -588,7 +589,7 @@ class QueryTest(NoCache, fixtures.MappedTest):
def _fixture(self):
Parent = self.classes.Parent
- sess = Session()
+ sess = fixture_session()
sess.add_all(
[
Parent(data1="d1", data2="d2", data3="d3", data4="d4")
@@ -601,7 +602,7 @@ class QueryTest(NoCache, fixtures.MappedTest):
def test_query_cols(self):
Parent = self.classes.Parent
self._fixture()
- sess = Session()
+ sess = fixture_session()
# warm up cache
for attr in [Parent.data1, Parent.data2, Parent.data3, Parent.data4]:
@@ -695,7 +696,7 @@ class SelectInEagerLoadTest(NoCache, fixtures.MappedTest):
def test_round_trip_results(self):
A, B, C = self.classes("A", "B", "C")
- sess = Session()
+ sess = fixture_session()
q = sess.query(A).options(selectinload(A.bs).selectinload(B.cs))
@@ -835,7 +836,7 @@ class JoinedEagerLoadTest(NoCache, fixtures.MappedTest):
def test_build_query(self):
A, B, C, D, E, F, G = self.classes("A", "B", "C", "D", "E", "F", "G")
- sess = Session()
+ sess = fixture_session()
@profiling.function_call_count()
def go():
@@ -1122,7 +1123,7 @@ class BranchedOptionTest(NoCache, fixtures.MappedTest):
base.joinedload(B.fs),
]
- q = Session().query(A)
+ q = fixture_session().query(A)
context = q._compile_state()
@@ -1149,7 +1150,7 @@ class BranchedOptionTest(NoCache, fixtures.MappedTest):
base.joinedload(B.fs),
]
- q = Session().query(A)
+ q = fixture_session().query(A)
context = q._compile_state()
@@ -1201,7 +1202,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_no_bundle(self):
A = self.classes.A
- s = Session()
+ s = fixture_session()
q = s.query(A).select_from(A)
@@ -1215,7 +1216,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_no_entity_wo_annotations(self):
A = self.classes.A
a = self.tables.a
- s = Session()
+ s = fixture_session()
q = s.query(a.c.data).select_from(A)
@@ -1228,7 +1229,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_no_entity_w_annotations(self):
A = self.classes.A
- s = Session()
+ s = fixture_session()
q = s.query(A.data).select_from(A)
@profiling.function_call_count(warmup=1)
@@ -1240,7 +1241,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_entity_w_annotations(self):
A = self.classes.A
- s = Session()
+ s = fixture_session()
q = s.query(A, A.data).select_from(A)
@profiling.function_call_count(warmup=1)
@@ -1253,7 +1254,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_entity_wo_annotations(self):
A = self.classes.A
a = self.tables.a
- s = Session()
+ s = fixture_session()
q = s.query(A, a.c.data).select_from(A)
@profiling.function_call_count(warmup=1)
@@ -1266,7 +1267,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_no_bundle_wo_annotations(self):
A = self.classes.A
a = self.tables.a
- s = Session()
+ s = fixture_session()
q = s.query(a.c.data, A).select_from(A)
@profiling.function_call_count(warmup=1)
@@ -1278,7 +1279,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_no_bundle_w_annotations(self):
A = self.classes.A
- s = Session()
+ s = fixture_session()
q = s.query(A.data, A).select_from(A)
@profiling.function_call_count(warmup=1)
@@ -1291,7 +1292,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_bundle_wo_annotation(self):
A = self.classes.A
a = self.tables.a
- s = Session()
+ s = fixture_session()
q = s.query(Bundle("ASdf", a.c.data), A).select_from(A)
@profiling.function_call_count(warmup=1)
@@ -1303,7 +1304,7 @@ class AnnotatedOverheadTest(NoCache, fixtures.MappedTest):
def test_bundle_w_annotation(self):
A = self.classes.A
- s = Session()
+ s = fixture_session()
q = s.query(Bundle("ASdf", A.data), A).select_from(A)
@profiling.function_call_count(warmup=1)
diff --git a/test/aaa_profiling/test_resultset.py b/test/aaa_profiling/test_resultset.py
index c48ff53d4..ae0ea4992 100644
--- a/test/aaa_profiling/test_resultset.py
+++ b/test/aaa_profiling/test_resultset.py
@@ -166,10 +166,10 @@ class ResultSetTest(fixtures.TablesTest, AssertsExecutionResults):
# seem to be handling this for a profile that skips
result.close()
- def test_contains_doesnt_compile(self):
+ def test_contains_doesnt_compile(self, connection):
t, t2 = self.tables("table1", "table2")
- row = t.select().execute().first()
+ row = connection.execute(t.select()).first()
c1 = Column("some column", Integer) + Column(
"some other column", Integer
)