|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import warnings |
5 | 6 | from argparse import ArgumentTypeError, Namespace |
6 | 7 | from typing import TYPE_CHECKING |
7 | 8 |
|
@@ -2240,3 +2241,53 @@ def test_custom_formatters_kwargs_invalid(output_file: Path, capsys: pytest.Capt |
2240 | 2241 | capsys=capsys, |
2241 | 2242 | expected_stderr_contains="Unable to load custom_formatters_kwargs mapping: must be a JSON string mapping", |
2242 | 2243 | ) |
| 2244 | + |
| 2245 | + |
| 2246 | +def test_use_annotated_deprecation_warning_pydantic_v2(output_file: Path) -> None: |
| 2247 | + """Test that deprecation warning is emitted for Pydantic v2 without --use-annotated.""" |
| 2248 | + with pytest.warns(DeprecationWarning, match=r"--use-annotated will be enabled by default for Pydantic v2"): |
| 2249 | + run_main_and_assert( |
| 2250 | + input_path=JSON_SCHEMA_DATA_PATH / "simple_string.json", |
| 2251 | + output_path=output_file, |
| 2252 | + input_file_type="jsonschema", |
| 2253 | + extra_args=["--output-model-type", "pydantic_v2.BaseModel"], |
| 2254 | + ) |
| 2255 | + |
| 2256 | + |
| 2257 | +def test_use_annotated_no_warning_with_flag(output_file: Path) -> None: |
| 2258 | + """Test that no warning is emitted when --use-annotated is explicitly set.""" |
| 2259 | + with warnings.catch_warnings(record=True) as w: |
| 2260 | + warnings.simplefilter("always") |
| 2261 | + run_main_and_assert( |
| 2262 | + input_path=JSON_SCHEMA_DATA_PATH / "simple_string.json", |
| 2263 | + output_path=output_file, |
| 2264 | + input_file_type="jsonschema", |
| 2265 | + extra_args=["--output-model-type", "pydantic_v2.BaseModel", "--use-annotated"], |
| 2266 | + ) |
| 2267 | + assert not any("--use-annotated will be enabled" in str(warning.message) for warning in w) |
| 2268 | + |
| 2269 | + |
| 2270 | +def test_use_annotated_no_warning_with_no_flag(output_file: Path) -> None: |
| 2271 | + """Test that no warning is emitted when --no-use-annotated is explicitly set.""" |
| 2272 | + with warnings.catch_warnings(record=True) as w: |
| 2273 | + warnings.simplefilter("always") |
| 2274 | + run_main_and_assert( |
| 2275 | + input_path=JSON_SCHEMA_DATA_PATH / "simple_string.json", |
| 2276 | + output_path=output_file, |
| 2277 | + input_file_type="jsonschema", |
| 2278 | + extra_args=["--output-model-type", "pydantic_v2.BaseModel", "--no-use-annotated"], |
| 2279 | + ) |
| 2280 | + assert not any("--use-annotated will be enabled" in str(warning.message) for warning in w) |
| 2281 | + |
| 2282 | + |
| 2283 | +def test_use_annotated_no_warning_pydantic_v1(output_file: Path) -> None: |
| 2284 | + """Test that use_annotated warning is not emitted for Pydantic v1.""" |
| 2285 | + with warnings.catch_warnings(record=True) as w: |
| 2286 | + warnings.simplefilter("always") |
| 2287 | + run_main_and_assert( |
| 2288 | + input_path=JSON_SCHEMA_DATA_PATH / "simple_string.json", |
| 2289 | + output_path=output_file, |
| 2290 | + input_file_type="jsonschema", |
| 2291 | + extra_args=["--output-model-type", "pydantic.BaseModel"], |
| 2292 | + ) |
| 2293 | + assert not any("--use-annotated will be enabled" in str(warning.message) for warning in w) |
0 commit comments