diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-12-01 10:53:16 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-12-02 14:51:12 -0500 |
| commit | f70b321661fa5b3fcf8672fcbcbe63870a77129c (patch) | |
| tree | 92c5dd66c89f1cf95ff2e31104be2708ff42ba61 /test | |
| parent | 55e0497b080bf7f5159faa5abcb341269ebfdc7f (diff) | |
| download | sqlalchemy-f70b321661fa5b3fcf8672fcbcbe63870a77129c.tar.gz | |
Removals: MetaData.bind, Table.bind, all other .bind
Change-Id: I1ef2eb2018f4b68825fe40a2a8d99084cf217b35
References: #7257
Diffstat (limited to 'test')
| -rw-r--r-- | test/engine/test_deprecations.py | 185 | ||||
| -rw-r--r-- | test/orm/declarative/test_deprecations.py | 57 | ||||
| -rw-r--r-- | test/orm/test_deprecations.py | 61 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 94 | ||||
| -rw-r--r-- | test/sql/test_metadata.py | 2 |
5 files changed, 5 insertions, 394 deletions
diff --git a/test/engine/test_deprecations.py b/test/engine/test_deprecations.py index b75d9c978..454a6c629 100644 --- a/test/engine/test_deprecations.py +++ b/test/engine/test_deprecations.py @@ -2,9 +2,7 @@ import re from unittest.mock import Mock import sqlalchemy as tsa -import sqlalchemy as sa from sqlalchemy import create_engine -from sqlalchemy import engine from sqlalchemy import event from sqlalchemy import exc from sqlalchemy import ForeignKey @@ -16,8 +14,6 @@ from sqlalchemy import pool from sqlalchemy import select from sqlalchemy import String from sqlalchemy import testing -from sqlalchemy import text -from sqlalchemy import ThreadLocalMetaData from sqlalchemy.engine import BindTyping from sqlalchemy.engine import reflection from sqlalchemy.engine.base import Connection @@ -32,9 +28,7 @@ from sqlalchemy.testing import engines from sqlalchemy.testing import eq_ from sqlalchemy.testing import fixtures from sqlalchemy.testing import is_ -from sqlalchemy.testing import is_false from sqlalchemy.testing import is_instance_of -from sqlalchemy.testing import is_true from sqlalchemy.testing import mock from sqlalchemy.testing.assertions import expect_deprecated from sqlalchemy.testing.assertions import expect_raises_message @@ -61,185 +55,6 @@ class ConnectionlessDeprecationTest(fixtures.TestBase): with inspector._operation_context() as conn: is_instance_of(conn, Connection) - def test_bind_close_engine(self): - e = testing.db - with e.connect() as conn: - assert not conn.closed - assert conn.closed - - def test_bind_create_drop_err_metadata(self): - metadata = MetaData() - Table("test_table", metadata, Column("foo", Integer)) - for meth in [metadata.create_all, metadata.drop_all]: - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - assert_raises_message( - exc.UnboundExecutionError, - "MetaData object is not bound to an Engine or Connection.", - meth, - ) - - def test_bind_create_drop_err_table(self): - metadata = MetaData() - table = Table("test_table", metadata, Column("foo", Integer)) - - for meth in [table.create, table.drop]: - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - assert_raises_message( - exc.UnboundExecutionError, - ( - "Table object 'test_table' is not bound to an " - "Engine or Connection." - ), - meth, - ) - - def test_bind_create_drop_bound(self): - - for meta in (MetaData, ThreadLocalMetaData): - for bind in (testing.db, testing.db.connect()): - if isinstance(bind, engine.Connection): - bind.begin() - - if meta is ThreadLocalMetaData: - with testing.expect_deprecated( - "ThreadLocalMetaData is deprecated" - ): - metadata = meta() - else: - metadata = meta() - table = Table("test_table", metadata, Column("foo", Integer)) - metadata.bind = bind - assert metadata.bind is table.bind is bind - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - metadata.create_all() - - with testing.expect_deprecated( - r"The Table.exists\(\) method is deprecated and will " - "be removed in a future release." - ): - assert table.exists() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - metadata.drop_all() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - table.create() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - table.drop() - with testing.expect_deprecated( - r"The Table.exists\(\) method is deprecated and will " - "be removed in a future release." - ): - assert not table.exists() - - if meta is ThreadLocalMetaData: - with testing.expect_deprecated( - "ThreadLocalMetaData is deprecated" - ): - metadata = meta() - else: - metadata = meta() - - table = Table("test_table", metadata, Column("foo", Integer)) - - metadata.bind = bind - - assert metadata.bind is table.bind is bind - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - metadata.create_all() - with testing.expect_deprecated( - r"The Table.exists\(\) method is deprecated and will " - "be removed in a future release." - ): - assert table.exists() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - metadata.drop_all() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - table.create() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL" - ): - table.drop() - with testing.expect_deprecated( - r"The Table.exists\(\) method is deprecated and will " - "be removed in a future release." - ): - assert not table.exists() - if isinstance(bind, engine.Connection): - bind.close() - - def test_bind_create_drop_constructor_bound(self): - for bind in (testing.db, testing.db.connect()): - if isinstance(bind, engine.Connection): - bind.begin() - try: - for args in (([bind], {}), ([], {"bind": bind})): - with testing.expect_deprecated_20( - "The MetaData.bind argument is deprecated " - ): - metadata = MetaData(*args[0], **args[1]) - table = Table( - "test_table", metadata, Column("foo", Integer) - ) - assert metadata.bind is table.bind is bind - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods " - "that invoke SQL" - ): - metadata.create_all() - is_true(inspect(bind).has_table(table.name)) - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods " - "that invoke SQL" - ): - metadata.drop_all() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods " - "that invoke SQL" - ): - table.create() - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods " - "that invoke SQL" - ): - table.drop() - is_false(inspect(bind).has_table(table.name)) - finally: - if isinstance(bind, engine.Connection): - bind.close() - - def test_bind_clauseelement(self, metadata): - table = Table("test_table", metadata, Column("foo", Integer)) - metadata.create_all(bind=testing.db) - for elem in [ - table.select, - lambda **kwargs: sa.func.current_timestamp(**kwargs).select(), - # func.current_timestamp().select, - lambda **kwargs: text("select * from test_table", **kwargs), - ]: - with testing.db.connect() as bind: - with testing.expect_deprecated_20( - "The .*bind argument is deprecated" - ): - e = elem(bind=bind) - assert e.bind is bind - def test_inspector_constructor_engine(self): with testing.expect_deprecated( r"The __init__\(\) method on Inspector is deprecated and will " diff --git a/test/orm/declarative/test_deprecations.py b/test/orm/declarative/test_deprecations.py deleted file mode 100644 index 0727baefd..000000000 --- a/test/orm/declarative/test_deprecations.py +++ /dev/null @@ -1,57 +0,0 @@ -from sqlalchemy import Integer -from sqlalchemy import testing -from sqlalchemy.orm import declarative_base -from sqlalchemy.orm import registry -from sqlalchemy.orm import Session -from sqlalchemy.testing import fixtures -from sqlalchemy.testing import is_ -from sqlalchemy.testing.schema import Column - - -class BoundMetadataDeclarativeTest(fixtures.MappedTest): - def test_bound_declarative_base(self): - with testing.expect_deprecated( - "The ``bind`` argument to declarative_base" - ): - Base = declarative_base(testing.db) - - class User(Base): - __tablename__ = "user" - id = Column(Integer, primary_key=True) - - s = Session() - - with testing.expect_deprecated_20( - "This Session located a target engine via bound metadata" - ): - is_(s.get_bind(User), testing.db) - - def test_bound_cls_registry_base(self): - reg = registry(_bind=testing.db) - - Base = reg.generate_base() - - class User(Base): - __tablename__ = "user" - id = Column(Integer, primary_key=True) - - s = Session() - with testing.expect_deprecated_20( - "This Session located a target engine via bound metadata" - ): - is_(s.get_bind(User), testing.db) - - def test_bound_cls_registry_decorated(self): - reg = registry(_bind=testing.db) - - @reg.mapped - class User: - __tablename__ = "user" - id = Column(Integer, primary_key=True) - - s = Session() - - with testing.expect_deprecated_20( - "This Session located a target engine via bound metadata" - ): - is_(s.get_bind(User), testing.db) diff --git a/test/orm/test_deprecations.py b/test/orm/test_deprecations.py index c16e95fc5..89e9a89e6 100644 --- a/test/orm/test_deprecations.py +++ b/test/orm/test_deprecations.py @@ -29,7 +29,6 @@ from sqlalchemy import true from sqlalchemy.engine import default from sqlalchemy.engine import result_tuple from sqlalchemy.orm import aliased -from sqlalchemy.orm import as_declarative from sqlalchemy.orm import attributes from sqlalchemy.orm import backref from sqlalchemy.orm import clear_mappers @@ -39,7 +38,6 @@ from sqlalchemy.orm import configure_mappers from sqlalchemy.orm import contains_alias from sqlalchemy.orm import contains_eager from sqlalchemy.orm import declarative_base -from sqlalchemy.orm import declared_attr from sqlalchemy.orm import defaultload from sqlalchemy.orm import defer from sqlalchemy.orm import deferred @@ -92,10 +90,6 @@ from .inheritance._poly_fixtures import Engineer from .inheritance._poly_fixtures import Manager from .inheritance._poly_fixtures import Person from .test_ac_relationships import PartitionByFixture -from .test_bind import GetBindTest as _GetBindTest -from .test_default_strategies import ( - DefaultStrategyOptionsTest as _DefaultStrategyOptionsTest, -) from .test_deferred import InheritanceTest as _deferred_InheritanceTest from .test_dynamic import _DynamicFixture from .test_events import _RemoveListeners @@ -106,6 +100,11 @@ from .test_query import QueryTest from .test_transaction import _LocalFixture from ..sql.test_compare import CacheKeyFixture +if True: + # hack - zimports won't stop reformatting this to be too-long for now + from .test_default_strategies import ( + DefaultStrategyOptionsTest as _DefaultStrategyOptionsTest, + ) join_aliased_dep = ( r"The ``aliased`` and ``from_joinpoint`` keyword arguments to " @@ -4325,33 +4324,6 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): eq_(list(q2), [(True,), (False,), (False,), (False,)]) -class DeclarativeBind(fixtures.TestBase): - def test_declarative_base(self): - with testing.expect_deprecated_20( - "The ``bind`` argument to declarative_base is " - "deprecated and will be removed in SQLAlchemy 2.0.", - ): - Base = declarative_base(bind=testing.db) - - is_true(Base.metadata.bind is testing.db) - - def test_as_declarative(self): - with testing.expect_deprecated_20( - "The ``bind`` argument to as_declarative is " - "deprecated and will be removed in SQLAlchemy 2.0.", - ): - - @as_declarative(bind=testing.db) - class Base: - @declared_attr - def __tablename__(cls): - return cls.__name__.lower() - - id = Column(Integer, primary_key=True) - - is_true(Base.metadata.bind is testing.db) - - class JoinTest(QueryTest, AssertsCompiledSQL): __dialect__ = "default" @@ -6103,29 +6075,6 @@ class BindSensitiveStringifyTest(fixtures.MappedTest): self._test(False, True, False) -class GetBindTest(_GetBindTest): - @classmethod - def define_tables(cls, metadata): - super(GetBindTest, cls).define_tables(metadata) - metadata.bind = testing.db - - def test_fallback_table_metadata(self): - session = self._fixture({}) - with testing.expect_deprecated_20( - "This Session located a target engine via bound metadata" - ): - is_(session.get_bind(self.classes.BaseClass), testing.db) - - def test_bind_base_table_concrete_sub_class(self): - base_class_bind = Mock() - session = self._fixture({self.tables.base_table: base_class_bind}) - - with testing.expect_deprecated_20( - "This Session located a target engine via bound metadata" - ): - is_(session.get_bind(self.classes.ConcreteSubClass), testing.db) - - class DeprecationScopedSessionTest(fixtures.MappedTest): def test_config_errors(self): sm = sessionmaker() diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 5828fbdcc..cd0b0f2c3 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -13,7 +13,6 @@ from sqlalchemy import exc from sqlalchemy import exists from sqlalchemy import ForeignKey from sqlalchemy import func -from sqlalchemy import inspect from sqlalchemy import Integer from sqlalchemy import join from sqlalchemy import literal_column @@ -65,70 +64,6 @@ class ToMetaDataTest(fixtures.TestBase): eq_(t2.name, "t") -class BoundMetadataTest(fixtures.TestBase): - def test_arg_deprecated(self): - with testing.expect_deprecated_20( - "The MetaData.bind argument is deprecated" - ): - m1 = MetaData(testing.db) - - Table("t", m1, Column("q", Integer)) - - with testing.expect_deprecated_20( - "The ``bind`` argument for schema methods that invoke SQL " - "against an engine or connection will be required" - ): - m1.create_all() - try: - assert "t" in inspect(testing.db).get_table_names() - finally: - m1.drop_all(testing.db) - - assert "t" not in inspect(testing.db).get_table_names() - - def test_bind_arg_text(self): - with testing.expect_deprecated_20( - "The text.bind argument is deprecated and will be " - "removed in SQLAlchemy 2.0." - ): - t1 = text("ASdf", bind=testing.db) - - # no warnings emitted - is_(t1.bind, testing.db) - eq_(str(t1), "ASdf") - - def test_bind_arg_function(self): - with testing.expect_deprecated_20( - "The text.bind argument is deprecated and will be " - "removed in SQLAlchemy 2.0." - ): - f1 = func.foobar(bind=testing.db) - - # no warnings emitted - is_(f1.bind, testing.db) - eq_(str(f1), "foobar()") - - def test_bind_arg_select(self): - with testing.expect_deprecated_20( - "The select.bind argument is deprecated and will be " - "removed in SQLAlchemy 2.0." - ): - s1 = select([column("q")], bind=testing.db) - - # no warnings emitted - is_(s1.bind, testing.db) - eq_(str(s1), "SELECT q") - - def test_bind_attr_join_no_warning(self): - t1 = table("t1", column("a")) - t2 = table("t2", column("b")) - j1 = join(t1, t2, t1.c.a == t2.c.b) - - # no warnings emitted - is_(j1.bind, None) - eq_(str(j1), "t1 JOIN t2 ON t1.a = t2.b") - - class DeprecationWarningsTest(fixtures.TestBase, AssertsCompiledSQL): __backend__ = True @@ -1728,35 +1663,6 @@ class LegacyOperatorTest(AssertsCompiledSQL, fixtures.TestBase): assert _op_modern == _op_legacy -class DDLDeprecatedBindTest(fixtures.TestBase): - def teardown_test(self): - with testing.db.begin() as conn: - if inspect(conn).has_table("foo"): - conn.execute(schema.DropTable(table("foo"))) - - @testing.combinations( - (schema.AddConstraint,), - (schema.DropConstraint,), - (schema.CreateSequence,), - (schema.DropSequence,), - (schema.CreateSchema,), - (schema.DropSchema,), - (schema.SetTableComment,), - (schema.DropTableComment,), - (schema.SetColumnComment,), - (schema.DropColumnComment,), - ) - def test_bind_other_constructs(self, const): - m1 = mock.Mock() - - with testing.expect_deprecated_20( - "The DDLElement.bind argument is deprecated" - ): - c1 = const(m1, bind=testing.db) - - is_(c1.bind, testing.db) - - class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): __dialect__ = "default" diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index e87063a90..b9abe4e71 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -820,7 +820,6 @@ class ToMetaDataTest(fixtures.TestBase, AssertsCompiledSQL, ComparesTables): def test_pickle(): meta.bind = testing.db meta2 = pickle.loads(pickle.dumps(meta)) - assert meta2.bind is None pickle.loads(pickle.dumps(meta2)) return ( meta2.tables["mytable"], @@ -836,7 +835,6 @@ class ToMetaDataTest(fixtures.TestBase, AssertsCompiledSQL, ComparesTables): Table("othertable", meta2, autoload_with=testing.db) Table("has_comments", meta2, autoload_with=testing.db) meta3 = pickle.loads(pickle.dumps(meta2)) - assert meta3.bind is None assert meta3.tables["mytable"] is not t1 return ( |
