Skip to content

Primitive Data

drizm_commons.testing.faker

Utilities for generating randomized test data.

from drizm_commons.testing import faker

random_email_address(top_level_domain='com', choice_sequence='abcdefghijklmnopqrstuvwxyz')

Generates a randomized email address out of provided presets.

Parameters:

Name Type Description Default
top_level_domain Optional[str]

The top-level-domain for the email address to be generated.

'com'
choice_sequence Optional[Sequence]

A sequence of characters that will be used to generated the random host and domain parts of the email address.

'abcdefghijklmnopqrstuvwxyz'

Returns:

Type Description
str

A semi-randomized email of the following format: prefix@host.tld.

random_flat_colored_image(size_x, size_y, ext='jpeg')

Generates a randomized image for testing purposes.

Parameters:

Name Type Description Default
size_x int

The width of the image to be generated, in pixels.

required
size_y int

The height of the image to be generated, in pixels.

required
ext Optional[str]

The filetype of the image to be generated, e.g. jpeg or png.

'jpeg'

Returns:

Type Description
BytesIO

A BytesIO file object, representing the generated image.

random_hex_color(short=False)

Generates a random hexadecimal color string.

Parameters:

Name Type Description Default
short Optional[bool]

If True, this function will generated a shortened 3-digit hex color, otherwise a 6-digit hex color will be generated instead.

False

Returns:

Type Description
str

A three or six digit hex color of the format #ff00ff or #f0f.

random_rgb_color()

Generates a random RGB-Color.

Returns:

Type Description
Tuple[int]

A tuple of 3 integer values between 0 and 255, representing the RGB colorspace of the generated color.