-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
535 additions
and
547 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import sys | ||
|
||
PY39 = sys.version_info[:2] >= (3, 9) | ||
PY310 = sys.version_info[:2] >= (3, 10) |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from typing import Dict, List, Literal, Set, Tuple, Union | ||
|
||
from tests.formats.dataclass.models.cases import PY39, PY310 | ||
from xsdata.models.enums import Mode | ||
|
||
tokens = [ | ||
(int, False), | ||
(Dict[int, int], False), | ||
(Dict, False), | ||
(Literal["foo"], False), | ||
(Set[str], False), | ||
(List[Union[List[int], int]], False), | ||
(List[List[int]], False), | ||
(Tuple[int, ...], ((int,), None, tuple)), | ||
(List[int], ((int,), None, list)), | ||
(List[Union[str, int]], ((str, int), None, list)), | ||
] | ||
|
||
not_tokens = [ | ||
(List[int], False), | ||
(Dict[int, str], False), | ||
(int, ((int,), None, None)), | ||
(str, ((str,), None, None)), | ||
(Union[str, Mode], ((str, Mode), None, None)), | ||
] | ||
|
||
if PY39: | ||
tokens.extend( | ||
[ | ||
(list[int, int], False), | ||
(dict[str, str], False), | ||
(dict, False), | ||
(set[str], False), | ||
(tuple[int, ...], ((int,), None, tuple)), | ||
(list[int], ((int,), None, list)), | ||
(list[Union[str, int]], ((str, int), None, list)), | ||
] | ||
) | ||
|
||
if PY310: | ||
tokens.extend( | ||
[ | ||
(tuple[int | str], ((int, str), None, tuple)), | ||
] | ||
) | ||
|
||
not_tokens.extend( | ||
[ | ||
(int | str, ((int, str), None, None)), | ||
] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import Dict, List, Set, Tuple | ||
|
||
from tests.formats.dataclass.models.cases import PY39 | ||
|
||
cases = [ | ||
(int, False), | ||
(Set, False), | ||
(List, False), | ||
(Tuple, False), | ||
(Dict[str, int], False), | ||
(Dict, ((str,), dict, None)), | ||
(Dict[str, str], ((str,), dict, None)), | ||
] | ||
|
||
if PY39: | ||
cases.extend( | ||
[ | ||
(dict[str, str], ((str,), dict, None)), | ||
] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Dict, List, Set, Tuple, Union | ||
|
||
from tests.formats.dataclass.models.cases import PY39 | ||
|
||
tokens = [ | ||
(Set, False), | ||
(Dict[str, int], False), | ||
(Tuple[str, str], False), | ||
(List[str], ((str,), None, list)), | ||
(Tuple[str, ...], ((str,), None, tuple)), | ||
(List[List[str]], ((str,), list, list)), | ||
(List[Tuple[str, ...]], ((str,), list, tuple)), | ||
(Tuple[List[str], ...], ((str,), tuple, list)), | ||
] | ||
|
||
not_tokens = [ | ||
(Set, False), | ||
(Dict[str, int], False), | ||
(Tuple[str, int], False), | ||
(List[List[str]], False), | ||
(List[Tuple[str, ...]], False), | ||
(Tuple[List[str], ...], False), | ||
(str, ((str,), None, None)), | ||
(List[str], ((str,), list, None)), | ||
(List[Union[str, int]], ((str, int), list, None)), | ||
(Tuple[str, ...], ((str,), tuple, None)), | ||
] | ||
|
||
if PY39: | ||
tokens.extend( | ||
[ | ||
(list[str], ((str,), None, list)), | ||
(tuple[str, ...], ((str,), None, tuple)), | ||
(list[list[str]], ((str,), list, list)), | ||
(list[tuple[str, ...]], ((str,), list, tuple)), | ||
(tuple[list[str], ...], ((str,), tuple, list)), | ||
] | ||
) | ||
|
||
not_tokens.extend( | ||
[ | ||
(list[str], ((str,), list, None)), | ||
(tuple[str, ...], ((str,), tuple, None)), | ||
] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import Dict, List, Optional, Tuple, Union | ||
|
||
from tests.formats.dataclass.models.cases import PY39, PY310 | ||
|
||
cases = [ | ||
(Dict, False), | ||
(str, ((object,), None, None)), | ||
(List[str], ((object,), list, None)), | ||
(Tuple[str, ...], ((object,), tuple, None)), | ||
(Optional[Union[str, int]], ((object,), None, None)), | ||
(Union[str, int, None], ((object,), None, None)), | ||
(List[Union[List[str], Tuple[str, ...]]], ((object,), list, None)), | ||
] | ||
|
||
|
||
if PY39: | ||
cases.extend( | ||
[ | ||
(list[str], ((object,), list, None)), | ||
(tuple[str, ...], ((object,), tuple, None)), | ||
(list[Union[list[str], tuple[str, ...]]], ((object,), list, None)), | ||
] | ||
) | ||
|
||
|
||
if PY310: | ||
cases.extend( | ||
[ | ||
(str | int | None, ((object,), None, None)), | ||
(list[list[str] | tuple[str, ...]], ((object,), list, None)), | ||
] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Dict, List, Literal, Optional, Set, Tuple | ||
|
||
from tests.formats.dataclass.models.cases import PY310 | ||
|
||
cases = [ | ||
(int, False), | ||
(Dict[int, int], False), | ||
(Dict, False), | ||
(Set, False), | ||
(Literal["foo"], False), | ||
(object, ((object,), None, None)), | ||
(List[object], ((object,), list, None)), | ||
(Tuple[object, ...], ((object,), tuple, None)), | ||
(Optional[object], ((object,), None, None)), | ||
] | ||
|
||
if PY310: | ||
cases.extend( | ||
[ | ||
(list[object], ((object,), list, None)), | ||
(tuple[object, ...], ((object,), tuple, None)), | ||
(object | None, ((object,), None, None)), | ||
] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from typing import Type | ||
|
||
import pytest | ||
|
||
from tests.formats.dataclass.models.cases import ( | ||
attribute, | ||
attributes, | ||
element, | ||
elements, | ||
wildcard, | ||
) | ||
from xsdata.formats.dataclass.models.typing import ( | ||
evaluate, | ||
evaluate_attribute, | ||
evaluate_attributes, | ||
evaluate_element, | ||
evaluate_elements, | ||
evaluate_wildcard, | ||
) | ||
|
||
|
||
def test_evaluate_with_typevar(): | ||
result = evaluate(Type["str"], None) | ||
assert str == result | ||
|
||
with pytest.raises(TypeError): | ||
evaluate_attribute(Type, tokens=True) | ||
|
||
|
||
@pytest.mark.parametrize("case,expected", attribute.tokens) | ||
def test_evaluate_attribute_with_tokens(case, expected): | ||
if expected: | ||
assert expected == evaluate_attribute(case, tokens=True) | ||
else: | ||
with pytest.raises(TypeError): | ||
evaluate_attribute(case, tokens=True) | ||
|
||
|
||
@pytest.mark.parametrize("case,expected", attribute.not_tokens) | ||
def test_evaluate_attribute_without_tokens(case, expected): | ||
if expected: | ||
assert expected == evaluate_attribute(case, tokens=False) | ||
else: | ||
with pytest.raises(TypeError): | ||
evaluate_attribute(case, tokens=False) | ||
|
||
|
||
@pytest.mark.parametrize("case,expected", attributes.cases) | ||
def test_evaluate_attributes(case, expected): | ||
if expected: | ||
assert expected == evaluate_attributes(case) | ||
else: | ||
with pytest.raises(TypeError): | ||
evaluate_attributes(case) | ||
|
||
|
||
@pytest.mark.parametrize("case,expected", element.tokens) | ||
def test_evaluate_element_with_tokens(case, expected): | ||
if expected: | ||
assert expected == evaluate_element(case, tokens=True) | ||
else: | ||
with pytest.raises(TypeError): | ||
evaluate_element(case, tokens=True) | ||
|
||
|
||
@pytest.mark.parametrize("case,expected", element.not_tokens) | ||
def test_evaluate_element_without_tokens(case, expected): | ||
if expected: | ||
assert expected == evaluate_element(case, tokens=False) | ||
else: | ||
with pytest.raises(TypeError): | ||
evaluate_element(case, tokens=False) | ||
|
||
|
||
@pytest.mark.parametrize("case,expected", elements.cases) | ||
def test_evaluate_elements(case, expected): | ||
if expected: | ||
assert expected == evaluate_elements(case) | ||
else: | ||
with pytest.raises(TypeError): | ||
evaluate_elements(case) | ||
|
||
|
||
@pytest.mark.parametrize("case,expected", wildcard.cases) | ||
def test_evaluate_wildcard(case, expected): | ||
if expected: | ||
assert expected == evaluate_wildcard(case) | ||
else: | ||
with pytest.raises(TypeError): | ||
evaluate_wildcard(case) |
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.