Skip to content

Commit b21d2e6

Browse files
committed
restore some missing test coverage
1 parent 53fca35 commit b21d2e6

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

end_to_end_tests/end_to_end_test_helpers.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,17 @@ def generate_client(
7878
extra_args: List[str] = [],
7979
output_path: str = "my-test-api-client",
8080
base_module: str = "my_test_api_client",
81+
specify_output_path_explicitly: bool = True,
8182
overwrite: bool = True,
8283
raise_on_error: bool = True,
8384
) -> GeneratedClientContext:
8485
"""Run the generator and return a GeneratedClientContext for accessing the generated code."""
8586
full_output_path = Path.cwd() / output_path
8687
if not overwrite:
8788
shutil.rmtree(full_output_path, ignore_errors=True)
88-
args = [
89-
*extra_args,
90-
"--output-path",
91-
str(full_output_path),
92-
]
89+
args = extra_args
90+
if specify_output_path_explicitly:
91+
args = [*args, "--output-path", str(full_output_path)]
9392
if overwrite:
9493
args = [*args, "--overwrite"]
9594
generator_result = _run_command("generate", args, openapi_document, raise_on_error=raise_on_error)

end_to_end_tests/generated_code_live_tests/test_defaults.py

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
numberWithStringValue: {"type": "number", "default": "5.5"}
3737
stringWithNumberValue: {"type": "string", "default": 6}
3838
stringConst: {"type": "string", "const": "always", "default": "always"}
39+
unionWithValidDefaultForType1:
40+
anyOf: [{"type": "boolean"}, {"type": "integer"}]
41+
default: true
42+
unionWithValidDefaultForType2:
43+
anyOf: [{"type": "boolean"}, {"type": "integer"}]
44+
default: 3
3945
""")
4046
@with_generated_code_imports(".models.MyModel")
4147
class TestSimpleDefaults:
@@ -62,6 +68,8 @@ def test_defaults_in_initializer(self, MyModel):
6268
number_with_string_value=5.5,
6369
string_with_number_value="6",
6470
string_const="always",
71+
union_with_valid_default_for_type_1=True,
72+
union_with_valid_default_for_type_2=3,
6573
)
6674

6775

@@ -131,6 +139,13 @@ def warnings(self):
131139
WithBadEnum:
132140
properties:
133141
badEnum: {"type": "string", "enum": ["a", "b"], "default": "x"}
142+
UnionWithNoValidDefault:
143+
properties:
144+
badBoolOrInt:
145+
anyOf:
146+
- type: boolean
147+
- type: integer
148+
default: "xxx"
134149
"""
135150
)
136151
# Note, the null/None type, and binary strings (files), are not covered here due to a known bug:
@@ -151,6 +166,7 @@ def warnings(self):
151166
("WithBadUuidAsString", "Invalid UUID value"),
152167
("WithBadUuidAsOther", "Invalid UUID value"),
153168
("WithBadEnum", "Value x is not valid for enum"),
169+
("UnionWithNoValidDefault", "Invalid int value"),
154170
]
155171
)
156172
def test_bad_default_warning(self, model_name, message, warnings):

end_to_end_tests/test_end_to_end.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ def run_e2e_test(
8686
golden_record_path: str = "golden-record",
8787
output_path: str = "my-test-api-client",
8888
expected_missing: Optional[Set[str]] = None,
89+
specify_output_path_explicitly: bool = True,
8990
) -> Result:
90-
with generate_client(openapi_document, extra_args, output_path) as g:
91+
with generate_client(openapi_document, extra_args, output_path, specify_output_path_explicitly=specify_output_path_explicitly) as g:
9192
gr_path = Path(__file__).parent / golden_record_path
9293

9394
expected_differences = expected_differences or {}
@@ -165,6 +166,7 @@ def test_none_meta():
165166
golden_record_path="test-3-1-golden-record/test_3_1_features_client",
166167
output_path="test_3_1_features_client",
167168
expected_missing={"py.typed"},
169+
specify_output_path_explicitly=False,
168170
)
169171

170172

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ignore = ["E501", "PLR0913", "PLR2004"]
6767
"tests/*" = ["PLR2004"]
6868

6969
[tool.coverage.run]
70-
omit = ["openapi_python_client/__main__.py", "openapi_python_client/templates/*"]
70+
omit = ["openapi_python_client/__main__.py", "openapi_python_client/templates/*", "end_to_end_tests/*", "integration_tests/*", "tests/*"]
7171

7272
[tool.mypy]
7373
plugins = ["pydantic.mypy"]
@@ -119,7 +119,7 @@ re = {composite = ["regen_e2e", "e2e --snapshot-update"]}
119119
regen_e2e = "python -m end_to_end_tests.regen_golden_record"
120120

121121
[tool.pdm.scripts.test]
122-
cmd = "pytest tests end_to_end_tests/test_end_to_end.py --basetemp=tests/tmp"
122+
cmd = "pytest tests end_to_end_tests/test_end_to_end.py end_to_end_tests/generated_code_live_tests --basetemp=tests/tmp"
123123
[tool.pdm.scripts.test.env]
124124
"TEST_RELATIVE" = "true"
125125

0 commit comments

Comments
 (0)