This notebook contains tests for tohu's primitive generators.
In [1]:
import tohu
from tohu.v5.primitive_generators import *
from tohu.v5.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=12345)
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=12345)
print_generated_sequence(g2, num=20, seed=99999)
Integer
returns a random integer between low
and high
(both inclusive).
In [7]:
g = Integer(low=100, high=200)
In [8]:
print_generated_sequence(g, num=20, seed=12345)
Float
returns a random float between low
and high
(both inclusive).
In [9]:
g = Float(low=2.3, high=4.2)
In [10]:
print_generated_sequence(g, num=10, sep='\n', fmt='.12f', seed=12345)
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, uppercase=False)
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 [ ]: