Skip to content

Commit cdae02e

Browse files
committed
test: add test for extra config
1 parent 787f229 commit cdae02e

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pydantic import BaseModel, Extra
2+
3+
4+
class ModelAllow(BaseModel, extra=Extra.allow):
5+
a: str
6+
7+
class ModelDefault(BaseModel):
8+
a: str
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
/* This file was automatically generated from pydantic models by running pydantic2ts.
5+
/* Do not modify it by hand - just update the pydantic models and then re-run the script
6+
*/
7+
8+
export interface ModelAllow {
9+
a: string;
10+
[k: string]: unknown;
11+
}
12+
export interface ModelDefault {
13+
a: string;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pydantic import BaseModel, ConfigDict
2+
3+
4+
class ModelExtraAllow(BaseModel):
5+
model_config = ConfigDict(extra="allow")
6+
a: str
7+
8+
9+
class ModelExtraForbid(BaseModel):
10+
model_config = ConfigDict(extra="forbid")
11+
a: str
12+
13+
14+
class ModelExtraIgnore(BaseModel):
15+
model_config = ConfigDict(extra="ignore")
16+
a: str
17+
18+
19+
class ModelExtraNone(BaseModel):
20+
a: str
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
/* This file was automatically generated from pydantic models by running pydantic2ts.
5+
/* Do not modify it by hand - just update the pydantic models and then re-run the script
6+
*/
7+
8+
export interface ModelExtraAllow {
9+
a: string;
10+
[k: string]: unknown;
11+
}
12+
export interface ModelExtraForbid {
13+
a: string;
14+
}
15+
export interface ModelExtraIgnore {
16+
a: string;
17+
}
18+
export interface ModelExtraNone {
19+
a: string;
20+
}

tests/test_script.py

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def test_computed_fields(tmpdir):
8787
pytest.skip("Computed fields are a pydantic v2 feature")
8888
run_test(tmpdir, "computed_fields")
8989

90+
def test_extra_fields(tmpdir):
91+
run_test(tmpdir, "extra_fields")
92+
9093

9194
def test_relative_filepath(tmpdir):
9295
test_name = "single_module"

0 commit comments

Comments
 (0)