Skip to content

Commit 68dc5a5

Browse files
author
Maximilian Sander
committed
Add test case for '--extend-yaml-scientific-notation' cli option
1 parent 1852aa9 commit 68dc5a5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# generated by datamodel-codegen:
2+
# filename: scientific_notation.json
3+
# timestamp: 2025-03-28T00:00:00+00:00
4+
5+
from __future__ import annotations
6+
7+
from typing import Optional
8+
9+
from pydantic import BaseModel, Field
10+
11+
12+
class Model(BaseModel):
13+
test: Optional[float] = Field(1e-05, description='Testcase', title='Test')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"test": {
6+
"type": "number",
7+
"title": "Test",
8+
"description": "Testcase",
9+
"default": 1e-5
10+
}
11+
}
12+
}

tests/main/jsonschema/test_main_jsonschema.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,3 +3114,22 @@ def test_main_jsonschema_field_has_same_name(output_model: str, expected_output:
31143114
])
31153115
assert return_code == Exit.OK
31163116
assert output_file.read_text() == (EXPECTED_JSON_SCHEMA_PATH / expected_output).read_text()
3117+
3118+
@freeze_time("2025-03-28")
3119+
def test_main_scientific_notation() -> None:
3120+
with TemporaryDirectory() as output_dir:
3121+
output_file: Path = Path(output_dir) / "scientific_notation.py"
3122+
expected_output: Path = EXPECTED_JSON_SCHEMA_PATH / "scientific_notation.py"
3123+
return_code: Exit = main([
3124+
"--extend-yaml-scientifc-notation",
3125+
"--input",
3126+
str(JSON_SCHEMA_DATA_PATH / "scientific_notation.json"),
3127+
"--output",
3128+
str(output_file),
3129+
"--input-file-type",
3130+
"jsonschema",
3131+
"--output-model-type",
3132+
"pydantic_v2.BaseModel",
3133+
])
3134+
assert return_code == Exit.OK
3135+
assert output_file.read_text() == (EXPECTED_JSON_SCHEMA_PATH / expected_output).read_text()

0 commit comments

Comments
 (0)