本文整理汇总了Python中mixer.main.mixer.blend函数的典型用法代码示例。如果您正苦于以下问题:Python blend函数的具体用法?Python blend怎么用?Python blend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了blend函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom
def test_custom(self):
mixer = Mixer()
def postprocess(x):
x.name += ' Done'
return x
mixer.register(Test, {
'name': 'Mike',
'one': mixer.G.get_float,
'body': lambda: mixer.G.get_datetime((1980, 1, 1)),
}, postprocess=postprocess)
test = mixer.blend(Test)
self.assertEqual(test.name, 'Mike Done')
self.assertTrue(isinstance(test.one, float))
self.assertTrue(test.body >= datetime.datetime(1980, 1, 1))
from mixer.main import GenFactory
class MyFactory(GenFactory):
generators = {str: lambda: "Always same"}
mixer = Mixer(factory=MyFactory, fake=False)
test = mixer.blend(Test)
self.assertEqual(test.name, "Always same")
示例2: test_invalid_scheme
def test_invalid_scheme():
from mixer.main import mixer
try:
mixer.blend('tests.test_main.Unknown')
except ValueError:
return False
raise Exception('test.failed')
示例3: test_custom
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)
assert isinstance(test.body, datetime.datetime)
from mixer.main import GenFactory
class MyFactory(GenFactory):
generators = {str: lambda: "Always same"}
mixer = Mixer(factory=MyFactory, fake=False)
test = mixer.blend(Test)
assert test.name == "Always same"
示例4: test_fake
def test_fake(self):
from mixer.main import mixer
test = mixer.blend(Test, name=mixer.FAKE, title=mixer.FAKE)
self.assertTrue(' ' in test.name)
self.assertTrue(' ' in test.title)
test = mixer.blend(Test, name=mixer.FAKE(bool))
self.assertTrue(test.name in (True, False))
示例5: test_fake
def test_fake():
from mixer.main import mixer
test = mixer.blend(Test, name=mixer.FAKE, title=mixer.FAKE)
assert ' ' in test.name
assert ' ' in test.title
test = mixer.blend(Test, name=mixer.FAKE(bool))
assert test.name in (True, False)
示例6: test_ctx
def test_ctx(self):
from mixer.main import LOGGER
mixer = Mixer()
level = LOGGER.level
with mixer.ctx(loglevel='INFO'):
mixer.blend(Test)
self.assertNotEqual(LOGGER.level, level)
self.assertEqual(LOGGER.level, level)
示例7: test_mixer
def test_mixer(self):
mixer = Mixer()
gen = ('test{0}'.format(i) for i in range(500))
test = mixer.blend('tests.test_main.Test', name=gen)
self.assertEqual(test.name, 'test0')
name_gen = mixer.sequence(lambda c: 'test' + str(c))
test = mixer.blend(Test, name=name_gen)
test = mixer.blend(Test, name=name_gen)
test = mixer.blend(Test, name=name_gen)
self.assertEqual(test.name, 'test2')
name_gen = mixer.sequence('test{0}')
test = mixer.blend(Test, name=name_gen)
test = mixer.blend(Test, name=name_gen)
self.assertEqual(test.name, 'test1')
name_gen = mixer.sequence()
test = mixer.blend(Test, name=name_gen)
test = mixer.blend(Test, name=name_gen)
self.assertEqual(test.name, 1)
mixer.register('tests.test_main.Test', dict(
name='Michel',
one=lambda: 'ID',
unknown="No error here"
))
test = mixer.blend(Test)
self.assertEqual(test.one, 'ID')
self.assertEqual(test.name, 'Michel')
示例8: test_ctx
def test_ctx():
from mixer.main import LOGGER
mixer = Mixer()
level = LOGGER.level
with mixer.ctx(loglevel='INFO'):
mixer.blend(Test)
assert LOGGER.level != level
assert LOGGER.level == level
示例9: test_silence
def test_silence():
mixer = Mixer()
@mixer.middleware(Test)
def falsed(test): # noqa
raise Exception('Unhandled')
with pytest.raises(Exception):
mixer.blend(Test)
with mixer.ctx(silence=True):
mixer.blend(Test)
示例10: test_random
def test_random():
from mixer._compat import string_types
mixer = TypeMixer(Test)
test = mixer.blend(name=mixer.RANDOM)
assert isinstance(test.name, string_types)
test = mixer.blend(name=mixer.RANDOM(int))
assert isinstance(test.name, int)
names = ['john_', 'kenn_', 'lenny_']
test = mixer.blend(name=mixer.RANDOM(*names))
assert test.name in names
示例11: test_silence
def test_silence(self):
mixer = Mixer()
def falsed(test):
raise Exception('Unhandled')
mixer.register(Test, postprocess=falsed)
try:
mixer.blend(Test)
raise AssertionError("Test should be failed.")
except Exception: # noqa
pass
with mixer.ctx(silence=True):
mixer.blend(Test)
示例12: test_random
def test_random(self):
from mixer.main import TypeMixer
from mixer.six import string_types
mixer = TypeMixer(Test)
test = mixer.blend(name=mixer.RANDOM)
self.assertTrue(isinstance(test.name, string_types))
self.assertFalse(' ' in test.name)
test = mixer.blend(name=mixer.RANDOM(int))
self.assertTrue(isinstance(test.name, int))
names = ['john_', 'kenn_', 'lenny_']
test = mixer.blend(name=mixer.RANDOM(*names))
self.assertTrue(test.name in names)
示例13: test_mix
def test_mix(self):
from mixer.main import mixer
lama = type('One', tuple(), dict(
two=int,
one=type('Two', tuple(), dict(two=2.1))
))
mix = mixer.mix.one.two
self.assertEqual(mix & lama, 2.1)
test = mixer.blend(lama, one__two=2.1)
self.assertEqual(test.one.two, 2.1)
self.assertNotEqual(test.two, test.one.two)
test = mixer.blend(lama, one__two=2.1, two=mixer.mix.one.two)
self.assertEqual(test.two, test.one.two)
示例14: test_ctx
def test_ctx():
from mixer.main import LOGGER
mixer = Mixer()
level = LOGGER.level
with mixer.ctx(loglevel='INFO'):
mixer.blend(Test)
assert LOGGER.level != level
with mixer.ctx(locale='ru'):
phone = mixer.faker.phone_number()
assert phone.startswith('+7')
assert LOGGER.level == level
示例15: test_mix
def test_mix():
from mixer.main import mixer
lama = type('One', tuple(), dict(
two=int,
one=type('Two', tuple(), dict(two=2.1))
))
mix = mixer.MIX.one.two
assert mix & lama == 2.1
test = mixer.blend(lama, one__two=2.1)
assert test.one.two == 2.1
assert test.two != test.one.two
test = mixer.blend(lama, one__two=2.1, two=mixer.MIX.one.two)
assert test.two == test.one.two