Skip to content

Commit

Permalink
Support Python 3.7 (#57)
Browse files Browse the repository at this point in the history
* Fix minor issues to support python 3.7

* Set travis dist to xenial to support python 3.7
  • Loading branch information
mofr authored Feb 25, 2019
1 parent 78f0243 commit 657fb29
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,7 +14,7 @@ before_script:
- coverage erase

script:
- tox -e py36
- tox

after_success:
- |
Expand Down
25 changes: 14 additions & 11 deletions tests/test_encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion winter/schema/type_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion winter/type_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 657fb29

Please sign in to comment.