Example: we want to generate names, but names cannot start with numbers.
from fauxfactory import gen_string
name = gen_string(
'alpha',
validator=lambda x: not x.startswith(('1', '2', '3', '4', '5', '6', '7', '8', '9', '0')),
default='foobar',
tries=10
)
or simpler
name = gen_string(
'alpha',
validator=lambda x: not x[0].isdigit(),
default='foobar',
tries=10
)
So fauxfactory should accept validator which should return True, otherwise the value is None or default. If tries is set, then it retries to generate 10 times, if tries = 0 it tries to generate until validator is met!
BONUS: the validator must be callable or re.Pattern instance, so it checks for regex matching.
Example: we want to generate names, but names cannot start with numbers.
So fauxfactory should accept
validator
which should return True, otherwise the value isNone
ordefault
. Iftries
is set, then it retries to generate 10 times, iftries
=0
it tries to generate until validator is met!BONUS: the validator must be callable or
re.Pattern
instance, so it checks for regex matching.