constrained_numbers¶
- class polyfactory.value_generators.constrained_numbers.NumberGeneratorProtocol[source]¶
Bases:
Protocol
[T
]Protocol for custom callables used to generate numerical values
- __call__(random: Random, minimum: T | None = None, maximum: T | None = None) T [source]¶
Signature of the callable.
- __init__(*args, **kwargs)¶
- polyfactory.value_generators.constrained_numbers.almost_equal_floats(value_1: float, value_2: float, *, delta: float = 1e-08) bool [source]¶
Return True if two floats are almost equal
- polyfactory.value_generators.constrained_numbers.is_multiply_of_multiple_of_in_range(minimum: T, maximum: T, multiple_of: T) bool [source]¶
Determine if at least one multiply of multiple_of lies in the given range.
- polyfactory.value_generators.constrained_numbers.passes_pydantic_multiple_validator(value: T, multiple_of: T) bool [source]¶
Determine whether a given value passes the pydantic multiple_of validation.
- polyfactory.value_generators.constrained_numbers.get_increment(t_type: type[T]) T [source]¶
Get a small increment base to add to constrained values, i.e. lt/gt entries.
- Parameters:
t_type¶ – A value of type T.
- Returns:
An increment T.
- polyfactory.value_generators.constrained_numbers.get_value_or_none(t_type: type[T], lt: T | None = None, le: T | None = None, gt: T | None = None, ge: T | None = None) tuple[Optional[T], Optional[T]] [source]¶
Return an optional value.
- polyfactory.value_generators.constrained_numbers.get_constrained_number_range(t_type: type[T], random: Random, lt: T | None = None, le: T | None = None, gt: T | None = None, ge: T | None = None, multiple_of: T | None = None) tuple[T | None, T | None] [source]¶
Return the minimum and maximum values given a field_meta’s constraints.
- Parameters:
- Returns:
a tuple of optional minimum and maximum values.
- polyfactory.value_generators.constrained_numbers.generate_constrained_number(random: Random, minimum: T | None, maximum: T | None, multiple_of: T | None, method: NumberGeneratorProtocol[T]) T [source]¶
Generate a constrained number, output depends on the passed in callbacks.
- polyfactory.value_generators.constrained_numbers.handle_constrained_int(random: Random, multiple_of: int | None = None, gt: int | None = None, ge: int | None = None, lt: int | None = None, le: int | None = None) int [source]¶
Handle constrained integers.
- polyfactory.value_generators.constrained_numbers.handle_constrained_float(random: Random, multiple_of: float | None = None, gt: float | None = None, ge: float | None = None, lt: float | None = None, le: float | None = None) float [source]¶
Handle constrained floats.
- polyfactory.value_generators.constrained_numbers.validate_max_digits(max_digits: int, minimum: Decimal | None, decimal_places: int | None) None [source]¶
Validate that max digits is greater than minimum and decimal places.
- polyfactory.value_generators.constrained_numbers.handle_decimal_length(generated_decimal: Decimal, decimal_places: int | None, max_digits: int | None) Decimal [source]¶
Handle the length of the decimal.
- polyfactory.value_generators.constrained_numbers.handle_constrained_decimal(random: Random, multiple_of: Decimal | None = None, decimal_places: int | None = None, max_digits: int | None = None, gt: Decimal | None = None, ge: Decimal | None = None, lt: Decimal | None = None, le: Decimal | None = None) Decimal [source]¶
Handle a constrained decimal.