Skip to content

Commit 75ac494

Browse files
committed
ugly rewrite
1 parent 24aef5c commit 75ac494

File tree

787 files changed

+81731
-1209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

787 files changed

+81731
-1209
lines changed

end_to_end_tests/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
""" Generate a complete client and verify that it is correct """
1+
"""Generate a complete client and verify that it is correct"""
2+
23
import pytest
34

45
pytest.register_assert_rewrite("end_to_end_tests.end_to_end_test_helpers")

end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/responses/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import types
44

5-
from . import post_responses_unions_simple_before_complex, reference_response, text_response
5+
from . import (
6+
post_responses_unions_simple_before_complex,
7+
reference_response,
8+
text_response,
9+
)
610

711

812
class ResponsesEndpoints:

end_to_end_tests/docstrings-on-attributes-golden-record/my_test_api_client/client.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ class Client:
3434
_base_url: str = field(alias="base_url")
3535
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
3636
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
37-
_timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
38-
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
39-
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
37+
_timeout: Optional[httpx.Timeout] = field(
38+
default=None, kw_only=True, alias="timeout"
39+
)
40+
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(
41+
default=True, kw_only=True, alias="verify_ssl"
42+
)
43+
_follow_redirects: bool = field(
44+
default=False, kw_only=True, alias="follow_redirects"
45+
)
4046
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
4147
_client: Optional[httpx.Client] = field(default=None, init=False)
4248
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
@@ -157,9 +163,15 @@ class AuthenticatedClient:
157163
_base_url: str = field(alias="base_url")
158164
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
159165
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
160-
_timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
161-
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
162-
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
166+
_timeout: Optional[httpx.Timeout] = field(
167+
default=None, kw_only=True, alias="timeout"
168+
)
169+
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(
170+
default=True, kw_only=True, alias="verify_ssl"
171+
)
172+
_follow_redirects: bool = field(
173+
default=False, kw_only=True, alias="follow_redirects"
174+
)
163175
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
164176
_client: Optional[httpx.Client] = field(default=None, init=False)
165177
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
@@ -206,7 +218,9 @@ def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
206218
def get_httpx_client(self) -> httpx.Client:
207219
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
208220
if self._client is None:
209-
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
221+
self._headers[self.auth_header_name] = (
222+
f"{self.prefix} {self.token}" if self.prefix else self.token
223+
)
210224
self._client = httpx.Client(
211225
base_url=self._base_url,
212226
cookies=self._cookies,
@@ -227,7 +241,9 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None:
227241
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
228242
self.get_httpx_client().__exit__(*args, **kwargs)
229243

230-
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
244+
def set_async_httpx_client(
245+
self, async_client: httpx.AsyncClient
246+
) -> "AuthenticatedClient":
231247
"""Manually the underlying httpx.AsyncClient
232248
233249
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
@@ -238,7 +254,9 @@ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Authentica
238254
def get_async_httpx_client(self) -> httpx.AsyncClient:
239255
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
240256
if self._async_client is None:
241-
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
257+
self._headers[self.auth_header_name] = (
258+
f"{self.prefix} {self.token}" if self.prefix else self.token
259+
)
242260
self._async_client = httpx.AsyncClient(
243261
base_url=self._base_url,
244262
cookies=self._cookies,

end_to_end_tests/functional_tests/generated_code_execution/test_arrays.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@with_generated_client_fixture(
12-
"""
12+
"""
1313
components:
1414
schemas:
1515
SimpleObject:
@@ -31,7 +31,8 @@
3131
arrayProp:
3232
type: array
3333
items: {"$ref": "#/components/schemas/SimpleObject"}
34-
""")
34+
"""
35+
)
3536
@with_generated_code_imports(
3637
".models.ModelWithArrayOfAny",
3738
".models.ModelWithArrayOfInts",
@@ -61,17 +62,27 @@ def test_array_of_object(self, ModelWithArrayOfObjects, SimpleObject):
6162
assert_model_decode_encode(
6263
ModelWithArrayOfObjects,
6364
{"arrayProp": [{"name": "a"}, {"name": "b"}]},
64-
ModelWithArrayOfObjects(array_prop=[SimpleObject(name="a"), SimpleObject(name="b")]),
65+
ModelWithArrayOfObjects(
66+
array_prop=[SimpleObject(name="a"), SimpleObject(name="b")]
67+
),
6568
)
6669

67-
def test_type_hints(self, ModelWithArrayOfAny, ModelWithArrayOfInts, ModelWithArrayOfObjects, Unset):
68-
assert_model_property_type_hint(ModelWithArrayOfAny, "array_prop", Union[list[Any], Unset])
69-
assert_model_property_type_hint(ModelWithArrayOfInts, "array_prop", Union[list[int], Unset])
70-
assert_model_property_type_hint(ModelWithArrayOfObjects, "array_prop", Union[list["SimpleObject"], Unset])
70+
def test_type_hints(
71+
self, ModelWithArrayOfAny, ModelWithArrayOfInts, ModelWithArrayOfObjects, Unset
72+
):
73+
assert_model_property_type_hint(
74+
ModelWithArrayOfAny, "array_prop", Union[list[Any], Unset]
75+
)
76+
assert_model_property_type_hint(
77+
ModelWithArrayOfInts, "array_prop", Union[list[int], Unset]
78+
)
79+
assert_model_property_type_hint(
80+
ModelWithArrayOfObjects, "array_prop", Union[list["SimpleObject"], Unset]
81+
)
7182

7283

7384
@with_generated_client_fixture(
74-
"""
85+
"""
7586
components:
7687
schemas:
7788
SimpleObject:
@@ -102,7 +113,8 @@ def test_type_hints(self, ModelWithArrayOfAny, ModelWithArrayOfInts, ModelWithAr
102113
- $ref: "#/components/schemas/SimpleObject"
103114
items:
104115
type: string
105-
""")
116+
"""
117+
)
106118
@with_generated_code_imports(
107119
".models.ModelWithSinglePrefixItem",
108120
".models.ModelWithPrefixItems",
@@ -132,8 +144,16 @@ def test_prefix_items_and_regular_items(self, ModelWithMixedItems, SimpleObject)
132144
ModelWithMixedItems(array_prop=[SimpleObject(name="a"), "b"]),
133145
)
134146

135-
def test_type_hints(self, ModelWithSinglePrefixItem, ModelWithPrefixItems, ModelWithMixedItems, Unset):
136-
assert_model_property_type_hint(ModelWithSinglePrefixItem, "array_prop", Union[list[str], Unset])
147+
def test_type_hints(
148+
self,
149+
ModelWithSinglePrefixItem,
150+
ModelWithPrefixItems,
151+
ModelWithMixedItems,
152+
Unset,
153+
):
154+
assert_model_property_type_hint(
155+
ModelWithSinglePrefixItem, "array_prop", Union[list[str], Unset]
156+
)
137157
assert_model_property_type_hint(
138158
ModelWithPrefixItems,
139159
"array_prop",

end_to_end_tests/functional_tests/generated_code_execution/test_defaults.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@with_generated_client_fixture(
11-
"""
11+
"""
1212
components:
1313
schemas:
1414
MyModel:
@@ -38,7 +38,8 @@
3838
unionWithValidDefaultForType2:
3939
anyOf: [{"type": "boolean"}, {"type": "integer"}]
4040
default: 3
41-
""")
41+
"""
42+
)
4243
@with_generated_code_imports(".models.MyModel")
4344
class TestSimpleDefaults:
4445
# Note, the null/None type is not covered here due to a known bug:
@@ -51,7 +52,9 @@ def test_defaults_in_initializer(self, MyModel):
5152
number_prop=1.5,
5253
int_prop=2,
5354
date_prop=datetime.date(2024, 1, 2),
54-
date_time_prop=datetime.datetime(2024, 1, 2, 3, 4, 5, tzinfo=datetime.timezone.utc),
55+
date_time_prop=datetime.datetime(
56+
2024, 1, 2, 3, 4, 5, tzinfo=datetime.timezone.utc
57+
),
5558
uuid_prop=uuid.UUID("07EF8B4D-AA09-4FFA-898D-C710796AFF41"),
5659
any_prop_with_string="b",
5760
any_prop_with_int=3,
@@ -69,9 +72,8 @@ def test_defaults_in_initializer(self, MyModel):
6972
)
7073

7174

72-
7375
@with_generated_client_fixture(
74-
"""
76+
"""
7577
components:
7678
schemas:
7779
MyEnum:
@@ -85,15 +87,16 @@ def test_defaults_in_initializer(self, MyModel):
8587
- $ref: "#/components/schemas/MyEnum"
8688
default: "a"
8789
88-
""")
90+
"""
91+
)
8992
@with_generated_code_imports(".models.MyEnum", ".models.MyModel")
9093
class TestEnumDefaults:
9194
def test_enum_default(self, MyEnum, MyModel):
9295
assert MyModel().enum_prop == MyEnum.A
9396

9497

9598
@with_generated_client_fixture(
96-
"""
99+
"""
97100
components:
98101
schemas:
99102
MyEnum:

end_to_end_tests/functional_tests/generated_code_execution/test_docstrings.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def __init__(self, item: Any):
1313
self.lines = [line.lstrip() for line in item.__doc__.split("\n")]
1414

1515
def get_section(self, header_line: str) -> list[str]:
16-
lines = self.lines[self.lines.index(header_line)+1:]
17-
return lines[0:lines.index("")]
16+
lines = self.lines[self.lines.index(header_line) + 1 :]
17+
return lines[0 : lines.index("")]
1818

1919

2020
@with_generated_client_fixture(
21-
"""
21+
"""
2222
components:
2323
schemas:
2424
MyModel:
@@ -34,7 +34,8 @@ def get_section(self, header_line: str) -> list[str]:
3434
undescribedProp:
3535
type: string
3636
required: ["reqStr", "undescribedProp"]
37-
""")
37+
"""
38+
)
3839
@with_generated_code_import(".models.MyModel")
3940
class TestSchemaDocstrings:
4041
def test_model_description(self, MyModel):
@@ -49,7 +50,7 @@ def test_model_properties(self, MyModel):
4950

5051

5152
@with_generated_client_fixture(
52-
"""
53+
"""
5354
tags:
5455
- name: service1
5556
paths:
@@ -130,10 +131,17 @@ def test_model_properties(self, MyModel):
130131
Thing:
131132
type: object
132133
description: The thing.
133-
""")
134-
@with_generated_code_import(".api.service1.get_simple_thing.sync", alias="get_simple_thing_sync")
135-
@with_generated_code_import(".api.service1.post_simple_thing.sync", alias="post_simple_thing_sync")
136-
@with_generated_code_import(".api.service1.get_attribute_by_index.sync", alias="get_attribute_by_index_sync")
134+
"""
135+
)
136+
@with_generated_code_import(
137+
".api.service1.get_simple_thing.sync", alias="get_simple_thing_sync"
138+
)
139+
@with_generated_code_import(
140+
".api.service1.post_simple_thing.sync", alias="post_simple_thing_sync"
141+
)
142+
@with_generated_code_import(
143+
".api.service1.get_attribute_by_index.sync", alias="get_attribute_by_index_sync"
144+
)
137145
class TestEndpointDocstrings:
138146
def test_description(self, get_simple_thing_sync):
139147
assert DocstringParser(get_simple_thing_sync).lines[0] == "Get a simple thing."
@@ -144,7 +152,9 @@ def test_response_single_type(self, get_simple_thing_sync):
144152
]
145153

146154
def test_response_union_type(self, post_simple_thing_sync):
147-
returns_line = DocstringParser(post_simple_thing_sync).get_section("Returns:")[0]
155+
returns_line = DocstringParser(post_simple_thing_sync).get_section("Returns:")[
156+
0
157+
]
148158
assert returns_line in (
149159
"Union[GoodResponse, ErrorResponse]",
150160
"Union[ErrorResponse, GoodResponse]",

0 commit comments

Comments
 (0)