File: test_example_1.py

package info (click to toggle)
python-polyfactory 2.22.2-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,892 kB
  • sloc: python: 11,338; makefile: 102; sh: 38
file content (37 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from __future__ import annotations

from dataclasses import dataclass
from typing import Literal

from polyfactory.factories.dataclass_factory import DataclassFactory


@dataclass
class Car:
    model: str


@dataclass
class Boat:
    can_float: bool


@dataclass
class Profile:
    age: int
    favourite_color: Literal["red", "green", "blue"]
    vehicle: Car | Boat


class ProfileFactory(DataclassFactory[Profile]): ...


def test_profile_coverage() -> None:
    profiles = list(ProfileFactory.coverage())

    assert profiles[0].favourite_color == "red"
    assert isinstance(profiles[0].vehicle, Car)
    assert profiles[1].favourite_color == "green"
    assert isinstance(profiles[1].vehicle, Boat)
    assert profiles[2].favourite_color == "blue"
    assert isinstance(profiles[2].vehicle, Car)