Skip to content

Commit a131f4e

Browse files
pbasistakvesteri
authored andcommitted
Remove deprecation warnings (kvesteri#373)
* Use sqlalchemy.orm.session.close_all_sessions The current call to sqlalchemy.orm.session.Session.close_all has been deprecated since SQLAlchemy version 1.3: https://docs.sqlalchemy.org/en/13/orm/session_api.html#sqlalchemy.orm.session.Session.close_all * Use "postgresql" instead of "postgres" as dialect name A deprecation warning about the usage of "postgres" dialect has been introduced to SQLAlchemy in this commit: sqlalchemy/sqlalchemy@c59bf00 * Use a correct name "usefixtures", not "usefixture" https://docs.pytest.org/en/latest/reference.html#pytest-mark-usefixtures * Use get_zonefile_instance instead of the deprecated gettz It has been deprecated by this commit: dateutil/dateutil@f0b433a Closes issue kvesteri#274.
1 parent 1263ff8 commit a131f4e

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sqlalchemy.ext.declarative import declarative_base, synonym_for
88
from sqlalchemy.ext.hybrid import hybrid_property
99
from sqlalchemy.orm import sessionmaker
10+
from sqlalchemy.orm.session import close_all_sessions
1011
from sqlalchemy_utils import (
1112
aggregates,
1213
coercion_listener,
@@ -54,7 +55,7 @@ def mysql_db_user():
5455

5556
@pytest.fixture
5657
def postgresql_dsn(postgresql_db_user, db_name):
57-
return 'postgres://{0}@localhost/{1}'.format(postgresql_db_user, db_name)
58+
return 'postgresql://{0}@localhost/{1}'.format(postgresql_db_user, db_name)
5859

5960

6061
@pytest.fixture
@@ -218,7 +219,7 @@ def session(request, engine, connection, Base, init_models):
218219

219220
def teardown():
220221
aggregates.manager.reset()
221-
session.close_all()
222+
close_all_sessions()
222223
Base.metadata.drop_all(connection)
223224
remove_composite_listeners()
224225
connection.close()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_version():
3333
'psycopg2>=2.5.1',
3434
'pg8000>=1.12.4',
3535
'pytz>=2014.2',
36-
'python-dateutil>=2.2',
36+
'python-dateutil>=2.6',
3737
'pymysql',
3838
'flake8>=2.4.0',
3939
'isort>=4.2.2',

sqlalchemy_utils/functions/database.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,13 @@ def database_exists(url):
438438
Performs backend-specific testing to quickly determine if a database
439439
exists on the server. ::
440440
441-
database_exists('postgres://postgres@localhost/name') #=> False
442-
create_database('postgres://postgres@localhost/name')
443-
database_exists('postgres://postgres@localhost/name') #=> True
441+
database_exists('postgresql://postgres@localhost/name') #=> False
442+
create_database('postgresql://postgres@localhost/name')
443+
database_exists('postgresql://postgres@localhost/name') #=> True
444444
445445
Supports checking against a constructed URL as well. ::
446446
447-
engine = create_engine('postgres://postgres@localhost/name')
447+
engine = create_engine('postgresql://postgres@localhost/name')
448448
database_exists(engine.url) #=> False
449449
create_database(engine.url)
450450
database_exists(engine.url) #=> True
@@ -523,7 +523,7 @@ def create_database(url, encoding='utf8', template=None):
523523
To create a database, you can pass a simple URL that would have
524524
been passed to ``create_engine``. ::
525525
526-
create_database('postgres://postgres@localhost/name')
526+
create_database('postgresql://postgres@localhost/name')
527527
528528
You may also pass the url from an existing engine. ::
529529
@@ -598,7 +598,7 @@ def drop_database(url):
598598
Works similar to the :ref:`create_database` method in that both url text
599599
and a constructed url are accepted. ::
600600
601-
drop_database('postgres://postgres@localhost/name')
601+
drop_database('postgresql://postgres@localhost/name')
602602
drop_database(engine.url)
603603
604604
"""

sqlalchemy_utils/types/timezone.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def __init__(self, backend='dateutil'):
3838
if backend == 'dateutil':
3939
try:
4040
from dateutil.tz import tzfile
41-
from dateutil.zoneinfo import gettz
41+
from dateutil.zoneinfo import get_zonefile_instance
4242

4343
self.python_type = tzfile
44-
self._to = gettz
44+
self._to = get_zonefile_instance().zones.get
4545
self._from = lambda x: six.text_type(x._filename)
4646

4747
except ImportError:

tests/functions/test_database.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_exists_memory(self, dsn):
2727
assert database_exists(dsn)
2828

2929

30-
@pytest.mark.usefixture('sqlite_none_database_dsn')
30+
@pytest.mark.usefixtures('sqlite_none_database_dsn')
3131
class TestDatabaseSQLiteMemoryNoDatabaseString(object):
3232
def test_exists_memory_none_database(self, sqlite_none_database_dsn):
3333
assert database_exists(sqlite_none_database_dsn)
@@ -75,7 +75,7 @@ def test_template(self, postgresql_db_user):
7575
"TEMPLATE my_template"
7676
)
7777
)
78-
dsn = 'postgres://{0}@localhost/db_test_sqlalchemy_util'.format(
78+
dsn = 'postgresql://{0}@localhost/db_test_sqlalchemy_util'.format(
7979
postgresql_db_user
8080
)
8181
create_database(dsn, template='my_template')
@@ -108,7 +108,7 @@ def test_template(self, postgresql_db_user):
108108
'TEMPLATE "my-template"'
109109
)
110110
)
111-
dsn = 'postgres://{0}@localhost/db_test_sqlalchemy-util'.format(
111+
dsn = 'postgresql://{0}@localhost/db_test_sqlalchemy-util'.format(
112112
postgresql_db_user
113113
)
114114
create_database(dsn, template='my-template')
@@ -117,7 +117,7 @@ def test_template(self, postgresql_db_user):
117117
class TestDatabasePostgresCreateDatabaseCloseConnection(object):
118118
def test_create_database_twice(self, postgresql_db_user):
119119
dsn_list = [
120-
'postgres://{0}@localhost/db_test_sqlalchemy-util-a'.format(
120+
'postgresql://{0}@localhost/db_test_sqlalchemy-util-a'.format(
121121
postgresql_db_user
122122
),
123123
'postgres://{0}@localhost/db_test_sqlalchemy-util-b'.format(

0 commit comments

Comments
 (0)