Skip to content

Commit 71279cd

Browse files
Fix tests
1 parent b776f80 commit 71279cd

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

openapi_python_client/templates/property_templates/property_macros.py.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ _{{ property.python_name }} = {{ source }}
1313
if {% if property.nullable %}_{{ property.python_name }} is not None{% endif %}{% if property.nullable and not property.required %} and {% endif %}{% if not property.required %}not isinstance(_{{ property.python_name }}, Unset){% endif %}:
1414
{{ property.python_name }} = {{ construct_function(property, "_" + property.python_name) }}
1515
{% endif %}
16-
{% endmacro %}
16+
{% endmacro %}

tests/test_templates/test_property_templates/test_date_property/optional_nullable.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22
from typing import cast, Union
33

44
from dateutil.parser import isoparse
5-
65
some_source = date(2020, 10, 12)
7-
8-
96
some_destination: Union[Unset, str] = UNSET
107
if not isinstance(some_source, Unset):
11-
128
some_destination = some_source.isoformat() if some_source else None
139

14-
15-
16-
17-
1810
a_prop = None
1911
_a_prop = some_destination
20-
if _a_prop is not None:
21-
a_prop = isoparse(cast(str, _a_prop)).date()
12+
if _a_prop is not None and not isinstance(_a_prop, Unset):
13+
a_prop = isoparse(_a_prop).date()
14+
2215

tests/test_templates/test_property_templates/test_date_property/required_not_null.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
from typing import cast, Union
33

44
from dateutil.parser import isoparse
5-
65
some_source = date(2020, 10, 12)
7-
8-
96
some_destination = some_source.isoformat()
10-
11-
12-
13-
147
a_prop = isoparse(some_destination).date()
158

9+

tests/test_templates/test_property_templates/test_date_property/required_nullable.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
from typing import cast, Union
33

44
from dateutil.parser import isoparse
5-
65
some_source = date(2020, 10, 12)
7-
8-
9-
some_destination = some_source.isoformat() if some_source else None
10-
11-
12-
13-
6+
some_destination = some_source.isoformat() if some_source else None
147
a_prop = None
158
_a_prop = some_destination
169
if _a_prop is not None:
17-
a_prop = isoparse(cast(str, _a_prop)).date()
10+
a_prop = isoparse(_a_prop).date()
11+
1812

tests/test_templates/test_property_templates/test_date_property/test_date_property.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def test_required_not_nullable():
1616
templates_dir = here.parent.parent.parent.parent / "openapi_python_client" / "templates"
1717

1818
env = jinja2.Environment(
19-
loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(here), jinja2.FileSystemLoader(templates_dir)])
19+
loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(here), jinja2.FileSystemLoader(templates_dir)]),
20+
trim_blocks=True,
21+
lstrip_blocks=True
2022
)
2123

2224
template = env.get_template("date_property_template.py")
@@ -38,7 +40,9 @@ def test_required_nullable():
3840
templates_dir = here.parent.parent.parent.parent / "openapi_python_client" / "templates"
3941

4042
env = jinja2.Environment(
41-
loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(here), jinja2.FileSystemLoader(templates_dir)])
43+
loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(here), jinja2.FileSystemLoader(templates_dir)]),
44+
trim_blocks=True,
45+
lstrip_blocks=True
4246
)
4347

4448
template = env.get_template("date_property_template.py")
@@ -60,10 +64,13 @@ def test_optional_nullable():
6064
templates_dir = here.parent.parent.parent.parent / "openapi_python_client" / "templates"
6165

6266
env = jinja2.Environment(
63-
loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(here), jinja2.FileSystemLoader(templates_dir)])
67+
loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(here), jinja2.FileSystemLoader(templates_dir)]),
68+
trim_blocks=True,
69+
lstrip_blocks=True
6470
)
6571

6672
template = env.get_template("date_property_template.py")
6773
content = template.render(property=prop)
74+
print(content)
6875
expected = here / "optional_nullable.py"
6976
assert content == expected.read_text()

0 commit comments

Comments
 (0)