Skip to content

Commit f3e8251

Browse files
committed
Add missed tests related to quoted and lazy_import
1 parent 36b00ed commit f3e8251

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/test_parser/test_properties/test_init.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ class TestListProperty:
129129
def test_is_base_type(self, list_property_factory):
130130
assert list_property_factory().is_base_type is False
131131

132+
@pytest.mark.parametrize("quoted", (True, False))
133+
def test_get_base_json_type_string_base_inner(self, list_property_factory, quoted):
134+
p = list_property_factory()
135+
assert p.get_base_json_type_string(quoted=quoted) == "List[str]"
136+
137+
@pytest.mark.parametrize("quoted", (True, False))
138+
def test_get_base_json_type_string_model_inner(self, list_property_factory, model_property_factory, quoted):
139+
m = model_property_factory()
140+
p = list_property_factory(inner_property=m)
141+
assert p.get_base_json_type_string(quoted=quoted) == "List[Dict[str, Any]]"
142+
143+
def test_get_lazy_import_base_inner(self, list_property_factory):
144+
p = list_property_factory()
145+
assert p.get_lazy_imports(prefix="..") == set()
146+
147+
def test_get_lazy_import_model_inner(self, list_property_factory, model_property_factory):
148+
m = model_property_factory()
149+
p = list_property_factory(inner_property=m)
150+
assert p.get_lazy_imports(prefix="..") == {'from ..models.my_module import MyClass'}
151+
132152
@pytest.mark.parametrize(
133153
"required, nullable, expected",
134154
(
@@ -209,6 +229,15 @@ class TestUnionProperty:
209229
def test_is_base_type(self, union_property_factory):
210230
assert union_property_factory().is_base_type is False
211231

232+
def test_get_lazy_import_base_inner(self, union_property_factory):
233+
p = union_property_factory()
234+
assert p.get_lazy_imports(prefix="..") == set()
235+
236+
def test_get_lazy_import_model_inner(self, union_property_factory, model_property_factory):
237+
m = model_property_factory()
238+
p = union_property_factory(inner_properties=[m])
239+
assert p.get_lazy_imports(prefix="..") == {'from ..models.my_module import MyClass'}
240+
212241
@pytest.mark.parametrize(
213242
"nullable,required,no_optional,json,expected",
214243
[

tests/test_parser/test_properties/test_model_property.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ def test_get_imports(self, model_property_factory):
5454
"from typing import cast",
5555
}
5656

57+
@pytest.mark.parametrize(
58+
"quoted,expected",
59+
[
60+
(False, "MyClass"),
61+
(True, "'MyClass'"),
62+
]
63+
)
64+
def test_get_type_string_parent(self, model_property_factory, quoted, expected):
65+
parent = model_property_factory()
66+
m = model_property_factory()
67+
assert m.get_type_string(model_parent=parent, quoted=quoted) == expected
68+
5769
def test_get_lazy_imports(self, model_property_factory):
5870
prop = model_property_factory(required=False, nullable=True)
5971

0 commit comments

Comments
 (0)