Skip to content

Commit

Permalink
Fix deprecation warnings (#379)
Browse files Browse the repository at this point in the history
* Fix deprecation warnings

* Fix import of Sequence
  • Loading branch information
Le-Stagiaire authored and kvesteri committed Jul 15, 2019
1 parent bc42df9 commit 4a04b5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions sqlalchemy_utils/functions/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import collections
try:
from collections.abc import Mapping, Sequence
except ImportError: # For python 2.7 support
from collections import Mapping, Sequence
import itertools
import os
from copy import copy
Expand Down Expand Up @@ -167,7 +170,7 @@ def json_sql(value, scalars_to_json=True):
def scalar_convert(a):
return sa.func.to_json(sa.text(a))

if isinstance(value, collections.Mapping):
if isinstance(value, Mapping):
return sa.func.json_build_object(
*(
json_sql(v, scalars_to_json=False)
Expand All @@ -176,7 +179,7 @@ def scalar_convert(a):
)
elif isinstance(value, str):
return scalar_convert("'{0}'".format(value))
elif isinstance(value, collections.Sequence):
elif isinstance(value, Sequence):
return sa.func.json_build_array(
*(
json_sql(v, scalars_to_json=False)
Expand Down
3 changes: 2 additions & 1 deletion tests/types/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.session import close_all_sessions

from sqlalchemy_utils import (
CompositeArray,
Expand Down Expand Up @@ -324,7 +325,7 @@ def teardown():
session.execute('DROP TABLE account')
session.execute('DROP TYPE money_type')
session.commit()
session.close_all()
close_all_sessions()
connection.close()
remove_composite_listeners()
engine.dispose()
Expand Down
8 changes: 4 additions & 4 deletions tests/types/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_check_and_update(self, User):
from passlib.hash import md5_crypt

obj = User()
obj.password = Password(md5_crypt.encrypt('b'))
obj.password = Password(md5_crypt.hash('b'))

assert obj.password.hash.decode('utf8').startswith('$1$')
assert obj.password == 'b'
Expand Down Expand Up @@ -139,10 +139,10 @@ def test_compare(self, User):
from passlib.hash import md5_crypt

obj = User()
obj.password = Password(md5_crypt.encrypt('b'))
obj.password = Password(md5_crypt.hash('b'))

other = User()
other.password = Password(md5_crypt.encrypt('b'))
other.password = Password(md5_crypt.hash('b'))

# Not sure what to assert here; the test raised an error before.
assert obj.password != other.password
Expand Down Expand Up @@ -203,7 +203,7 @@ def test_check_and_update_persist(self, session, User):
from passlib.hash import md5_crypt

obj = User()
obj.password = Password(md5_crypt.encrypt('b'))
obj.password = Password(md5_crypt.hash('b'))

session.add(obj)
session.commit()
Expand Down

0 comments on commit 4a04b5c

Please sign in to comment.