Skip to content

Commit 0ca6ac7

Browse files
committed
Make test cases easier to create and understand
1 parent f43957a commit 0ca6ac7

File tree

1 file changed

+68
-66
lines changed

1 file changed

+68
-66
lines changed
Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import textwrap
2+
13
from ..case import Case
24
from ..file import File
35

@@ -6,84 +8,84 @@
68
id="Replace Config class to model",
79
input=File(
810
"config_to_model.py",
9-
content=[
10-
"from pydantic import BaseModel",
11-
"",
12-
"",
13-
"class A(BaseModel):",
14-
" class Config:",
15-
" orm_mode = True",
16-
" validate_all = True",
17-
"",
18-
"",
19-
"class BaseConfig:",
20-
" orm_mode = True",
21-
" validate_all = True",
22-
"",
23-
"",
24-
"class B(BaseModel):",
25-
" class Config(BaseConfig):",
26-
" ...",
27-
],
11+
content=textwrap.dedent("""\
12+
from pydantic import BaseModel
13+
14+
15+
class A(BaseModel):
16+
class Config:
17+
orm_mode = True
18+
validate_all = True
19+
20+
21+
class BaseConfig:
22+
orm_mode = True
23+
validate_all = True
24+
25+
26+
class B(BaseModel):
27+
class Config(BaseConfig):
28+
...
29+
""").splitlines(),
2830
),
2931
expected=File(
3032
"config_to_model.py",
31-
content=[
32-
"from pydantic import ConfigDict, BaseModel",
33-
"",
34-
"",
35-
"class A(BaseModel):",
36-
" model_config = ConfigDict(from_attributes=True, validate_default=True)",
37-
"",
38-
"",
39-
"class BaseConfig:",
40-
" orm_mode = True",
41-
" validate_all = True",
42-
"",
43-
"",
44-
"class B(BaseModel):",
45-
" # TODO[pydantic]: The `Config` class inherits from another class, please create the `model_config` manually.", # noqa: E501
46-
" # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.",
47-
" class Config(BaseConfig):",
48-
" ...",
49-
],
33+
content=textwrap.dedent("""\
34+
from pydantic import ConfigDict, BaseModel
35+
36+
37+
class A(BaseModel):
38+
model_config = ConfigDict(from_attributes=True, validate_default=True)
39+
40+
41+
class BaseConfig:
42+
orm_mode = True
43+
validate_all = True
44+
45+
46+
class B(BaseModel):
47+
# TODO[pydantic]: The `Config` class inherits from another class, please create the `model_config` manually.
48+
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
49+
class Config(BaseConfig):
50+
...",
51+
""").splitlines(),
5052
),
5153
),
5254
Case(
5355
id="Replace Config class on BaseSettings",
5456
input=File(
5557
"config_dict_and_settings.py",
56-
content=[
57-
"from pydantic import BaseModel, BaseSettings",
58-
"",
59-
"",
60-
"class Settings(BaseSettings):",
61-
" sentry_dsn: str",
62-
"",
63-
" class Config:",
64-
" orm_mode = True",
65-
"",
66-
"",
67-
"class A(BaseModel):",
68-
" class Config:",
69-
" orm_mode = True",
70-
],
58+
content=textwrap.dedent("""\
59+
from pydantic import BaseModel, BaseSettings
60+
61+
62+
class Settings(BaseSettings):
63+
sentry_dsn: str
64+
65+
class Config:
66+
orm_mode = True
67+
68+
69+
class A(BaseModel):
70+
class Config:
71+
orm_mode = True
72+
""").splitlines(),
7173
),
7274
expected=File(
7375
"config_dict_and_settings.py",
74-
content=[
75-
"from pydantic import ConfigDict, BaseModel",
76-
"from pydantic_settings import BaseSettings, SettingsConfigDict",
77-
"",
78-
"",
79-
"class Settings(BaseSettings):",
80-
" sentry_dsn: str",
81-
" model_config = SettingsConfigDict(from_attributes=True)",
82-
"",
83-
"",
84-
"class A(BaseModel):",
85-
" model_config = ConfigDict(from_attributes=True)",
86-
],
76+
content=textwrap.dedent("""\
77+
from pydantic import ConfigDict, BaseModel
78+
from pydantic_settings import BaseSettings, SettingsConfigDict
79+
80+
81+
class Settings(BaseSettings):
82+
sentry_dsn: str
83+
model_config = SettingsConfigDict(from_attributes=True)
84+
85+
86+
class A(BaseModel):
87+
model_config = ConfigDict(from_attributes=True)
88+
""").splitlines(),
8789
),
8890
),
8991
]

0 commit comments

Comments
 (0)