-
-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Remove Pydantic as default model from tests (#2458)
* Remove Pydantic as default model from tests --------- Signed-off-by: Janek Nouvertné <[email protected]>
- Loading branch information
1 parent
5fd40c1
commit 56eaeeb
Showing
22 changed files
with
368 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +0,0 @@ | ||
from dataclasses import dataclass as vanilla_dataclass | ||
from enum import Enum | ||
from typing import Dict, List, Optional | ||
from uuid import UUID | ||
|
||
import attrs | ||
import msgspec | ||
from polyfactory.factories.pydantic_factory import ModelFactory | ||
from pydantic import BaseModel, Field | ||
from pydantic.dataclasses import dataclass as pydantic_dataclass | ||
from typing_extensions import NotRequired, Required, TypedDict | ||
|
||
from litestar.contrib.pydantic import PydanticDTO | ||
from litestar.dto import DTOConfig | ||
|
||
|
||
class Species(str, Enum): | ||
DOG = "Dog" | ||
CAT = "Cat" | ||
MONKEY = "Monkey" | ||
PIG = "Pig" | ||
|
||
|
||
class PydanticPet(BaseModel): | ||
name: str | ||
species: Species = Field(default=Species.MONKEY) | ||
age: float | ||
|
||
|
||
class PydanticPerson(BaseModel): | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[PydanticPet]] = None | ||
|
||
|
||
class PydanticPersonFactory(ModelFactory[PydanticPerson]): | ||
__model__ = PydanticPerson | ||
|
||
|
||
class PydanticPetFactory(ModelFactory[PydanticPet]): | ||
__model__ = PydanticPet | ||
|
||
|
||
class PartialPersonDTO(PydanticDTO[PydanticPerson]): | ||
config = DTOConfig(partial=True) | ||
|
||
|
||
@vanilla_dataclass | ||
class VanillaDataClassPerson: | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[PydanticPet]] = None | ||
|
||
|
||
@pydantic_dataclass | ||
class PydanticDataClassPerson: | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[PydanticPet]] = None | ||
|
||
|
||
class TypedDictPerson(TypedDict): | ||
first_name: Required[str] | ||
last_name: Required[str] | ||
id: Required[str] | ||
optional: NotRequired[Optional[str]] | ||
complex: Required[Dict[str, List[Dict[str, str]]]] | ||
pets: NotRequired[Optional[List[PydanticPet]]] | ||
|
||
|
||
@attrs.define | ||
class AttrsPerson: | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[PydanticPet]] | ||
|
||
|
||
class MsgSpecStructPerson(msgspec.Struct): | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[PydanticPet]] | ||
|
||
|
||
class User(BaseModel): | ||
name: str | ||
id: UUID | ||
|
||
|
||
class UserFactory(ModelFactory[User]): | ||
__model__ = User | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import dataclasses | ||
from enum import Enum | ||
from typing import Dict, List, Optional | ||
from uuid import UUID | ||
|
||
import attrs | ||
import msgspec | ||
from polyfactory.factories import DataclassFactory | ||
from pydantic import BaseModel | ||
from pydantic.dataclasses import dataclass as pydantic_dataclass | ||
from typing_extensions import NotRequired, Required, TypedDict | ||
|
||
|
||
class Species(str, Enum): | ||
DOG = "Dog" | ||
CAT = "Cat" | ||
MONKEY = "Monkey" | ||
PIG = "Pig" | ||
|
||
|
||
@dataclasses.dataclass | ||
class DataclassPet: | ||
name: str | ||
age: float | ||
species: Species = Species.MONKEY | ||
|
||
|
||
@dataclasses.dataclass | ||
class DataclassPerson: | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[DataclassPet]] = None | ||
|
||
|
||
@pydantic_dataclass | ||
class PydanticDataclassPerson: | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[DataclassPet]] = None | ||
|
||
|
||
class TypedDictPerson(TypedDict): | ||
first_name: Required[str] | ||
last_name: Required[str] | ||
id: Required[str] | ||
optional: NotRequired[Optional[str]] | ||
complex: Required[Dict[str, List[Dict[str, str]]]] | ||
pets: NotRequired[Optional[List[DataclassPet]]] | ||
|
||
|
||
class PydanticPerson(BaseModel): | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[DataclassPet]] = None | ||
|
||
|
||
@attrs.define | ||
class AttrsPerson: | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[DataclassPet]] | ||
|
||
|
||
class MsgSpecStructPerson(msgspec.Struct): | ||
first_name: str | ||
last_name: str | ||
id: str | ||
optional: Optional[str] | ||
complex: Dict[str, List[Dict[str, str]]] | ||
pets: Optional[List[DataclassPet]] | ||
|
||
|
||
@dataclasses.dataclass | ||
class User: | ||
name: str | ||
id: UUID | ||
|
||
|
||
class UserFactory(DataclassFactory[User]): | ||
__model__ = User | ||
|
||
|
||
class DataclassPersonFactory(DataclassFactory[DataclassPerson]): | ||
__model__ = DataclassPerson | ||
|
||
|
||
class DataclassPetFactory(DataclassFactory[DataclassPet]): | ||
__model__ = DataclassPet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.