diff options
author | Gord Thompson <gord@gordthompson.com> | 2021-11-08 11:03:54 -0700 |
---|---|---|
committer | Gord Thompson <gord@gordthompson.com> | 2021-11-09 06:12:39 -0700 |
commit | bd1be0b7e0ecd76bdf6d26fd11cc42e1a473b319 (patch) | |
tree | bcb527a334bb3da906b8c450f93f3dc3ed683a27 /test | |
parent | cf404d840c15fe167518dd884b295dc99ee26178 (diff) | |
download | sqlalchemy-bd1be0b7e0ecd76bdf6d26fd11cc42e1a473b319.tar.gz |
De-emphasize notion of "default driver" (DBAPI)
Fixes: #6960
Even though a default driver still exists for
each dialect, remove most usages of `dialect://`
to encourage users to explicitly specify
`dialect+driver://`
Change-Id: I0ad42167582df509138fca64996bbb53e379b1af
Diffstat (limited to 'test')
-rw-r--r-- | test/dialect/mssql/test_deprecations.py | 4 | ||||
-rw-r--r-- | test/dialect/mssql/test_engine.py | 25 | ||||
-rw-r--r-- | test/dialect/mysql/test_dialect.py | 6 | ||||
-rw-r--r-- | test/dialect/postgresql/test_dialect.py | 16 | ||||
-rw-r--r-- | test/engine/test_deprecations.py | 6 | ||||
-rw-r--r-- | test/engine/test_execute.py | 2 | ||||
-rw-r--r-- | test/engine/test_parseconnect.py | 72 | ||||
-rw-r--r-- | test/engine/test_reconnect.py | 4 | ||||
-rw-r--r-- | test/sql/test_deprecations.py | 4 |
9 files changed, 86 insertions, 53 deletions
diff --git a/test/dialect/mssql/test_deprecations.py b/test/dialect/mssql/test_deprecations.py index aecb813fa..24625d65c 100644 --- a/test/dialect/mssql/test_deprecations.py +++ b/test/dialect/mssql/test_deprecations.py @@ -64,14 +64,14 @@ class LegacySchemaAliasingTest(fixtures.TestBase, AssertsCompiledSQL): @testing.combinations( ( { - "sqlalchemy.url": "mssql://foodsn", + "sqlalchemy.url": "mssql+pyodbc://foodsn", "sqlalchemy.legacy_schema_aliasing": "true", }, True, ), ( { - "sqlalchemy.url": "mssql://foodsn", + "sqlalchemy.url": "mssql+pyodbc://foodsn", "sqlalchemy.legacy_schema_aliasing": "false", }, False, diff --git a/test/dialect/mssql/test_engine.py b/test/dialect/mssql/test_engine.py index 5482e2616..e14fd164a 100644 --- a/test/dialect/mssql/test_engine.py +++ b/test/dialect/mssql/test_engine.py @@ -32,26 +32,27 @@ from sqlalchemy.testing.mock import Mock class ParseConnectTest(fixtures.TestBase): def test_pyodbc_connect_dsn_trusted(self): dialect = pyodbc.dialect() - u = url.make_url("mssql://mydsn") + u = url.make_url("mssql+pyodbc://mydsn") connection = dialect.create_connect_args(u) eq_([["dsn=mydsn;Trusted_Connection=Yes"], {}], connection) def test_pyodbc_connect_old_style_dsn_trusted(self): dialect = pyodbc.dialect() - u = url.make_url("mssql:///?dsn=mydsn") + u = url.make_url("mssql+pyodbc:///?dsn=mydsn") connection = dialect.create_connect_args(u) eq_([["dsn=mydsn;Trusted_Connection=Yes"], {}], connection) def test_pyodbc_connect_dsn_non_trusted(self): dialect = pyodbc.dialect() - u = url.make_url("mssql://username:password@mydsn") + u = url.make_url("mssql+pyodbc://username:password@mydsn") connection = dialect.create_connect_args(u) eq_([["dsn=mydsn;UID=username;PWD=password"], {}], connection) def test_pyodbc_connect_dsn_extra(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql://username:password@mydsn/?LANGUAGE=us_" "english&foo=bar" + "mssql+pyodbc://username:password@mydsn/?LANGUAGE=us_" + "english&foo=bar" ) connection = dialect.create_connect_args(u) dsn_string = connection[0][0] @@ -61,7 +62,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_hostname(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql://username:password@hostspec/database?driver=SQL+Server" + "mssql+pyodbc://username:password@hostspec/database?driver=SQL+Server" # noqa ) connection = dialect.create_connect_args(u) eq_( @@ -84,7 +85,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_host_no_driver(self): dialect = pyodbc.dialect() - u = url.make_url("mssql://username:password@hostspec/database") + u = url.make_url("mssql+pyodbc://username:password@hostspec/database") def go(): return dialect.create_connect_args(u) @@ -111,7 +112,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_connect_comma_port(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql://username:password@hostspec:12345/data" + "mssql+pyodbc://username:password@hostspec:12345/data" "base?driver=SQL Server" ) connection = dialect.create_connect_args(u) @@ -129,7 +130,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_connect_config_port(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql://username:password@hostspec/database?p" + "mssql+pyodbc://username:password@hostspec/database?p" "ort=12345&driver=SQL+Server" ) connection = dialect.create_connect_args(u) @@ -147,7 +148,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_extra_connect(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql://username:password@hostspec/database?L" + "mssql+pyodbc://username:password@hostspec/database?L" "ANGUAGE=us_english&foo=bar&driver=SQL+Server" ) connection = dialect.create_connect_args(u) @@ -186,7 +187,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_odbc_connect(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql:///?odbc_connect=DRIVER%3D%7BSQL+Server" + "mssql+pyodbc:///?odbc_connect=DRIVER%3D%7BSQL+Server" "%7D%3BServer%3Dhostspec%3BDatabase%3Ddatabase" "%3BUID%3Dusername%3BPWD%3Dpassword" ) @@ -205,7 +206,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_odbc_connect_with_dsn(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql:///?odbc_connect=dsn%3Dmydsn%3BDatabase" + "mssql+pyodbc:///?odbc_connect=dsn%3Dmydsn%3BDatabase" "%3Ddatabase%3BUID%3Dusername%3BPWD%3Dpassword" ) connection = dialect.create_connect_args(u) @@ -217,7 +218,7 @@ class ParseConnectTest(fixtures.TestBase): def test_pyodbc_odbc_connect_ignores_other_values(self): dialect = pyodbc.dialect() u = url.make_url( - "mssql://userdiff:passdiff@localhost/dbdiff?od" + "mssql+pyodbc://userdiff:passdiff@localhost/dbdiff?od" "bc_connect=DRIVER%3D%7BSQL+Server%7D%3BServer" "%3Dhostspec%3BDatabase%3Ddatabase%3BUID%3Duse" "rname%3BPWD%3Dpassword" diff --git a/test/dialect/mysql/test_dialect.py b/test/dialect/mysql/test_dialect.py index 834e1874c..9a0f2bc0d 100644 --- a/test/dialect/mysql/test_dialect.py +++ b/test/dialect/mysql/test_dialect.py @@ -202,7 +202,7 @@ class DialectTest(fixtures.TestBase): dialect = mysqldb.dialect() connect_args = dialect.create_connect_args( make_url( - "mysql://scott:tiger@localhost:3306/test" + "mysql+mysqldb://scott:tiger@localhost:3306/test" "?%s=%s" % (kwarg, value) ) ) @@ -262,7 +262,7 @@ class DialectTest(fixtures.TestBase): def test_random_arg(self): dialect = testing.db.dialect kw = dialect.create_connect_args( - make_url("mysql://u:p@host/db?foo=true") + make_url("mysql+mysqldb://u:p@host/db?foo=true") )[1] eq_(kw["foo"], "true") @@ -303,7 +303,7 @@ class DialectTest(fixtures.TestBase): class ParseVersionTest(fixtures.TestBase): def test_mariadb_madness(self): - mysql_dialect = make_url("mysql://").get_dialect()() + mysql_dialect = make_url("mysql+mysqldb://").get_dialect()() is_(mysql_dialect.is_mariadb, False) diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index e7c4ebb7c..fe3700bbb 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -171,42 +171,44 @@ $$ LANGUAGE plpgsql;""" def test_psycopg2_empty_connection_string(self): dialect = psycopg2_dialect.dialect() - u = url.make_url("postgresql://") + u = url.make_url("postgresql+psycopg2://") cargs, cparams = dialect.create_connect_args(u) eq_(cargs, [""]) eq_(cparams, {}) def test_psycopg2_nonempty_connection_string(self): dialect = psycopg2_dialect.dialect() - u = url.make_url("postgresql://host") + u = url.make_url("postgresql+psycopg2://host") cargs, cparams = dialect.create_connect_args(u) eq_(cargs, []) eq_(cparams, {"host": "host"}) def test_psycopg2_empty_connection_string_w_query_one(self): dialect = psycopg2_dialect.dialect() - u = url.make_url("postgresql:///?service=swh-log") + u = url.make_url("postgresql+psycopg2:///?service=swh-log") cargs, cparams = dialect.create_connect_args(u) eq_(cargs, []) eq_(cparams, {"service": "swh-log"}) def test_psycopg2_empty_connection_string_w_query_two(self): dialect = psycopg2_dialect.dialect() - u = url.make_url("postgresql:///?any_random_thing=yes") + u = url.make_url("postgresql+psycopg2:///?any_random_thing=yes") cargs, cparams = dialect.create_connect_args(u) eq_(cargs, []) eq_(cparams, {"any_random_thing": "yes"}) def test_psycopg2_nonempty_connection_string_w_query(self): dialect = psycopg2_dialect.dialect() - u = url.make_url("postgresql://somehost/?any_random_thing=yes") + u = url.make_url( + "postgresql+psycopg2://somehost/?any_random_thing=yes" + ) cargs, cparams = dialect.create_connect_args(u) eq_(cargs, []) eq_(cparams, {"host": "somehost", "any_random_thing": "yes"}) def test_psycopg2_nonempty_connection_string_w_query_two(self): dialect = psycopg2_dialect.dialect() - url_string = "postgresql://USER:PASS@/DB?host=hostA" + url_string = "postgresql+psycopg2://USER:PASS@/DB?host=hostA" u = url.make_url(url_string) cargs, cparams = dialect.create_connect_args(u) eq_(cargs, []) @@ -215,7 +217,7 @@ $$ LANGUAGE plpgsql;""" def test_psycopg2_nonempty_connection_string_w_query_three(self): dialect = psycopg2_dialect.dialect() url_string = ( - "postgresql://USER:PASS@/DB" + "postgresql+psycopg2://USER:PASS@/DB" "?host=hostA:portA&host=hostB&host=hostC" ) u = url.make_url(url_string) diff --git a/test/engine/test_deprecations.py b/test/engine/test_deprecations.py index 6e7169d12..956524abd 100644 --- a/test/engine/test_deprecations.py +++ b/test/engine/test_deprecations.py @@ -278,7 +278,7 @@ class CreateEngineTest(fixtures.TestBase): "only argument accepted is 'mock'" ): e = create_engine( - "postgresql://", strategy="mock", executor=executor + "postgresql+psycopg2://", strategy="mock", executor=executor ) assert isinstance(e, MockConnection) @@ -292,7 +292,7 @@ class CreateEngineTest(fixtures.TestBase): tsa.exc.ArgumentError, "unknown strategy: 'threadlocal'", create_engine, - "postgresql://", + "postgresql+psycopg2://", strategy="threadlocal", ) @@ -302,7 +302,7 @@ class CreateEngineTest(fixtures.TestBase): "and no longer has any effect." ): create_engine( - "postgresql://", + "postgresql+psycopg2://", empty_in_strategy="static", module=Mock(), _initialize=False, diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index afe95ba82..3b691ebc9 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1161,7 +1161,7 @@ class MockStrategyTest(fixtures.TestBase): def dump(sql, *multiparams, **params): buf.write(util.text_type(sql.compile(dialect=engine.dialect))) - engine = create_mock_engine("postgresql://", executor=dump) + engine = create_mock_engine("postgresql+psycopg2://", executor=dump) return engine, buf def test_sequence_not_duped(self): diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 044dc2cbd..f0a1dba4b 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -16,6 +16,7 @@ from sqlalchemy.testing import is_ from sqlalchemy.testing import is_false from sqlalchemy.testing import is_true from sqlalchemy.testing import mock +from sqlalchemy.testing import ne_ from sqlalchemy.testing.assertions import expect_deprecated from sqlalchemy.testing.assertions import expect_raises_message from sqlalchemy.testing.mock import call @@ -447,7 +448,7 @@ class CreateEngineTest(fixtures.TestBase): def test_connect_query(self): dbapi = MockDBAPI(foober="12", lala="18", fooz="somevalue") e = create_engine( - "postgresql://scott:tiger@somehost/test?foobe" + "postgresql+psycopg2://scott:tiger@somehost/test?foobe" "r=12&lala=18&fooz=somevalue", module=dbapi, _initialize=False, @@ -459,7 +460,8 @@ class CreateEngineTest(fixtures.TestBase): foober=12, lala=18, hoho={"this": "dict"}, fooz="somevalue" ) e = create_engine( - "postgresql://scott:tiger@somehost/test?fooz=" "somevalue", + "postgresql+psycopg2://scott:tiger@somehost/test?fooz=" + "somevalue", connect_args={"foober": 12, "lala": 18, "hoho": {"this": "dict"}}, module=dbapi, _initialize=False, @@ -470,7 +472,7 @@ class CreateEngineTest(fixtures.TestBase): dbapi = mock_dbapi config = { - "sqlalchemy.url": "postgresql://scott:tiger@somehost/test" + "sqlalchemy.url": "postgresql+psycopg2://scott:tiger@somehost/test" "?fooz=somevalue", "sqlalchemy.pool_recycle": "50", "sqlalchemy.echo": "true", @@ -479,7 +481,7 @@ class CreateEngineTest(fixtures.TestBase): e = engine_from_config(config, module=dbapi, _initialize=False) assert e.pool._recycle == 50 assert e.url == url.make_url( - "postgresql://scott:tiger@somehost/test?foo" "z=somevalue" + "postgresql+psycopg2://scott:tiger@somehost/test?foo" "z=somevalue" ) assert e.echo is True @@ -487,7 +489,7 @@ class CreateEngineTest(fixtures.TestBase): dbapi = mock_dbapi config = { - "sqlalchemy.url": "postgresql://scott:tiger@somehost/test" + "sqlalchemy.url": "postgresql+psycopg2://scott:tiger@somehost/test" "?fooz=somevalue", "sqlalchemy.future": "true", } @@ -498,7 +500,7 @@ class CreateEngineTest(fixtures.TestBase): dbapi = mock_dbapi config = { - "sqlalchemy.url": "postgresql://scott:tiger@somehost/test" + "sqlalchemy.url": "postgresql+psycopg2://scott:tiger@somehost/test" "?fooz=somevalue", "sqlalchemy.future": "false", } @@ -519,7 +521,7 @@ class CreateEngineTest(fixtures.TestBase): ("none", pool.reset_none), ]: config = { - "sqlalchemy.url": "postgresql://scott:tiger@somehost/test", + "sqlalchemy.url": "postgresql+psycopg2://scott:tiger@somehost/test", # noqa "sqlalchemy.pool_reset_on_return": value, } @@ -603,7 +605,10 @@ class CreateEngineTest(fixtures.TestBase): # module instead of psycopg e = create_engine( - "postgresql://", creator=connect, module=dbapi, _initialize=False + "postgresql+psycopg2://", + creator=connect, + module=dbapi, + _initialize=False, ) e.connect() @@ -612,7 +617,10 @@ class CreateEngineTest(fixtures.TestBase): foober=12, lala=18, hoho={"this": "dict"}, fooz="somevalue" ) e = create_engine( - "postgresql://", pool_recycle=472, module=dbapi, _initialize=False + "postgresql+psycopg2://", + pool_recycle=472, + module=dbapi, + _initialize=False, ) assert e.pool._recycle == 472 @@ -628,7 +636,7 @@ class CreateEngineTest(fixtures.TestBase): (False, pool.reset_none), ]: e = create_engine( - "postgresql://", + "postgresql+psycopg2://", pool_reset_on_return=value, module=dbapi, _initialize=False, @@ -638,7 +646,7 @@ class CreateEngineTest(fixtures.TestBase): assert_raises( exc.ArgumentError, create_engine, - "postgresql://", + "postgresql+psycopg2://", pool_reset_on_return="hi", module=dbapi, _initialize=False, @@ -654,7 +662,7 @@ class CreateEngineTest(fixtures.TestBase): assert_raises( TypeError, create_engine, - "postgresql://", + "postgresql+psycopg2://", use_ansi=True, module=mock_dbapi, ) @@ -672,7 +680,7 @@ class CreateEngineTest(fixtures.TestBase): assert_raises( TypeError, create_engine, - "postgresql://", + "postgresql+psycopg2://", lala=5, module=mock_dbapi, ) @@ -695,25 +703,25 @@ class CreateEngineTest(fixtures.TestBase): """test the url attribute on ``Engine``.""" e = create_engine( - "mysql://scott:tiger@localhost/test", + "mysql+mysqldb://scott:tiger@localhost/test", module=mock_dbapi, _initialize=False, ) - u = url.make_url("mysql://scott:tiger@localhost/test") + u = url.make_url("mysql+mysqldb://scott:tiger@localhost/test") e2 = create_engine(u, module=mock_dbapi, _initialize=False) - assert e.url.drivername == e2.url.drivername == "mysql" + assert e.url.drivername == e2.url.drivername == "mysql+mysqldb" assert e.url.username == e2.url.username == "scott" assert e2.url is u - assert str(u) == "mysql://scott:tiger@localhost/test" - assert repr(u) == "mysql://scott:***@localhost/test" - assert repr(e) == "Engine(mysql://scott:***@localhost/test)" - assert repr(e2) == "Engine(mysql://scott:***@localhost/test)" + assert str(u) == "mysql+mysqldb://scott:tiger@localhost/test" + assert repr(u) == "mysql+mysqldb://scott:***@localhost/test" + assert repr(e) == "Engine(mysql+mysqldb://scott:***@localhost/test)" + assert repr(e2) == "Engine(mysql+mysqldb://scott:***@localhost/test)" def test_poolargs(self): """test that connection pool args make it thru""" e = create_engine( - "postgresql://", + "postgresql+psycopg2://", creator=None, pool_recycle=50, echo_pool=None, @@ -725,7 +733,7 @@ class CreateEngineTest(fixtures.TestBase): # these args work for QueuePool e = create_engine( - "postgresql://", + "postgresql+psycopg2://", max_overflow=8, pool_timeout=60, poolclass=tsa.pool.QueuePool, @@ -783,6 +791,26 @@ class CreateEngineTest(fixtures.TestBase): e.connect() eq_(sp.called, 1) + def test_default_driver(self): + successes = 0 + for url_prefix, driver_name in [ + ("mariadb://", "mysqldb"), + ("mssql://", "pyodbc"), + ("mysql://", "mysqldb"), + ("oracle://", "cx_oracle"), + ("postgresql://", "psycopg2"), + ("sqlite://", "pysqlite"), + ]: + try: + en = create_engine(url_prefix) + eq_(en.dialect.driver, driver_name) + successes += 1 + except ModuleNotFoundError: + # not all test environments will have every driver installed + pass + # but we should at least find one + ne_(successes, 0, "No default drivers found.") + class TestRegNewDBAPI(fixtures.TestBase): def test_register_base(self): diff --git a/test/engine/test_reconnect.py b/test/engine/test_reconnect.py index 0c7f86a62..c9894b0f2 100644 --- a/test/engine/test_reconnect.py +++ b/test/engine/test_reconnect.py @@ -166,7 +166,7 @@ class PrePingMockTest(fixtures.TestBase): def _pool_fixture(self, pre_ping, pool_kw=None): dialect = url.make_url( - "postgresql://foo:bar@localhost/test" + "postgresql+psycopg2://foo:bar@localhost/test" ).get_dialect()() dialect.dbapi = self.dbapi _pool = pool.QueuePool( @@ -360,7 +360,7 @@ class MockReconnectTest(fixtures.TestBase): self.dbapi = MockDBAPI() self.db = testing_engine( - "postgresql://foo:bar@localhost/test", + "postgresql+psycopg2://foo:bar@localhost/test", options=dict(module=self.dbapi, _initialize=False), ) diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 22b743434..93e280d4e 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -178,7 +178,9 @@ class DeprecationWarningsTest(fixtures.TestBase, AssertsCompiledSQL): "The create_engine.convert_unicode parameter and " "corresponding dialect-level" ): - create_engine("mysql://", convert_unicode=True, module=mock.Mock()) + create_engine( + "mysql+mysqldb://", convert_unicode=True, module=mock.Mock() + ) def test_empty_and_or(self): with testing.expect_deprecated( |