Skip to content

Commit

Permalink
Make test cases easier to create and understand
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Jul 10, 2023
1 parent f43957a commit 7aef942
Showing 1 changed file with 68 additions and 66 deletions.
134 changes: 68 additions & 66 deletions tests/integration/cases/config_to_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import textwrap

from ..case import Case
from ..file import File

Expand All @@ -6,84 +8,84 @@
id="Replace Config class to model",
input=File(
"config_to_model.py",
content=[
"from pydantic import BaseModel",
"",
"",
"class A(BaseModel):",
" class Config:",
" orm_mode = True",
" validate_all = True",
"",
"",
"class BaseConfig:",
" orm_mode = True",
" validate_all = True",
"",
"",
"class B(BaseModel):",
" class Config(BaseConfig):",
" ...",
],
content=textwrap.dedent("""\
from pydantic import BaseModel"
class A(BaseModel):
class Config:
orm_mode = True
validate_all = True
class BaseConfig:
orm_mode = True
validate_all = True
class B(BaseModel):
class Config(BaseConfig):
...
""").splitlines(),
),
expected=File(
"config_to_model.py",
content=[
"from pydantic import ConfigDict, BaseModel",
"",
"",
"class A(BaseModel):",
" model_config = ConfigDict(from_attributes=True, validate_default=True)",
"",
"",
"class BaseConfig:",
" orm_mode = True",
" validate_all = True",
"",
"",
"class B(BaseModel):",
" # TODO[pydantic]: The `Config` class inherits from another class, please create the `model_config` manually.", # noqa: E501
" # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.",
" class Config(BaseConfig):",
" ...",
],
content=textwrap.dedent("""\
from pydantic import ConfigDict, BaseModel
class A(BaseModel):
model_config = ConfigDict(from_attributes=True, validate_default=True)
class BaseConfig:
orm_mode = True
validate_all = True
class B(BaseModel):
# TODO[pydantic]: The `Config` class inherits from another class, please create the `model_config` manually.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
class Config(BaseConfig):
...",
""").splitlines(),
),
),
Case(
id="Replace Config class on BaseSettings",
input=File(
"config_dict_and_settings.py",
content=[
"from pydantic import BaseModel, BaseSettings",
"",
"",
"class Settings(BaseSettings):",
" sentry_dsn: str",
"",
" class Config:",
" orm_mode = True",
"",
"",
"class A(BaseModel):",
" class Config:",
" orm_mode = True",
],
content=textwrap.dedent("""\
from pydantic import BaseModel, BaseSettings
class Settings(BaseSettings):
sentry_dsn: str
class Config:
orm_mode = True
class A(BaseModel):
class Config:
orm_mode = True
""").splitlines(),
),
expected=File(
"config_dict_and_settings.py",
content=[
"from pydantic import ConfigDict, BaseModel",
"from pydantic_settings import BaseSettings, SettingsConfigDict",
"",
"",
"class Settings(BaseSettings):",
" sentry_dsn: str",
" model_config = SettingsConfigDict(from_attributes=True)",
"",
"",
"class A(BaseModel):",
" model_config = ConfigDict(from_attributes=True)",
],
content=textwrap.dedent("""\
from pydantic import ConfigDict, BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
sentry_dsn: str
model_config = SettingsConfigDict(from_attributes=True)
class A(BaseModel):
model_config = ConfigDict(from_attributes=True)
""").splitlines(),
),
),
]

0 comments on commit 7aef942

Please sign in to comment.