arjuna.tpi.data.generator module

Data Generator

This module contains classes and functions that generate data.

class arjuna.tpi.data.generator.Random

Bases: object

Provides methods to create random strings and numbers of different kinds.

classmethod city(*, locale='en')

Generate a city name.

Keyword Arguments:
 locale – (Optional) locale for generating city name
Returns:A generated city name
classmethod country(*, locale='en')

Generate a country name

Keyword Arguments:
 locale – (Optional) locale for generating country name
Returns:A generated country name
classmethod email(*, locale='en')

Generate an email address.

Keyword Arguments:
 locale – (Optional) locale for generating email address
Returns:A generated email address
classmethod first_name(*, locale='en')

Generate a first name.

Keyword Arguments:
 locale – (Optional) locale for generating first name
Returns:A generated first name
classmethod fixed_length_number(*, length)

Generate a fixed length number

Keyword Arguments:
 length – Number of digits in generated number.
Returns:A generated fixed length number

Note

A number of minimum length 1 is always generated.

classmethod house_number(*, locale='en')

Generate a house number

Keyword Arguments:
 locale – (Optional) locale for generating house number
Returns:A generated house number
classmethod int(*, end, begin=0)

Generate a random integer.

Keyword Arguments:
 
  • end – (inclusive) upper limit for the integer
  • begin – (inclusive) lower limit for the integer. Default is 0.
Returns:

A generated integer

classmethod last_name(*, locale='en')

Generate a last name.

Keyword Arguments:
 locale – (Optional) locale for generating last name
Returns:A generated last name
classmethod name(*, locale='en')

Generate a full name (first name and last name).

Keyword Arguments:
 locale – (Optional) locale for generating phone number
Returns:A generated full name
classmethod phone(*, locale='en')

Generate a phone number.

Keyword Arguments:
 locale – (Optional) locale for generating phone number
Returns:A generated phone number
classmethod postal_code(*, locale='en')

Generate a postal code

Keyword Arguments:
 locale – (Optional) locale for generating postal code
Returns:A generated postal code
classmethod sentence(*, locale='en')

Generate a sentence

Keyword Arguments:
 locale – (Optional) locale for generating sentence
Returns:A generated sentence
classmethod street_name(*, locale='en')

Generate a street name

Keyword Arguments:
 locale – (Optional) locale for generating street name
Returns:A generated street name
classmethod street_number(*, locale='en')

Generate a street number

Keyword Arguments:
 locale – (Optional) locale for generating street number
Returns:A generated street number
classmethod ustr(*, prefix: str = None, maxlen=None) → str

Generate a unique UUID string

Keyword Arguments:
 
  • prefix – (Optional) prefix to be added to the generated UUID string.
  • maxlen – (Optional) Maximum length of the retuned string (inclusive of prefix-).
Returns:

A string that is unique for current session.

class arjuna.tpi.data.generator.composer(callable, *args, **kwargs)

Bases: object

Combines data in an iterable by calling the provided callable with provided arguments.

Parameters:
  • callable – The callable to be called in composing.
  • *args – Arbitrary positional args to be passed to the callable.
Keyword Arguments:
 

**kwargs – Arbitrary keyword arguments to tbe passed to the callable.

compose(data_iter)

Combine data in the provided iterable by calling the callable with arguments provided in constructor.

Parameters:data_iter – Data iterable
class arjuna.tpi.data.generator.composite(*generators_or_data, composer=<function _same>)

Bases: arjuna.tpi.data.generator._gen

Composite Data Generator.

Generate data by composing the output of all generators, callables or static data.

Parameters:*generators_or_data – Arbitrary generators, functions or static data objects.
Keyword Arguments:
 composer – This callable is called after data sequence is generated by passing generated data sequence as argument. Useful for data transformation of any kind.
generate()

Generate data by composing the output of all generators, callables or static data.

The composer callable is called after data sequence is generated by passing generated data sequence as argument. Useful for data transformation of any kind.

class arjuna.tpi.data.generator.generator(callable, *args, processor=<function _same>, **kwargs)

Bases: arjuna.tpi.data.generator._gen

Generate data by calling the provided callable with provided arguments.

Parameters:
  • callable – The callable to be called in composing. By default, same generated object is returned.
  • *args – Arbitrary positional args to be passed to the callable.
Keyword Arguments:
 
  • processor – This callable is called after data is generated by passing generated data as argument. Useful for data transformation of any kind. If its type is string, it is assumed to be a method of the data which the data callable generated.
  • **kwargs – Arbitrary keyword arguments to tbe passed to the callable.
generate()

Generate data by calling the callable with arguments provided in constructor.

After generation the coverter callable is called with this data before returning the data.

class arjuna.tpi.data.generator.processor(callable, *args, **kwargs)

Bases: object

Processes data by calling the provided callable with provided arguments.

Parameters:
  • callable – The callable to be called in processing.
  • *args – Arbitrary positional args to be passed to the callable.
Keyword Arguments:
 

**kwargs – Arbitrary keyword arguments to tbe passed to the callable.

process(data)

Processes data in the provided data object by calling the callable with arguments provided in constructor.

Parameters:data – Data object