From 657fb2941d48adb2956dd17fae50c6f6e7614015 Mon Sep 17 00:00:00 2001 From: Alexander Egorov Date: Mon, 25 Feb 2019 15:21:44 +0700 Subject: [PATCH] Support Python 3.7 (#57) * Fix minor issues to support python 3.7 * Set travis dist to xenial to support python 3.7 --- .travis.yml | 5 +++-- tests/test_encodings.py | 25 ++++++++++++++----------- tox.ini | 6 +----- winter/schema/type_inspection.py | 2 +- winter/type_utils.py | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51fa5842..0c4bff4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ -dist: trusty +dist: xenial sudo: required language: python cache: pip python: - '3.6' +- '3.7' install: - pip install -r requirements/ci.txt @@ -13,7 +14,7 @@ before_script: - coverage erase script: -- tox -e py36 +- tox after_success: - | diff --git a/tests/test_encodings.py b/tests/test_encodings.py index 256bb6a2..116ff4bd 100644 --- a/tests/test_encodings.py +++ b/tests/test_encodings.py @@ -79,23 +79,26 @@ def test_encoder(value, expected_value): assert expected_value == json.loads(json.dumps(value, cls=encoder_class)) -@pytest.mark.parametrize(('value', 'exception_type', 'exception_message'), ( +@pytest.mark.parametrize(('value', 'exception_type', 'exception_messages'), ( + ( + datetime.time(hour=3, minute=50, second=20, tzinfo=pytz.UTC), + ValueError, + ("JSON can't represent timezone-aware times.", ), + ), + ( + object(), + TypeError, ( - datetime.time(hour=3, minute=50, second=20, tzinfo=pytz.UTC), - ValueError, - "JSON can't represent timezone-aware times." - ), - ( - object(), - TypeError, - f"Object of type '{object.__name__}' is not JSON serializable" + f"Object of type '{object.__name__}' is not JSON serializable", + f"Object of type {object.__name__} is not JSON serializable", ), + ), )) -def test_encoder_with_raises(value, exception_type, exception_message): +def test_encoder_with_raises(value, exception_type, exception_messages): encoder_class = get_encoder_class() data = {'key': value} with pytest.raises(exception_type) as exception: json.dumps(data, cls=encoder_class) - assert exception.value.args == (exception_message, ) + assert exception.value.args[0] in exception_messages diff --git a/tox.ini b/tox.ini index dfbe3995..04e89b63 100644 --- a/tox.ini +++ b/tox.ini @@ -7,8 +7,4 @@ deps = -rrequirements/test.txt commands = - pytest --cov --cov-config .coveragerc --cov-append --cov-report="" - -[pytest] -filterwarnings = - error + pytest --cov --cov-config .coveragerc --cov-append --cov-report="" -vv diff --git a/winter/schema/type_inspection.py b/winter/schema/type_inspection.py index 1223b020..d9385873 100644 --- a/winter/schema/type_inspection.py +++ b/winter/schema/type_inspection.py @@ -165,7 +165,7 @@ def inspect_enum(enum_class: typing.Type[enum.Enum]) -> TypeInfo: return type_info -@register_type_inspector(UnionType, checker=is_optional) +@register_type_inspector(object, checker=is_optional) def inspect_optional(hint_class) -> TypeInfo: child_type = hint_class.__args__[0] type_info = inspect_type(child_type) diff --git a/winter/type_utils.py b/winter/type_utils.py index b2d88ef5..bc413a40 100644 --- a/winter/type_utils.py +++ b/winter/type_utils.py @@ -19,7 +19,7 @@ def is_iterable(typing: object) -> bool: def is_union(typing: object) -> bool: - return isinstance(typing, UnionType) + return get_origin_type(typing) == Union def get_origin_type(hint_class):