pip_services3_commons.random package
Submodules
- pip_services3_commons.random.RandomArray module
- pip_services3_commons.random.RandomBoolean module
- pip_services3_commons.random.RandomDateTime module
- pip_services3_commons.random.RandomDouble module
- pip_services3_commons.random.RandomFloat module
- pip_services3_commons.random.RandomInteger module
- pip_services3_commons.random.RandomString module
- pip_services3_commons.random.RandomText module
Module contents
pip_services3_commons.random.__init__
Contains implementation of random args generators that are used for functional as well as non-functional testing. Used to generate random objects and fill databases with unique objects.
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
-
class
pip_services3_commons.random.
RandomArray
Bases:
object
Random generator for array objects.
Example:
value1 = RandomArray.pick([1, 2, 3, 4]) # Possible result: 3
-
static
pick
(values: List[Any]) → Any Picks a random element from specified array.
- Parameters
values – an array of any type
- Returns
a randomly picked item.
-
static
-
class
pip_services3_commons.random.
RandomBoolean
Bases:
object
Random generator for boolean values.
Example:
value1 = RandomBoolean.next_boolean() # Possible result: true value2 = RandomBoolean.chance(1,3) # Possible result: false
-
class
pip_services3_commons.random.
RandomDateTime
Bases:
object
Random generator for Date time values.
Example:
(month must be in 1..12) value1 = RandomDateTime.next_date(datetime.datetime(2010,1,1)) # Possible result: 2008-01-03 value2 = RandomDateTime.next_datetime(datetime.datetime(2017,1,1)) # Possible result: 2007-03-11 11:20:32 value3 = RandomDateTime.update_datetime(datetime.datetime(2010,1,2)) # Possible result: 2010-02-05 11:33:23
-
static
next_date
(min_year: <module 'datetime' from '/usr/local/lib/python3.10/datetime.py'>, max_year: <module 'datetime' from '/usr/local/lib/python3.10/datetime.py'> = None) → <module ‘datetime’ from ‘/usr/local/lib/python3.10/datetime.py’> Generates a random Date in the range [‘min_year’, ‘max_year’]. This method generate dates without time (or time set to 00:00:00
- Parameters
min_year – min range args
max_year – (optional) maximum range args
- Returns
a random Date and time args.
-
static
next_datetime
(min_year: <module 'datetime' from '/usr/local/lib/python3.10/datetime.py'>, max_year: <module 'datetime' from '/usr/local/lib/python3.10/datetime.py'> = None) → <module ‘datetime’ from ‘/usr/local/lib/python3.10/datetime.py’> Generates a random Date and time in the range [‘minYear’, ‘maxYear’]. This method generate dates without time (or time set to 00:00:00)
- Parameters
min_year – min range args
max_year – (optional) maximum range args
- Returns
a random Date and time args.
-
static
update_datetime
(value: <module 'datetime' from '/usr/local/lib/python3.10/datetime.py'>, range: Union[int, float] = None) → <module ‘datetime’ from ‘/usr/local/lib/python3.10/datetime.py’> Updates (drifts) a Date args within specified range defined
- Parameters
value – a Date args to drift.
range – (optional) a range in milliseconds. Default: 10 days
- Returns
an updated DateTime args.
-
static
-
class
pip_services3_commons.random.
RandomDouble
Bases:
object
Random generator for double values.
Example:
value1 = RandomDouble.next_double(5, 10) # Possible result: 7.3 value2 = RandomDouble.next_double(10) # Possible result: 3.7 value3 = RandomDouble.next_double(10, 3) # Possible result: 9.2
-
class
pip_services3_commons.random.
RandomFloat
Bases:
object
Random generator for float values.
Example:
value1 = RandomFloat.next_float(5, 10) # Possible result: 7.3 value2 = RandomFloat.next_float(10) # Possible result: 3.7 value3 = RandomFloat.update_float(10, 3) # Possible result: 9.2
-
class
pip_services3_commons.random.
RandomInteger
Bases:
object
Random generator for integer values.
Example:
value1 = RandomInteger.next_integer(5, 10) # Possible result: 7 value2 = RandomInteger.next_integer(10) # Possible result: 3 value3 = RandomInteger.update_integer(10, 3) # Possible result: 9
-
static
next_integer
(min: int, max: int = None) → int Generates a integer in the range [‘min’, ‘max’]. If ‘max’ is omitted, then the range will be set to [0, ‘min’].
- Parameters
min – minimum args of the integer that will be generated. If ‘max’ is omitted, then ‘max’ is set to ‘min’ and ‘min’ is set to 0.
max – (optional) maximum args of the float that will be generated. Defaults to ‘min’ if omitted.
- Returns
generated random integer args.
-
static
sequence
(min: int, max: int = None) → List[int] Generates a random sequence of integers starting from 0 like: [0,1,2,3…??]
- Parameters
min – minimum args of the integer that will be generated. If ‘max’ is omitted, then ‘max’ is set to ‘min’ and ‘min’ is set to 0.
max – (optional) maximum args of the float that will be generated. Defaults to ‘min’ if omitted.
- Returns
generated array of integers.
-
static
-
class
pip_services3_commons.random.
RandomString
Bases:
object
Random generator for string values.
Example:
value1 = RandomString.pickChar("ABC") # Possible result: "C" value2 = RandomString.pick(["A","B","C"]) # Possible result: "gBW"
-
static
distort
(value: str) → str Distorts a string by randomly replacing characters in it.
- Parameters
value – a string to distort.
- Returns
a distored string.
-
static
next_alpha_char
() → str Generates random alpha characted [A-Za-z] :return: a random characted.
-
static
next_string
(min_size: int, max_size: int) → str Generates a random string, consisting of upper and lower case letters (of the English alphabet), digits (0-9), and symbols (“_,.:-/.[].{},#-!,$=%.+^.&*-() “).
- Parameters
min_size – (optional) minimum string length.
max_size – maximum string length.
- Returns
a random string.
-
static
-
class
pip_services3_commons.random.
RandomText
Bases:
object
Random generator for various text values like names, addresses or phone numbers.
Example:
value1 = RandomText.name() # Possible result: "Sergio" value2 = RandomText.verb() # Possible result: "Run" value3 = RandomText.text(50) # Possible result: "Run jorge. Red high scream?"
-
static
adjective
() → str Generates a random adjective. The result args is capitalized.
- Returns
a random adjective.
-
static
color
() → str Generates a random color name. The result args is capitalized.
- Returns
a random color name.
-
static
full_name
() → str Generates a random person’s name which has the following structure <optional prefix> <first name> <second name> <optional suffix>
- Returns
a random name.
-
static
name
() → str Generates a random person’s name which has the following structure <optional prefix> <first name> <second name> <optional suffix>
- Returns
a random name.
-
static
noun
() → str Generates a random noun. The result value is capitalized.
- Returns
a random noun
-
static
phone
() → str Generates a random phone number. The phone number has the format: (XXX) XXX-YYYY
- Returns
a random phone number.
-
static
phrase
(min_size: int, max_size: int = None) → str Generates a random phrase which consists of few words separated by spaces. The first word is capitalized, others are not.
- Parameters
min_size – (optional) minimum string length.
max_size – maximum string length.
- Returns
a random phrase.
-
static
stuff
() → str Generates a random noun. The result args is capitalized.
- Returns
a random noun.
-
static
text
(min_size: int, max_size: int = None) → str Generates a random text, consisting of first names, last names, colors, stuffs, adjectives, verbs, and punctuation marks.
- Parameters
min_size – minimum amount of words to generate. Text will contain ‘minSize’ words if ‘maxSize’ is omitted.
max_size – (optional) maximum amount of words to generate.
- Returns
a random text.
-
static
verb
() → str Generates a random verb. The result args is capitalized.
- Returns
a random verb.
-
static