Skip to content

Commit

Permalink
skip tests for python < 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
loyada committed Dec 9, 2023
1 parent 8e50b02 commit 9406374
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions tests/test_deserialization.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import enum
import operator
import sys
from collections import OrderedDict, deque
from decimal import Decimal
from typing import Optional

from pytest import raises
from pytest import raises, mark

from typedpy import (
Boolean,
Expand Down Expand Up @@ -199,8 +200,8 @@ def test_anyof_field_failure():
with raises(ValueError) as excinfo:
deserialize_structure(Example, data)
assert (
"any: Got [{'name': 'john', 'ssid': '123'}, {'name': 'paul'}]; Does not match any field option"
in str(excinfo.value)
"any: Got [{'name': 'john', 'ssid': '123'}, {'name': 'paul'}]; Does not match any field option"
in str(excinfo.value)
)


Expand Down Expand Up @@ -300,8 +301,8 @@ class UnsupportedStruct(Structure):
with raises(NotImplementedError) as excinfo:
deserialize_structure(UnsupportedStruct, {"unsupported": 1})
assert (
"unsupported: Got 1; Cannot deserialize value of type UnsupportedField"
in str(excinfo.value)
"unsupported: Got 1; Cannot deserialize value of type UnsupportedField"
in str(excinfo.value)
)


Expand All @@ -312,8 +313,8 @@ class Foo(Structure):
with raises(ValueError) as excinfo:
deserialize_structure(Foo, {"bar": 1})
assert (
"bar: Got 1; Does not match <Array>. reason: bar: Got 1; Expected a list, set, or tuple"
in str(excinfo.value)
"bar: Got 1; Does not match <Array>. reason: bar: Got 1; Expected a list, set, or tuple"
in str(excinfo.value)
)


Expand All @@ -330,8 +331,8 @@ def test_invalid_type_err():
with raises(ValueError) as excinfo:
deserialize_structure(Example, data)
assert (
"all: Got ''; Does not match <Number>. reason: all: Got ''; Expected a number"
in str(excinfo.value)
"all: Got ''; Does not match <Number>. reason: all: Got ''; Expected a number"
in str(excinfo.value)
)


Expand Down Expand Up @@ -386,8 +387,8 @@ def test_invalid_value_err():
with raises(ValueError) as excinfo:
deserialize_structure(Example, data)
assert (
"""name: Got '123'; Does not match regular expression: '[A-Za-z]+$'"""
in str(excinfo.value)
"""name: Got '123'; Does not match regular expression: '[A-Za-z]+$'"""
in str(excinfo.value)
)


Expand Down Expand Up @@ -1210,8 +1211,8 @@ class Foo(Structure):
with raises(ValueError) as excinfo:
Deserializer(target_class=Foo, mapper=mapper)
assert (
"Invalid key in mapper for class Foo: xyz. Keys must be one of the class fields"
in str(excinfo.value)
"Invalid key in mapper for class Foo: xyz. Keys must be one of the class fields"
in str(excinfo.value)
)


Expand Down Expand Up @@ -1317,8 +1318,8 @@ class Foo(Structure):
Deserializer(target_class=Foo).deserialize({"s": None, "a": None, "i": 1})
assert "missing a required argument: 's'" in str(excinfo.value)
assert (
Deserializer(target_class=Foo).deserialize({"s": "x", "a": None, "i": 1}).a
is None
Deserializer(target_class=Foo).deserialize({"s": "x", "a": None, "i": 1}).a
is None
)


Expand Down Expand Up @@ -1516,7 +1517,7 @@ class Foo(Structure):
in str(excinfo.value)
)


@mark.skipif(sys.version_info < (3, 9), reason="requires python3.9 or higher")
def test_smart_compact_deserialization_is_turned_off_by_default():
class Foo(Structure):
a: list[int]
Expand All @@ -1529,9 +1530,10 @@ class Foo(Structure):
in str(excinfo.value)
)

@mark.skipif(sys.version_info < (3, 9), reason="requires python3.9 or higher")
def test_smart_compact_deserialization_is_turned_on(compact_serialization):
class Foo(Structure):
a: list[int]
_additional_properties = False

assert Deserializer(Foo).deserialize([2, 3]) == Foo(a=[2,3])
assert Deserializer(Foo).deserialize([2, 3]) == Foo(a=[2, 3])

0 comments on commit 9406374

Please sign in to comment.