|
| 1 | +import textwrap |
| 2 | + |
1 | 3 | from ..case import Case
|
2 | 4 | from ..file import File
|
3 | 5 |
|
|
6 | 8 | id="Replace Config class to model",
|
7 | 9 | input=File(
|
8 | 10 | "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(), |
28 | 30 | ),
|
29 | 31 | expected=File(
|
30 | 32 | "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(), |
50 | 52 | ),
|
51 | 53 | ),
|
52 | 54 | Case(
|
53 | 55 | id="Replace Config class on BaseSettings",
|
54 | 56 | input=File(
|
55 | 57 | "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(), |
71 | 73 | ),
|
72 | 74 | expected=File(
|
73 | 75 | "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(), |
87 | 89 | ),
|
88 | 90 | ),
|
89 | 91 | ]
|
0 commit comments