coincidence.utils

Test helper utilities.

Functions:

generate_truthy_values([extra_truthy, ratio])

Returns an iterator of strings, integers and booleans which should be considered True.

generate_falsy_values([extra_falsy, ratio])

Returns an iterator of strings, integers and booleans which should be considered False.

is_docker()

Returns whether the current Python instance is running in Docker.

with_fixed_datetime(fixed_datetime)

Context manager to set a fixed datetime for the duration of the with block.

generate_truthy_values(extra_truthy=(), ratio=1)[source]

Returns an iterator of strings, integers and booleans which should be considered True.

Optionally, a random selection of the values can be returned using the ratio argument.

Parameters
  • extra_truthy (Iterable[Union[str, int, ~_T]]) – Additional values which should be considered True. Default ().

  • ratio (float) – The ratio of the number of values to select to the total number of values. Default 1.

Return type

Iterator[Union[str, int, ~_T]]

generate_falsy_values(extra_falsy=(), ratio=1)[source]

Returns an iterator of strings, integers and booleans which should be considered False.

Optionally, a random selection of the values can be returned using the ratio argument.

Parameters
  • extra_falsy (Iterable[Union[str, int, ~_T]]) – Additional values which should be considered True. Default ().

  • ratio (float) – The ratio of the number of values to select to the total number of values. Default 1.

Return type

Iterator[Union[str, int, ~_T]]

is_docker()[source]

Returns whether the current Python instance is running in Docker.

Return type

bool

with_fixed_datetime(fixed_datetime)[source]

Context manager to set a fixed datetime for the duration of the with block.

Parameters

fixed_datetime (datetime)

See also

The fixed_datetime fixture.

Attention

The monkeypatching only works when datetime is used and imported like:

import datetime
print(datetime.datetime.now())

Using from datetime import datetime won’t work.

Return type

Iterator