Skip to content

Commit efbc5d6

Browse files
committed
adding tests to highlight the graphql bug
1 parent fd5e698 commit efbc5d6

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# generated by datamodel-codegen:
2+
# filename: empty_list_default.graphql
3+
# timestamp: 2019-07-26T00:00:00+00:00
4+
5+
from __future__ import annotations
6+
7+
from typing import List, Optional
8+
9+
from pydantic import BaseModel, Field
10+
11+
12+
class Container(BaseModel):
13+
name: Optional[str] = None
14+
15+
16+
class PodSpec(BaseModel):
17+
containers: Optional[List[Container]] = Field(default_factory=list)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# generated by datamodel-codegen:
2+
# filename: empty_list_default.graphql
3+
# timestamp: 2019-07-26T00:00:00+00:00
4+
5+
from __future__ import annotations
6+
7+
from typing import List, Optional
8+
9+
from pydantic import BaseModel, Field
10+
11+
12+
class Container(BaseModel):
13+
name: Optional[str] = None
14+
15+
16+
class PodSpec(BaseModel):
17+
containers: Optional[List[Container]] = Field(default_factory=list)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
Equivalent types for the GraphQL schemas.
3+
"""
4+
input Container {
5+
name: String
6+
}
7+
8+
input PodSpec {
9+
containers: [Container!]! = []
10+
}

tests/main/graphql/test_main_graphql.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,39 @@ def test_main_use_default_kwarg(output_file: Path) -> None:
104104
)
105105

106106

107+
@pytest.mark.parametrize(
108+
("output_model", "expected_output"),
109+
[
110+
(
111+
"pydantic.BaseModel",
112+
"empty_list_default.py",
113+
),
114+
(
115+
"pydantic_v2.BaseModel",
116+
"pydantic_v2_empty_list_default.py",
117+
),
118+
],
119+
)
120+
@pytest.mark.skipif(
121+
black.__version__.split(".")[0] == "19",
122+
reason="Installed black doesn't support the old style",
123+
)
124+
def test_main_graphql_empty_list_default(output_model: str, expected_output: str, output_file: Path) -> None:
125+
"""Test GraphQL generation with empty list default values."""
126+
run_main_and_assert(
127+
input_path=GRAPHQL_DATA_PATH / "empty_list_default.graphql",
128+
output_path=output_file,
129+
expected_file=GRAPHQL_DATA_PATH / expected_output,
130+
input_file_type="graphql",
131+
extra_args=[
132+
"--output-model-type",
133+
output_model,
134+
"--target-python-version",
135+
"3.13",
136+
],
137+
)
138+
139+
107140
@pytest.mark.skipif(
108141
black.__version__.split(".")[0] == "19",
109142
reason="Installed black doesn't support the old style",

0 commit comments

Comments
 (0)