How to use the mixer.main.Mixer function in mixer

To help you get started, we’ve selected a few mixer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klen / mixer / tests / test_main.py View on Github external
def test_skip():
    mixer = Mixer()
    test = mixer.blend(Test, one=mixer.SKIP)
    assert test.one is not mixer.SKIP
    assert test.one is int
github klen / mixer / tests / test_main.py View on Github external
def test_guard():
    mixer = Mixer()
    test = mixer.guard().blend(Test)
    assert test
github klen / mixer / tests / test_main.py View on Github external
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)
github klen / mixer / tests / test_main.py View on Github external
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'
github klen / mixer / tests / test_main.py View on Github external
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
github klen / mixer / tests / test_main.py View on Github external
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'
github klen / mixer / mixer / main.py View on Github external
"""
        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()
github klen / mixer / mixer / main.py View on Github external
    SELECT = property(lambda s: Mixer.SELECT)
    SKIP = property(lambda s: Mixer.SKIP)
github klen / mixer / mixer / main.py View on Github external
    SKIP = property(lambda s: Mixer.SKIP)