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_skip():
mixer = Mixer()
test = mixer.blend(Test, one=mixer.SKIP)
assert test.one is not mixer.SKIP
assert test.one is int
def test_guard():
mixer = Mixer()
test = mixer.guard().blend(Test)
assert test
def test_custom():
mixer = Mixer()
@mixer.middleware(Test)
def postprocess(x): # noqa
x.name += ' Done'
return x
mixer.register(
Test,
name='Mike',
one=mixer.faker.pyfloat,
body=mixer.faker.date_time,
)
test = mixer.blend(Test)
assert test.name == 'Mike Done'
assert isinstance(test.one, float)
def test_mixer():
mixer = Mixer()
assert Mixer.SKIP == mixer.SKIP
try:
Mixer.SKIP = 111
raise AssertionError('test are failed')
except AttributeError:
pass
try:
mixer.SKIP = 111
raise AssertionError('test are failed')
except AttributeError:
pass
gen = ('test{0}'.format(i) for i in range(500))
test = mixer.blend('tests.test_main.Test', name=gen)
assert test.name == 'test0'
def test_silence():
mixer = Mixer()
class CustomException(Exception):
pass
@mixer.middleware(Test)
def falsed(test): # noqa
raise CustomException('Unhandled')
with pytest.raises(CustomException):
mixer.blend(Test)
with mixer.ctx(silence=True):
mixer.blend(Test)
mixer.unregister_middleware(Test, falsed)
mixer.blend(Test) # does not raise any exceptions
def test_mixer_cycle():
mixer = Mixer()
test = mixer.cycle(3).blend(Test)
assert len(test) == 3
assert test[0].__class__ == Test
test = mixer.cycle(3).blend(Test, name=mixer.sequence('lama{0}'))
assert test[2].name == 'lama2'
"""
return ProxyMixer(self, count=1, guards=(args, kwargs))
def _guard(self, scheme, guards, **values):
type_mixer = self.get_typemixer(scheme)
args, kwargs = guards
seek = type_mixer.guard(*args, **kwargs)
if seek:
LOGGER.info('Finded: %s [%s]', seek, type(seek)) # noqa
return seek
return self.blend(scheme, **values)
# Default mixer
mixer = Mixer()
SELECT = property(lambda s: Mixer.SELECT)
SKIP = property(lambda s: Mixer.SKIP)
SKIP = property(lambda s: Mixer.SKIP)