-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade packages and fix pytest warnings (#388)
* Fix warnings reported by Pytest * Replace calls to utcnow with now(UTC) * Introduce a new function called `utcnow_func` in protean.utils to use as default * Replace pkgutil with importlib functions * Remove support 3.8, 3.9, and 3.10 * Remove Protean's own importlib.py file * Call datetime.now(UTC) on utcnow_func invocation * Add test for utcnow_func * Add test on comparing meta of different classes * Upgrade coverage and linked packages
- Loading branch information
Showing
30 changed files
with
104 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1 @@ | ||
""" Module defines utilities for importing modules and packages """ | ||
|
||
import importlib.util | ||
|
||
from importlib import import_module | ||
|
||
|
||
def perform_import(val): | ||
""" | ||
If the given setting is a string import notation, | ||
then perform the necessary import or imports. | ||
""" | ||
if val is not None: | ||
if isinstance(val, str): | ||
return import_from_string(val) | ||
elif isinstance(val, (list, tuple)): | ||
return [import_from_string(item) for item in val] | ||
|
||
return val | ||
|
||
|
||
def import_from_string(val, package=None): | ||
""" | ||
Attempt to import a class from a string representation. | ||
""" | ||
try: | ||
module_path, class_name = val.rsplit(".", 1) | ||
module = import_module(module_path, package=package) | ||
return getattr(module, class_name) | ||
except (ImportError, AttributeError) as e: | ||
msg = f"Could not import {val}. {e.__class__.__name__}: {e}" | ||
raise ImportError(msg) | ||
|
||
|
||
def import_from_full_path(domain, path): | ||
spec = importlib.util.spec_from_file_location(domain, path) | ||
mod = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(mod) | ||
|
||
return getattr(mod, domain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from datetime import datetime | ||
from datetime import UTC, datetime | ||
|
||
import pytest | ||
|
||
|
@@ -110,7 +110,7 @@ def test_array_content_type_validation(test_domain): | |
{"email": "[email protected]", "roles": [1, 2]}, | ||
{"email": "[email protected]", "roles": ["1", 2]}, | ||
{"email": "[email protected]", "roles": [1.0, 2.0]}, | ||
{"email": "[email protected]", "roles": [datetime.utcnow()]}, | ||
{"email": "[email protected]", "roles": [datetime.now(UTC)]}, | ||
]: | ||
with pytest.raises(ValidationError) as exception: | ||
ArrayUser(**kwargs) | ||
|
@@ -127,7 +127,7 @@ def test_array_content_type_validation(test_domain): | |
for kwargs in [ | ||
{"email": "[email protected]", "roles": ["ADMIN", "USER"]}, | ||
{"email": "[email protected]", "roles": ["1", "2"]}, | ||
{"email": "[email protected]", "roles": [datetime.utcnow()]}, | ||
{"email": "[email protected]", "roles": [datetime.now(UTC)]}, | ||
]: | ||
with pytest.raises(ValidationError) as exception: | ||
IntegerArrayUser(**kwargs) | ||
|
5 changes: 2 additions & 3 deletions
5
tests/adapters/model/sqlalchemy_model/postgresql/test_json_datatype.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from datetime import datetime | ||
from datetime import UTC, datetime | ||
|
||
import pytest | ||
|
||
|
@@ -40,7 +40,7 @@ def test_array_content_type_validation(test_domain): | |
{"email": "[email protected]", "roles": [1, 2]}, | ||
{"email": "[email protected]", "roles": ["1", 2]}, | ||
{"email": "[email protected]", "roles": [1.0, 2.0]}, | ||
{"email": "[email protected]", "roles": [datetime.utcnow()]}, | ||
{"email": "[email protected]", "roles": [datetime.now(UTC)]}, | ||
]: | ||
with pytest.raises(ValidationError) as exception: | ||
ListUser(**kwargs) | ||
|
@@ -57,7 +57,7 @@ def test_array_content_type_validation(test_domain): | |
for kwargs in [ | ||
{"email": "[email protected]", "roles": ["ADMIN", "USER"]}, | ||
{"email": "[email protected]", "roles": ["1", "2"]}, | ||
{"email": "[email protected]", "roles": [datetime.utcnow()]}, | ||
{"email": "[email protected]", "roles": [datetime.now(UTC)]}, | ||
]: | ||
with pytest.raises(ValidationError) as exception: | ||
IntegerListUser(**kwargs) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from datetime import datetime | ||
from datetime import UTC, datetime | ||
|
||
import pytest | ||
|
||
|
@@ -60,7 +60,7 @@ def test_array_content_type_validation(test_domain): | |
{"email": "[email protected]", "roles": [1, 2]}, | ||
{"email": "[email protected]", "roles": ["1", 2]}, | ||
{"email": "[email protected]", "roles": [1.0, 2.0]}, | ||
{"email": "[email protected]", "roles": [datetime.utcnow()]}, | ||
{"email": "[email protected]", "roles": [datetime.now(UTC)]}, | ||
]: | ||
with pytest.raises(ValidationError) as exception: | ||
ArrayUser(**kwargs) | ||
|
@@ -77,7 +77,7 @@ def test_array_content_type_validation(test_domain): | |
for kwargs in [ | ||
{"email": "[email protected]", "roles": ["ADMIN", "USER"]}, | ||
{"email": "[email protected]", "roles": ["1", "2"]}, | ||
{"email": "[email protected]", "roles": [datetime.utcnow()]}, | ||
{"email": "[email protected]", "roles": [datetime.now(UTC)]}, | ||
]: | ||
with pytest.raises(ValidationError) as exception: | ||
IntegerArrayUser(**kwargs) | ||
|
5 changes: 2 additions & 3 deletions
5
tests/adapters/model/sqlalchemy_model/sqlite/test_json_datatype.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.