Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_matrix(self, numbers):
with pytest.raises(NonEnumerableError):
numbers.matrix(num_type='int')
result = numbers.matrix(rounding=4)
assert len(result) == 10
for row in result:
assert len(row) == 10
for e in row:
assert isinstance(e, float)
assert len(str(e).split('.')[1]) <= 4
result = numbers.matrix(m=5, n=5, num_type=NumTypes.INTEGERS, start=5)
assert len(result) == 5
for row in result:
assert len(row) == 5
assert min(row) >= 5
for e in row:
Gender.FEMALE,
Gender.MALE,
],
)
def test_full_name(self, person, gender):
result = person.full_name(gender=gender)
result = result.split(' ')
assert result[0] is not None
assert result[1] is not None
result = person.full_name(reverse=True)
assert result is not None
with pytest.raises(NonEnumerableError):
person.full_name(gender='nil')
(True, PortRange.REGISTERED),
],
)
def test_ip_v4(self, net, with_port, port_range):
ip = net.ip_v4(with_port, port_range)
if not with_port:
assert re.match(patterns.IP_V4_REGEX, ip)
else:
port = int(ip.split(':')[-1])
port_start, port_end = port_range.value
assert port_start <= port <= port_end
(False, PortRange.ALL),
(True, PortRange.ALL),
(True, PortRange.WELL_KNOWN),
(True, PortRange.EPHEMERAL),
(True, PortRange.REGISTERED),
],
)
def test_ip_v4(self, net, with_port, port_range):
ip = net.ip_v4(with_port, port_range)
if not with_port:
assert re.match(patterns.IP_V4_REGEX, ip)
else:
port = int(ip.split(':')[-1])
port_start, port_end = port_range.value
assert port_start <= port <= port_end
from mimesis_factory import MimesisField
class Guest(object):
def __init__(self, full_name, patronymic):
self.full_name = full_name
self.patronymic = patronymic
@register
class FactoryWithNoProviders(factory.Factory):
class Meta(object):
model = Guest
full_name = MimesisField('full_name', gender=Gender.FEMALE)
patronymic = MimesisField('patronymic')
@register
class FactoryWithProviders(factory.Factory):
class Meta(object):
model = Guest
class Params(object):
providers = (builtins.RussiaSpecProvider,)
full_name = MimesisField('full_name', gender=Gender.FEMALE)
patronymic = MimesisField('patronymic')
def test_factory_with_not_extended_providers(factory_with_no_providers):
def test_credit_card_owner(self, p1, p2):
assert p1.credit_card_owner() == p2.credit_card_owner()
assert p1.credit_card_owner(gender=Gender.FEMALE) == \
p2.credit_card_owner(gender=Gender.FEMALE)
Gender.MALE,
],
)
def test_patronymic(russia, gender):
result = russia.patronymic(gender=gender)
assert result is not None
assert len(result) >= 4
with pytest.raises(NonEnumerableError):
russia.patronymic(gender='nil')
(Gender.FEMALE, 'female'),
(None, ['female', 'male']),
],
)
def test_validate_enum(self, base_data_provider, gender, excepted):
result = base_data_provider._validate_enum(gender, Gender)
assert (result == excepted) or (result in excepted)
assert result in [item.value for item in Gender]
with pytest.raises(NonEnumerableError):
base_data_provider._validate_enum('', '')
def test_surname(self, p1, p2):
assert p1.surname() == p2.surname()
assert p1.last_name(gender=Gender.MALE) == \
p2.last_name(gender=Gender.MALE)
MIN_AGE = 30
MAX_AGE = 32
class Guest(object):
def __init__(self, full_name, age):
self.full_name = full_name
self.age = age
@register
class GuestFactory(factory.Factory):
class Meta(object):
model = Guest
full_name = MimesisField('full_name', gender=Gender.FEMALE)
age = MimesisField('age', minimum=MIN_AGE, maximum=MAX_AGE)
def test_guest_factory_different_data(guest_factory):
guest1 = guest_factory()
guest2 = guest_factory()
assert isinstance(guest1, Guest)
assert isinstance(guest2, Guest)
assert guest1 != guest2
assert guest1.full_name != guest2.full_name
assert MIN_AGE <= guest1.age <= MAX_AGE
assert MIN_AGE <= guest2.age <= MAX_AGE
def test_guest_factory_create_batch(guest_factory):