Skip to content

Commit

Permalink
Adding minor fix for unit test on Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
ghandic committed May 3, 2021
1 parent 5690351 commit 194cc9a
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/tests/test_model_gen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import platform
from enum import Enum
from typing import List

Expand All @@ -9,28 +10,40 @@

Object = create_model("Object")

expected = [
("boolean", bool),
("enum", Enum),
("inner-ref", Object),
("integer", int),
("null", type(None)),
("number", float),
("object", Object),
("custom", Object),
("string-enum", Enum),
("string", str),
("tuple", tuple),
]
if int(platform.python_version_tuple()[1]) < 9:
expected.append(("array", List))

else:
from typing import _GenericAlias

def test_gen_model_list(TestData):
with open(TestData / f"array.json", "r") as file:
schema = json.load(file)
p = JSF(schema)
Model = p.pydantic()
assert _GenericAlias == type(Model)


@pytest.mark.parametrize(
"filestem, expected_type_anno",
[
("array", List),
("boolean", bool),
("enum", Enum),
("inner-ref", Object),
("integer", int),
("null", type(None)),
("number", float),
("object", Object),
("custom", Object),
("string-enum", Enum),
("string", str),
("tuple", tuple),
],
"filestem, expected_type_anno", expected,
)
def test_gen_model(TestData, filestem, expected_type_anno):
with open(TestData / f"{filestem}.json", "r") as file:
schema = json.load(file)
p = JSF(schema)
Model = p.pydantic()
print(type(Model))
print(type(Model), type(expected_type_anno))
assert type(expected_type_anno) == type(Model)

0 comments on commit 194cc9a

Please sign in to comment.