10
10
from pydantic2ts .cli .script import parse_cli_args
11
11
from pydantic2ts .pydantic_v2 import enabled as v2_enabled
12
12
13
- _PYDANTIC_VERSIONS = ("v1" , "v2" ) if v2_enabled else ("v1" ,)
13
+ _PYDANTIC_VERSIONS = (1 , 2 ) if v2_enabled else (1 ,)
14
14
_RESULTS_DIRECTORY = Path (
15
15
os .path .join (os .path .dirname (os .path .realpath (__file__ )), "expected_results" )
16
16
)
17
17
18
18
19
- def _get_input_module (test_name : str , pydantic_version : str ) -> str :
20
- return str (_RESULTS_DIRECTORY / test_name / pydantic_version / "input.py" )
19
+ def _get_input_module (test_name : str , pydantic_version : int ) -> str :
20
+ return str (_RESULTS_DIRECTORY / test_name / f"v { pydantic_version } " / "input.py" )
21
21
22
22
23
- def _get_expected_output (test_name : str , pydantic_version : str ) -> str :
24
- return (_RESULTS_DIRECTORY / test_name / pydantic_version / "output.ts" ).read_text ()
23
+ def _get_expected_output (test_name : str , pydantic_version : int ) -> str :
24
+ return (_RESULTS_DIRECTORY / test_name / f"v { pydantic_version } " / "output.ts" ).read_text ()
25
25
26
26
27
27
def _run_test (
28
28
tmp_path : Path ,
29
29
test_name : str ,
30
- pydantic_version : str ,
30
+ pydantic_version : int ,
31
31
* ,
32
32
module_path : Optional [str ] = None ,
33
33
call_from_python : bool = False ,
@@ -38,7 +38,7 @@ def _run_test(
38
38
Compare the output with the expected output, verifying it is identical.
39
39
"""
40
40
module_path = module_path or _get_input_module (test_name , pydantic_version )
41
- output_path = str (tmp_path / f"{ test_name } _ { pydantic_version } .ts" )
41
+ output_path = str (tmp_path / f"{ test_name } _v { pydantic_version } .ts" )
42
42
43
43
if call_from_python :
44
44
generate_typescript_defs (module_path , output_path , exclude )
@@ -55,31 +55,31 @@ def _run_test(
55
55
"pydantic_version, call_from_python" ,
56
56
product (_PYDANTIC_VERSIONS , [False , True ]),
57
57
)
58
- def test_single_module (tmp_path : Path , pydantic_version : str , call_from_python : bool ):
58
+ def test_single_module (tmp_path : Path , pydantic_version : int , call_from_python : bool ):
59
59
_run_test (tmp_path , "single_module" , pydantic_version , call_from_python = call_from_python )
60
60
61
61
62
62
@pytest .mark .parametrize (
63
63
"pydantic_version, call_from_python" ,
64
64
product (_PYDANTIC_VERSIONS , [False , True ]),
65
65
)
66
- def test_submodules (tmp_path : Path , pydantic_version : str , call_from_python : bool ):
66
+ def test_submodules (tmp_path : Path , pydantic_version : int , call_from_python : bool ):
67
67
_run_test (tmp_path , "submodules" , pydantic_version , call_from_python = call_from_python )
68
68
69
69
70
70
@pytest .mark .parametrize (
71
71
"pydantic_version, call_from_python" ,
72
72
product (_PYDANTIC_VERSIONS , [False , True ]),
73
73
)
74
- def test_generics (tmp_path : Path , pydantic_version : str , call_from_python : bool ):
74
+ def test_generics (tmp_path : Path , pydantic_version : int , call_from_python : bool ):
75
75
_run_test (tmp_path , "generics" , pydantic_version , call_from_python = call_from_python )
76
76
77
77
78
78
@pytest .mark .parametrize (
79
79
"pydantic_version, call_from_python" ,
80
80
product (_PYDANTIC_VERSIONS , [False , True ]),
81
81
)
82
- def test_excluding_models (tmp_path : Path , pydantic_version : str , call_from_python : bool ):
82
+ def test_excluding_models (tmp_path : Path , pydantic_version : int , call_from_python : bool ):
83
83
_run_test (
84
84
tmp_path ,
85
85
"excluding_models" ,
@@ -91,25 +91,25 @@ def test_excluding_models(tmp_path: Path, pydantic_version: str, call_from_pytho
91
91
92
92
@pytest .mark .parametrize (
93
93
"pydantic_version, call_from_python" ,
94
- product ([v for v in _PYDANTIC_VERSIONS if v != "v1" ], [False , True ]),
94
+ product ([v for v in _PYDANTIC_VERSIONS if v > 1 ], [False , True ]),
95
95
)
96
- def test_computed_fields (tmp_path : Path , pydantic_version : str , call_from_python : bool ):
96
+ def test_computed_fields (tmp_path : Path , pydantic_version : int , call_from_python : bool ):
97
97
_run_test (tmp_path , "computed_fields" , pydantic_version , call_from_python = call_from_python )
98
98
99
99
100
100
@pytest .mark .parametrize (
101
101
"pydantic_version, call_from_python" ,
102
102
product (_PYDANTIC_VERSIONS , [False , True ]),
103
103
)
104
- def test_extra_fields (tmp_path : Path , pydantic_version : str , call_from_python : bool ):
104
+ def test_extra_fields (tmp_path : Path , pydantic_version : int , call_from_python : bool ):
105
105
_run_test (tmp_path , "extra_fields" , pydantic_version , call_from_python = call_from_python )
106
106
107
107
108
108
def test_relative_filepath (tmp_path : Path ):
109
109
test_name = "single_module"
110
110
pydantic_version = _PYDANTIC_VERSIONS [0 ]
111
111
relative_path = (
112
- Path ("." ) / "tests" / "expected_results" / test_name / pydantic_version / "input.py"
112
+ Path ("." ) / "tests" / "expected_results" / test_name / f"v { pydantic_version } " / "input.py"
113
113
)
114
114
_run_test (
115
115
tmp_path ,
0 commit comments