Skip to content

Commit 80c8333

Browse files
committed
reorganize
1 parent eabbf2b commit 80c8333

17 files changed

+390
-393
lines changed

end_to_end_tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
import pytest
33

44
pytest.register_assert_rewrite("end_to_end_tests.end_to_end_test_helpers")
5+
pytest.register_assert_rewrite("end_to_end_tests.functional_tests.helpers")

end_to_end_tests/end_to_end_test_helpers.py

-267
This file was deleted.

end_to_end_tests/functional_tests/README.md

+23-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ components:
3737
""")
3838
@with_generated_code_import(".models.MyModel")
3939
class TestSimpleJsonObject:
40-
def test_encoding(MyModel):
40+
def test_encoding(self, MyModel):
4141
instance = MyModel(string_prop="abc")
4242
assert instance.to_dict() == {"stringProp": "abc"}
4343
```
@@ -46,11 +46,30 @@ class TestSimpleJsonObject:
4646

4747
These run the generator with an invalid API spec and make assertions about the warning/error output. Some of these invalid conditions are expected to only produce warnings about the affected schemas, while others are expected to produce fatal errors that terminate the generator.
4848

49-
For warning conditions, each test class follows this pattern:
49+
For warning conditions, each test class uses `@with_generated_client_fixture` as above, then uses `assert_bad_schema` to parse the output and check for a specific warning message for a specific schema name.
5050

51-
- Call `inline_spec_should_cause_warnings`, providing an inline API spec (JSON or YAML). If there are several test methods in the class using the same spec, use a fixture with scope "class" so the generator is only run once.
52-
- Use `assert_bad_schema_warning` to parse the output and check for a specific warning message for a specific schema name.
51+
```python
52+
@with_generated_client_fixture(
53+
"""
54+
components:
55+
schemas:
56+
MyModel:
57+
# some kind of invalid schema
58+
""")
59+
class TestBadSchema:
60+
def test_encoding(self, generated_client):
61+
assert_bad_schema(generated_client, "MyModel", "some expected warning text")
62+
```
5363

5464
Or, for fatal error conditions:
5565

5666
- Call `inline_spec_should_fail`, providing an inline API spec (JSON or YAML).
67+
68+
```python
69+
class TestBadSpec:
70+
def test_some_spec_error(self):
71+
result = inline_spec_should_fail("""
72+
# some kind of invalid spec
73+
""")
74+
assert "some expected error text" in result.output
75+
```

end_to_end_tests/functional_tests/generated_code_execution/test_arrays.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import datetime
21
from typing import Any, ForwardRef, List, Union
3-
import uuid
4-
import pytest
5-
from end_to_end_tests.end_to_end_test_helpers import (
2+
3+
from end_to_end_tests.functional_tests.helpers import (
64
assert_model_decode_encode,
75
assert_model_property_type_hint,
86
with_generated_client_fixture,

end_to_end_tests/functional_tests/generated_code_execution/test_defaults.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import uuid
3-
from end_to_end_tests.end_to_end_test_helpers import (
3+
4+
from end_to_end_tests.functional_tests.helpers import (
45
with_generated_client_fixture,
56
with_generated_code_imports,
67
)

end_to_end_tests/functional_tests/generated_code_execution/test_docstrings.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any, List
2-
from end_to_end_tests.end_to_end_test_helpers import (
2+
3+
from end_to_end_tests.functional_tests.helpers import (
34
with_generated_code_import,
45
with_generated_client_fixture,
56
)

end_to_end_tests/functional_tests/generated_code_execution/test_enums_and_consts.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Literal, Union
22
import pytest
3-
from end_to_end_tests.end_to_end_test_helpers import (
3+
4+
from end_to_end_tests.functional_tests.helpers import (
45
assert_model_decode_encode,
56
assert_model_property_type_hint,
6-
with_generated_code_import,
77
with_generated_client_fixture,
88
with_generated_code_imports,
99
)
@@ -187,7 +187,7 @@ def test_type_hints(self, MyModel, MyEnum, Unset):
187187
const: 30
188188
""",
189189
)
190-
@with_generated_code_import(".models.MyModel")
190+
@with_generated_code_imports(".models.MyModel")
191191
class TestConst:
192192
def test_valid_string(self, MyModel):
193193
assert_model_decode_encode(
@@ -327,7 +327,7 @@ def test_invalid_values(self, MyModel):
327327
""",
328328
config="literal_enums: true",
329329
)
330-
@with_generated_code_import(".models.MyModel")
330+
@with_generated_code_imports(".models.MyModel")
331331
class TestNullableLiteralEnum:
332332
def test_nullable_enum_prop(self, MyModel):
333333
assert_model_decode_encode(MyModel, {"nullableEnumProp": "B"}, MyModel(nullable_enum_prop="B"))

end_to_end_tests/functional_tests/generated_code_execution/test_properties.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from typing import Any, ForwardRef, Union
33
import uuid
44
import pytest
5-
from end_to_end_tests.end_to_end_test_helpers import (
5+
6+
from end_to_end_tests.functional_tests.helpers import (
67
assert_model_decode_encode,
78
assert_model_property_type_hint,
89
with_generated_client_fixture,

end_to_end_tests/functional_tests/generated_code_execution/test_unions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import ForwardRef, Union
2-
from end_to_end_tests.end_to_end_test_helpers import (
2+
3+
from end_to_end_tests.functional_tests.helpers import (
34
assert_model_decode_encode,
45
assert_model_property_type_hint,
56
with_generated_client_fixture,

0 commit comments

Comments
 (0)