summaryrefslogtreecommitdiff
path: root/test/orm
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2023-05-10 15:11:06 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2023-05-10 15:11:06 +0000
commitbce61160a9aec321ea0af4a59d4b83ff93a0429f (patch)
tree3754696c2d8f97d92507309ef4c13037b7372bf3 /test/orm
parent987285fb4b13c39bcc6b8922e618d9e830577dda (diff)
parent60b31198311eedfa3814e7098c94d3aa29338fdd (diff)
downloadsqlalchemy-bce61160a9aec321ea0af4a59d4b83ff93a0429f.tar.gz
Merge "fix test suite warnings" into main
Diffstat (limited to 'test/orm')
-rw-r--r--test/orm/declarative/test_basic.py1
-rw-r--r--test/orm/declarative/test_inheritance.py1
-rw-r--r--test/orm/inheritance/test_relationship.py1
-rw-r--r--test/orm/test_collection.py3
-rw-r--r--test/orm/test_deprecations.py15
-rw-r--r--test/orm/test_eager_relations.py4
-rw-r--r--test/orm/test_joins.py1
-rw-r--r--test/orm/test_relationships.py89
-rw-r--r--test/orm/test_session.py26
-rw-r--r--test/orm/test_utils.py4
10 files changed, 56 insertions, 89 deletions
diff --git a/test/orm/declarative/test_basic.py b/test/orm/declarative/test_basic.py
index 2ccbc19f1..130f3da45 100644
--- a/test/orm/declarative/test_basic.py
+++ b/test/orm/declarative/test_basic.py
@@ -1394,7 +1394,6 @@ class DeclarativeMultiBaseTest(
r"non-schema SQLAlchemy expression object; ",
r"Attribute 'y' on class <class .*Foo5.* appears to be a "
r"non-schema SQLAlchemy expression object; ",
- raise_on_any_unexpected=True,
):
class Foo5(Base):
diff --git a/test/orm/declarative/test_inheritance.py b/test/orm/declarative/test_inheritance.py
index 333d24230..7d66c0d0b 100644
--- a/test/orm/declarative/test_inheritance.py
+++ b/test/orm/declarative/test_inheritance.py
@@ -1026,7 +1026,6 @@ class DeclarativeInheritanceTest(
if not combine_on_b and not omit_from_statements:
ctx = expect_warnings(
"Implicitly combining column a.extra with column b.extra",
- raise_on_any_unexpected=True,
)
else:
ctx = contextlib.nullcontext()
diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py
index 6d168d2ce..ab9c29918 100644
--- a/test/orm/inheritance/test_relationship.py
+++ b/test/orm/inheritance/test_relationship.py
@@ -61,7 +61,6 @@ def _aliased_join_warning(arg):
return testing.expect_warnings(
r"An alias is being generated automatically against joined entity "
r"Mapper\[%s\] due to overlapping tables" % (arg,),
- raise_on_any_unexpected=True,
)
diff --git a/test/orm/test_collection.py b/test/orm/test_collection.py
index 650b30aaa..85efbe0a3 100644
--- a/test/orm/test_collection.py
+++ b/test/orm/test_collection.py
@@ -2928,7 +2928,6 @@ class AttrKeyedDictKeysTest(fixtures.TestBase):
"'bs' was None;",
"Attribute keyed dictionary value for attribute "
"'B.a' was None;",
- raise_on_any_unexpected=True,
):
a1 = A(bs={"k1": b1, "k2": b2})
sess.add(a1)
@@ -2943,7 +2942,6 @@ class AttrKeyedDictKeysTest(fixtures.TestBase):
with expect_warnings(
"Attribute keyed dictionary value for attribute "
"'unknown relationship' was None;",
- raise_on_any_unexpected=True,
):
eq_(a1.bs, {None: b2})
@@ -3074,7 +3072,6 @@ class UnpopulatedAttrTest(fixtures.TestBase):
with expect_warnings(
"Attribute keyed dictionary value for attribute "
"'B.a' was None;",
- raise_on_any_unexpected=True,
):
b1.a = a1
else:
diff --git a/test/orm/test_deprecations.py b/test/orm/test_deprecations.py
index a3e2f4ef7..db64f91f1 100644
--- a/test/orm/test_deprecations.py
+++ b/test/orm/test_deprecations.py
@@ -414,7 +414,6 @@ class MiscDeprecationsTest(fixtures.TestBase):
with expect_deprecated(
rf"The column_property.{paramname} parameter is deprecated "
r"for column_property\(\)",
- raise_on_any_unexpected=True,
):
column_property(column("q"), **{paramname: value})
@@ -429,7 +428,6 @@ class MiscDeprecationsTest(fixtures.TestBase):
r"for column_property\(\)",
r"The column_property.kw_only parameter is deprecated "
r"for column_property\(\)",
- raise_on_any_unexpected=True,
):
class MyClass(dc_decl_base):
@@ -488,7 +486,8 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL):
s = addresses.select()
sess = fixture_session()
with testing.expect_deprecated(
- "Implicit coercion of SELECT and " "textual SELECT constructs"
+ "Implicit coercion of SELECT and textual SELECT constructs",
+ "An alias is being generated automatically against joined entity",
):
self.assert_compile(
sess.query(User).join(s, User.addresses),
@@ -1592,7 +1591,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
def go():
with testing.expect_deprecated(
"The AliasOption object is not necessary for entities to be "
- "matched up to a query"
+ "matched up to a query",
):
result = (
q.options(
@@ -1624,7 +1623,8 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
def go():
with testing.expect_deprecated(
- r"Using the Query.instances\(\) method without a context"
+ r"The Query.instances\(\) method is deprecated",
+ r"Using the Query.instances\(\) method without a context",
):
result = list(
q.options(contains_eager(User.addresses)).instances(
@@ -1639,7 +1639,8 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
def go():
with testing.expect_deprecated(
- r"Using the Query.instances\(\) method without a context"
+ r"The Query.instances\(\) method is deprecated",
+ r"Using the Query.instances\(\) method without a context",
):
result = list(
q.options(contains_eager(User.addresses)).instances(
@@ -1674,7 +1675,6 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
r"Using the Query.instances\(\) method without a context",
r"The Query.instances\(\) method is deprecated and will be "
r"removed in a future release.",
- raise_on_any_unexpected=True,
):
result = list(
q.options(
@@ -1721,7 +1721,6 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
r"Using the Query.instances\(\) method without a context",
r"The Query.instances\(\) method is deprecated and will be "
r"removed in a future release.",
- raise_on_any_unexpected=True,
):
result = list(
q.options(
diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py
index ef6d4b684..fa44dbf10 100644
--- a/test/orm/test_eager_relations.py
+++ b/test/orm/test_eager_relations.py
@@ -1656,7 +1656,7 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
def go():
eq_(u1.addresses[0].user, u1)
- with testing.expect_warnings(raise_on_any_unexpected=True):
+ with testing.expect_warnings():
self.assert_sql_execution(
testing.db,
go,
@@ -1707,7 +1707,7 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
def go():
eq_(u1.addresses[0].user, u1)
- with testing.expect_warnings(raise_on_any_unexpected=True):
+ with testing.expect_warnings():
self.assert_sql_execution(
testing.db,
go,
diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py
index 3120a160d..ff684d846 100644
--- a/test/orm/test_joins.py
+++ b/test/orm/test_joins.py
@@ -170,7 +170,6 @@ class InheritedJoinTest(InheritedTest, AssertsCompiledSQL):
r"Mapper\[Manager\(managers\)\] due to overlapping",
"An alias is being generated automatically against joined entity "
r"Mapper\[Boss\(boss\)\] due to overlapping",
- raise_on_any_unexpected=True,
):
self.assert_compile(
q,
diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py
index 0cbcc01f3..12651fe36 100644
--- a/test/orm/test_relationships.py
+++ b/test/orm/test_relationships.py
@@ -33,7 +33,6 @@ from sqlalchemy.orm.interfaces import MANYTOONE
from sqlalchemy.orm.interfaces import ONETOMANY
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
-from sqlalchemy.testing import assert_warns_message
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import expect_raises_message
@@ -656,18 +655,15 @@ class OverlappingFksSiblingTest(fixtures.MappedTest):
add_bsub2_a_viewonly=False,
add_b_a_overlaps=None,
):
-
Base = self.mapper_registry.generate_base()
class A(Base):
-
__tablename__ = "a"
id = Column(Integer, primary_key=True)
a_members = relationship("AMember", backref="a")
class AMember(Base):
-
__tablename__ = "a_member"
a_id = Column(Integer, ForeignKey("a.id"), primary_key=True)
@@ -707,14 +703,12 @@ class OverlappingFksSiblingTest(fixtures.MappedTest):
# however, *no* warning should be emitted otherwise.
class BSub1(B):
-
if add_bsub1_a:
a = relationship("A")
__mapper_args__ = {"polymorphic_identity": "bsub1"}
class BSub2(B):
-
if add_bsub2_a_viewonly:
a = relationship("A", viewonly=True)
@@ -729,7 +723,6 @@ class OverlappingFksSiblingTest(fixtures.MappedTest):
return A, AMember, B, BSub1, BSub2
def _fixture_two(self, setup_backrefs=False, setup_overlaps=False):
-
Base = self.mapper_registry.generate_base()
# purposely using the comma to make sure parsing the comma works
@@ -874,15 +867,13 @@ class OverlappingFksSiblingTest(fixtures.MappedTest):
@testing.provide_metadata
def test_simple_warn(self):
- assert_warns_message(
- exc.SAWarning,
+ with expect_warnings(
r"relationship '(?:Child.parent|Parent.children)' will copy "
r"column parent.id to column child.parent_id, which conflicts "
r"with relationship\(s\): '(?:Parent.children|Child.parent)' "
- r"\(copies parent.id to child.parent_id\).",
- self._fixture_two,
- setup_backrefs=False,
- )
+ r"\(copies parent.id to child.parent_id\)."
+ ):
+ self._fixture_two(setup_backrefs=False)
@testing.combinations((True,), (False,), argnames="set_overlaps")
def test_fixture_five(self, metadata, set_overlaps):
@@ -965,15 +956,12 @@ class OverlappingFksSiblingTest(fixtures.MappedTest):
@testing.provide_metadata
def test_double_rel_same_mapper_warns(self):
- assert_warns_message(
- exc.SAWarning,
+ with expect_warnings(
r"relationship 'Parent.child[12]' will copy column parent.id to "
r"column child.parent_id, which conflicts with relationship\(s\): "
- r"'Parent.child[12]' \(copies parent.id to child.parent_id\)",
- self._fixture_three,
- use_same_mappers=True,
- setup_overlaps=False,
- )
+ r"'Parent.child[12]' \(copies parent.id to child.parent_id\)"
+ ):
+ self._fixture_three(use_same_mappers=True, setup_overlaps=False)
@testing.provide_metadata
def test_double_rel_same_mapper_overlaps_works(self):
@@ -985,48 +973,37 @@ class OverlappingFksSiblingTest(fixtures.MappedTest):
@testing.provide_metadata
def test_warn_one(self):
- assert_warns_message(
- exc.SAWarning,
+ with expect_warnings(
r"relationship '(?:BSub1.a|BSub2.a_member|B.a)' will copy column "
- r"(?:a.id|a_member.a_id) to column b.a_id",
- self._fixture_one,
- add_b_a=True,
- add_bsub1_a=True,
- )
+ r"(?:a.id|a_member.a_id) to column b.a_id"
+ ):
+ self._fixture_one(add_b_a=True, add_bsub1_a=True)
@testing.provide_metadata
def test_warn_two(self):
- assert_warns_message(
- exc.SAWarning,
+ with expect_warnings(
r"relationship '(?:BSub1.a|B.a_member)' will copy column "
- r"(?:a.id|a_member.a_id) to column b.a_id",
- self._fixture_one,
- add_b_amember=True,
- add_bsub1_a=True,
- )
+ r"(?:a.id|a_member.a_id) to column b.a_id"
+ ):
+ self._fixture_one(add_b_amember=True, add_bsub1_a=True)
@testing.provide_metadata
def test_warn_three(self):
- assert_warns_message(
- exc.SAWarning,
- r"relationship '(?:BSub1.a|B.a_member|B.a)' will copy column "
- r"(?:a.id|a_member.a_id) to column b.a_id",
- self._fixture_one,
- add_b_amember=True,
- add_bsub1_a=True,
- add_b_a=True,
- )
+ with expect_warnings(
+ r"relationship '(?:BSub1.a|B.a_member|BSub2.a_member|B.a)' "
+ r"will copy column (?:a.id|a_member.a_id) to column b.a_id",
+ ):
+ self._fixture_one(
+ add_b_amember=True, add_bsub1_a=True, add_b_a=True
+ )
@testing.provide_metadata
def test_warn_four(self):
- assert_warns_message(
- exc.SAWarning,
+ with expect_warnings(
r"relationship '(?:B.a|BSub2.a_member|B.a)' will copy column "
- r"(?:a.id|a_member.a_id) to column b.a_id",
- self._fixture_one,
- add_bsub2_a_viewonly=True,
- add_b_a=True,
- )
+ r"(?:a.id|a_member.a_id) to column b.a_id"
+ ):
+ self._fixture_one(add_bsub2_a_viewonly=True, add_b_a=True)
@testing.provide_metadata
def test_works_one(self):
@@ -1303,12 +1280,11 @@ class CompositeSelfRefFKTest(fixtures.MappedTest, AssertsCompiledSQL):
},
)
- assert_warns_message(
- exc.SAWarning,
+ with expect_warnings(
r"relationship .* will copy column .* to column "
- r"employee_t.company_id, which conflicts with relationship\(s\)",
- configure_mappers,
- )
+ r"employee_t.company_id, which conflicts with relationship\(s\)"
+ ):
+ configure_mappers()
def test_annotated_no_overwriting(self):
Employee, Company, employee_t, company_t = (
@@ -2537,7 +2513,6 @@ class JoinConditionErrorTest(fixtures.TestBase):
argnames="argname, arg",
)
def test_invalid_string_args(self, registry, argname, arg):
-
kw = {argname: arg}
Base = registry.generate_base()
@@ -4789,7 +4764,6 @@ class SecondaryNestedJoinTest(
)
def test_render_lazyload(self):
-
A = self.classes.A
sess = fixture_session()
a1 = sess.query(A).filter(A.name == "a1").first()
@@ -5968,7 +5942,6 @@ class InactiveHistoryNoRaiseTest(_fixtures.FixtureTest):
delete,
legacy_inactive_history_style,
):
-
if delete:
assert not backref, "delete and backref are mutually exclusive"
diff --git a/test/orm/test_session.py b/test/orm/test_session.py
index 5a0431788..395603a77 100644
--- a/test/orm/test_session.py
+++ b/test/orm/test_session.py
@@ -36,6 +36,7 @@ from sqlalchemy.testing import config
from sqlalchemy.testing import engines
from sqlalchemy.testing import eq_
from sqlalchemy.testing import expect_raises_message
+from sqlalchemy.testing import expect_warnings
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
from sqlalchemy.testing import is_false
@@ -108,7 +109,6 @@ class ExecutionTest(_fixtures.FixtureTest):
)
def test_no_string_execute(self, connection):
-
with Session(bind=connection) as sess:
with expect_raises_message(
sa.exc.ArgumentError,
@@ -242,7 +242,6 @@ class TransScopingTest(_fixtures.FixtureTest):
self.mapper_registry.map_imperatively(Address, addresses)
with Session(testing.db) as sess:
-
sess.add(User(name="u1"))
sess.commit()
@@ -2293,13 +2292,13 @@ class FlushWarningsTest(fixtures.MappedTest):
def evt(mapper, conn, instance):
instance.addresses.append(Address(email="x1"))
- self._test(evt, "collection append")
+ self._test(evt, "collection append", "related attribute set")
def test_o2m_cascade_remove(self):
def evt(mapper, conn, instance):
del instance.addresses[0]
- self._test(evt, "collection remove")
+ self._test(evt, "collection remove", "related attribute set")
def test_m2o_cascade_add(self):
User = self.classes.User
@@ -2308,14 +2307,19 @@ class FlushWarningsTest(fixtures.MappedTest):
instance.addresses[0].user = User(name="u2")
with expect_raises_message(orm_exc.FlushError, ".*Over 100"):
- self._test(evt, "related attribute set")
+ self._test(
+ evt,
+ "related attribute set",
+ "collection remove",
+ "collection append",
+ )
def test_m2o_cascade_remove(self):
def evt(mapper, conn, instance):
a1 = instance.addresses[0]
del a1.user
- self._test(evt, "related attribute delete")
+ self._test(evt, "related attribute delete", "collection remove")
def test_plain_add(self):
Address = self.classes.Address
@@ -2344,7 +2348,7 @@ class FlushWarningsTest(fixtures.MappedTest):
):
self._test(evt, r"Session.delete\(\)")
- def _test(self, fn, method):
+ def _test(self, fn, *methods):
User = self.classes.User
Address = self.classes.Address
@@ -2353,6 +2357,8 @@ class FlushWarningsTest(fixtures.MappedTest):
u1 = User(name="u1", addresses=[Address(name="a1")])
s.add(u1)
- assert_warns_message(
- sa.exc.SAWarning, "Usage of the '%s'" % method, s.commit
- )
+
+ with expect_warnings(
+ *[f"Usage of the '{method}'" for method in methods]
+ ):
+ s.commit()
diff --git a/test/orm/test_utils.py b/test/orm/test_utils.py
index 3bd0230de..4d6c14863 100644
--- a/test/orm/test_utils.py
+++ b/test/orm/test_utils.py
@@ -78,7 +78,6 @@ class ContextualWarningsTest(fixtures.TestBase):
"bar.foo_id, which conflicts with relationship(s): 'Foo.bars' "
"(copies foo.id to bar.foo_id). "
),
- raise_on_any_unexpected=True,
):
decl_base.registry.configure()
@@ -96,7 +95,6 @@ class ContextualWarningsTest(fixtures.TestBase):
"invoked automatically in response to a user-initiated "
"operation.)"
),
- raise_on_any_unexpected=True,
):
FooAlias = aliased(Foo)
assert hasattr(FooAlias, "bars")
@@ -115,7 +113,6 @@ class ContextualWarningsTest(fixtures.TestBase):
"invoked automatically in response to a user-initiated "
"operation.)"
),
- raise_on_any_unexpected=True,
):
foo = Foo()
assert hasattr(foo, "bars")
@@ -145,7 +142,6 @@ class ContextualWarningsTest(fixtures.TestBase):
"process, which was invoked automatically in response to a "
"user-initiated operation.)"
),
- raise_on_any_unexpected=True,
):
sess.execute(select(Foo))