This notebook contains tests for tohu's primitive generators.
In [1]:
import tohu
from tohu.v7.primitive_generators import *
from tohu.v7.utils import print_generated_sequence
In [2]:
print(f'Tohu version: {tohu.__version__}')
Constant
simply returns the same, constant value every time.
In [3]:
g = Constant('quux')
In [4]:
print_generated_sequence(g, num=10, seed=99999)
Boolean
returns either True
or False
, optionally with different probabilities.
In [5]:
g1 = Boolean()
g2 = Boolean(p=0.8)
In [6]:
print_generated_sequence(g1, num=20, seed=99999)
print_generated_sequence(g2, num=20, seed=99999)
Incremental
returns a sequence of numbers that increase in regular steps.
In [7]:
g = Incremental(start=200, step=4)
In [8]:
print_generated_sequence(g, num=20, seed=99999)
Integer
returns a random integer between low
and high
(both inclusive).
In [9]:
g = Integer(low=100, high=200)
In [10]:
print_generated_sequence(g, num=20, seed=99999)
HashDigest
returns hex strings representing hash digest values (or alternatively raw bytes).
In [11]:
g = HashDigest(length=6)
In [12]:
print_generated_sequence(g, num=10, seed=12345)
In [13]:
g = HashDigest(length=6, lowercase=True)
In [14]:
print_generated_sequence(g, num=10, seed=12345)
In [15]:
g = HashDigest(length=10, as_bytes=True)
In [16]:
print_generated_sequence(g, num=5, seed=12345, sep='\n')
FakerGenerator
gives access to any of the methods supported by the faker module. Here are a couple of examples.
In [17]:
g = FakerGenerator(method='name')
In [18]:
print_generated_sequence(g, num=8, seed=12345)
In [19]:
g = FakerGenerator(method='address')
In [20]:
print_generated_sequence(g, num=8, seed=12345, sep='\n---\n')
In [ ]: