1010from pydantic2ts .cli .script import parse_cli_args
1111from pydantic2ts .pydantic_v2 import enabled as v2_enabled
1212
13- _PYDANTIC_VERSIONS = ("v1" , "v2" ) if v2_enabled else ("v1" ,)
13+ _PYDANTIC_VERSIONS = (1 , 2 ) if v2_enabled else (1 ,)
1414_RESULTS_DIRECTORY = Path (
1515 os .path .join (os .path .dirname (os .path .realpath (__file__ )), "expected_results" )
1616)
1717
1818
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" )
2121
2222
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 ()
2525
2626
2727def _run_test (
2828 tmp_path : Path ,
2929 test_name : str ,
30- pydantic_version : str ,
30+ pydantic_version : int ,
3131 * ,
3232 module_path : Optional [str ] = None ,
3333 call_from_python : bool = False ,
@@ -38,7 +38,7 @@ def _run_test(
3838 Compare the output with the expected output, verifying it is identical.
3939 """
4040 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" )
4242
4343 if call_from_python :
4444 generate_typescript_defs (module_path , output_path , exclude )
@@ -55,31 +55,31 @@ def _run_test(
5555 "pydantic_version, call_from_python" ,
5656 product (_PYDANTIC_VERSIONS , [False , True ]),
5757)
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 ):
5959 _run_test (tmp_path , "single_module" , pydantic_version , call_from_python = call_from_python )
6060
6161
6262@pytest .mark .parametrize (
6363 "pydantic_version, call_from_python" ,
6464 product (_PYDANTIC_VERSIONS , [False , True ]),
6565)
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 ):
6767 _run_test (tmp_path , "submodules" , pydantic_version , call_from_python = call_from_python )
6868
6969
7070@pytest .mark .parametrize (
7171 "pydantic_version, call_from_python" ,
7272 product (_PYDANTIC_VERSIONS , [False , True ]),
7373)
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 ):
7575 _run_test (tmp_path , "generics" , pydantic_version , call_from_python = call_from_python )
7676
7777
7878@pytest .mark .parametrize (
7979 "pydantic_version, call_from_python" ,
8080 product (_PYDANTIC_VERSIONS , [False , True ]),
8181)
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 ):
8383 _run_test (
8484 tmp_path ,
8585 "excluding_models" ,
@@ -91,25 +91,25 @@ def test_excluding_models(tmp_path: Path, pydantic_version: str, call_from_pytho
9191
9292@pytest .mark .parametrize (
9393 "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 ]),
9595)
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 ):
9797 _run_test (tmp_path , "computed_fields" , pydantic_version , call_from_python = call_from_python )
9898
9999
100100@pytest .mark .parametrize (
101101 "pydantic_version, call_from_python" ,
102102 product (_PYDANTIC_VERSIONS , [False , True ]),
103103)
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 ):
105105 _run_test (tmp_path , "extra_fields" , pydantic_version , call_from_python = call_from_python )
106106
107107
108108def test_relative_filepath (tmp_path : Path ):
109109 test_name = "single_module"
110110 pydantic_version = _PYDANTIC_VERSIONS [0 ]
111111 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"
113113 )
114114 _run_test (
115115 tmp_path ,
0 commit comments