Factories (objetto.factories)

Factories.

class objetto.factories.MultiFactory(factories, module=None)

Adds multiple factories together.

Inherits from:
Parameters

factories (collections.abc.Iterable[objetto.bases.BaseFactory or collections.abc.Callable or function or str or None]) – Factories to be added together.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

__add__(other)

Add with another factory.

Parameters

other (objetto.bases.BaseFactoryor str or collections.abc.Callable or None) – Another factory.

Returns

Multi factory with added factories.

Return type

objetto.factories.MultiFactory

property factories

Factories.

Returns

tuple[objetto.bases.BaseFactory or collections.abc.Callable or function or str]

class objetto.factories.Integer(minimum=None, maximum=None, clamp_minimum=False, clamp_maximum=False, accepts_none=False)

Integer factory.

Inherits from:
Parameters
  • minimum (int or None) – Minimum.

  • maximum (int or None) – Maximum.

  • clamp_minimum (bool) – Whether to clamp to minimum value instead of erroring.

  • clamp_maximum (bool) – Whether to clamp to maximum value instead of erroring.

  • accepts_none (bool) – Whether to accept None as a value.

Raises

ValueError – Invalid parameter value.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value (int or None) – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

Return type

int or None

Raises

ValueError – Value out of bounds.

property minimum

Minimum.

Return type

int or None

property maximum

Maximum.

Return type

int or None

property clamp_minimum

Whether to clamp to minimum value instead of erroring.

Return type

bool

property clamp_maximum

Whether to clamp to maximum value instead of erroring.

Return type

bool

property accepts_none

Whether to accept None as a value.

Return type

bool

class objetto.factories.FloatingPoint(minimum=None, maximum=None, clamp_minimum=False, clamp_maximum=False, accepts_none=False)

Floating point factory.

Inherits from:
Parameters
  • minimum (float or None) – Minimum.

  • maximum (float or None) – Maximum.

  • clamp_minimum (bool) – Whether to clamp to minimum value instead of erroring.

  • clamp_maximum (bool) – Whether to clamp to maximum value instead of erroring.

  • accepts_none (bool) – Whether to accept None as a value.

Raises

ValueError – Invalid parameter value.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value (float or None) – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

Return type

float or None

Raises

ValueError – Value out of bounds.

property minimum

Minimum.

Return type

float or None

property maximum

Maximum.

Return type

float or None

property clamp_minimum

Whether to clamp to minimum value instead of erroring.

Return type

bool

property clamp_maximum

Whether to clamp to maximum value instead of erroring.

Return type

bool

property accepts_none

Whether to accept None as a value.

Return type

bool

class objetto.factories.String(accepts_none=False)

String factory.

Inherits from:
Parameters

accepts_none (bool) – Whether to accept None.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value (str or None) – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

Return type

str or None

Raises

ValueError – Value out of bounds.

property accepts_none

Whether to accept None.

Return type

bool

class objetto.factories.RegexMatch(pattern, accepts_none=False)

Regex match check factory.

Inherits from:
Parameters
  • pattern (str) – Regex pattern.

  • accepts_none (bool) – Whether to accept None.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value (str or None) – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

Return type

str or None

Raises

ValueError – Value out of bounds.

property pattern

Regex pattern.

Return type

str

property compiled_pattern

Compiled regex pattern.

Return type

re.Pattern

class objetto.factories.RegexSub(pattern, repl, accepts_none=False)

Regex substitution factory.

Inherits from:
Parameters
  • pattern (str) – Regex pattern.

  • repl (str) – Substitution.

  • accepts_none (bool) – Whether to accept None.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value (str or None) – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

Return type

str or None

Raises

ValueError – Value out of bounds.

property pattern

Regex pattern.

Return type

str

property compiled_pattern

Compiled regex pattern.

Return type

re.Pattern

property repl

Substitution.

Return type

str

class objetto.factories.Curated(*values)

Curated values factory.

Inherits from:
Parameters

values – Accepted values.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

property values

Accepted values.

Return type

tuple

class objetto.factories.Boolean(accepts_none=False)

Boolean factory.

Inherits from:
Parameters

accepts_none (bool) – Whether to accept None as a value.

__call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value – Input value.

  • kwargs – Keyword arguments.

Returns

Output value (True or False).

Return type

bool or None

property accepts_none

Whether to accept None as a value.

Return type

bool