• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mixer.blend函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mixer.main.mixer.blend函数的典型用法代码示例。如果您正苦于以下问题:Python blend函数的具体用法?Python blend怎么用?Python blend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了blend函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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")
开发者ID:imbaczek,项目名称:mixer,代码行数:26,代码来源:test_main.py


示例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')
开发者ID:checko,项目名称:mixer,代码行数:7,代码来源:test_main.py


示例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"
开发者ID:klen,项目名称:mixer,代码行数:28,代码来源:test_main.py


示例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))
开发者ID:imbaczek,项目名称:mixer,代码行数:9,代码来源:test_main.py


示例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)
开发者ID:klen,项目名称:mixer,代码行数:9,代码来源:test_main.py


示例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)
开发者ID:imbaczek,项目名称:mixer,代码行数:10,代码来源:test_main.py


示例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')
开发者ID:erm0l0v,项目名称:mixer,代码行数:31,代码来源:test_main.py


示例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
开发者ID:DmitriyMoseev,项目名称:mixer,代码行数:11,代码来源:test_main.py


示例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)
开发者ID:DmitriyMoseev,项目名称:mixer,代码行数:12,代码来源:test_main.py


示例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
开发者ID:klen,项目名称:mixer,代码行数:13,代码来源:test_main.py


示例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)
开发者ID:imbaczek,项目名称:mixer,代码行数:15,代码来源:test_main.py


示例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)
开发者ID:imbaczek,项目名称:mixer,代码行数:15,代码来源:test_main.py


示例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)
开发者ID:checko,项目名称:mixer,代码行数:15,代码来源:test_main.py


示例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
开发者ID:klen,项目名称:mixer,代码行数:15,代码来源:test_main.py


示例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
开发者ID:klen,项目名称:mixer,代码行数:16,代码来源:test_main.py


示例16: generate

    def generate(self, num_events=60, num_days=45):
        from orders_manager.models import Order
        from mixer.main import mixer
        import json

        class Scheme:
            address_details = str
            details = str
            executor_comment = str

        orders_list = []

        while len(orders_list) < num_events:

            data = mixer.blend(Scheme)

            common_gen = CommonDataGenerator()

            client_id = self._get_client_id()
            program_id = self._get_program_id()
            program_duration = self._get_program_duration(program_id)
            program_price = self._get_program_price(program_id,
                                                    program_duration)
            additional_services_ids = self._get_additional_serveces_ids()

            address = common_gen.generate_address()
            address.update({
                'details': data.address_details
            })

            order_info = {
                'author_id': self._get_author_id(),
                'client_id': client_id,
                'client_children_id': self._get_client_children_ids(client_id),
                'children_num': self._get_children_num(),
                'celebrate_date': common_gen.generate_date_in_future(
                    num_days_for_start=-7, num_days_for_end=num_days),
                'celebrate_time': common_gen.generate_time(),
                'celebrate_place': self._get_celebrate_place(),
                'address': json.dumps(address),
                'program_id': program_id,
                'program_executors_id': self._get_program_executors_ids(
                    program_id),
                'duration': program_duration,
                'services_executors': self._get_services_to_executors(
                    additional_services_ids),
                'discount_id': self._get_discount(),
                'details': data.details,
                'executor_comment': data.executor_comment,
                'where_was_found': self._get_where_was_found(),
                'cost_of_the_way': self._get_cost_of_the_way(),
                'price': program_price,
                'total_price': program_price,
                'total_price_with_discounts': program_price
            }
            orders_list.append(Order.objects.create(**order_info))

        return orders_list
开发者ID:Ra3bOjN1K,项目名称:order_manager,代码行数:58,代码来源:generate_data_helper.py


示例17: test_reload

def test_reload():
    mixer = Mixer()
    test = mixer.blend(Test)
    test2 = mixer.reload(test)
    assert test is not test2
    assert test.name == test2.name

    test3, test4 = mixer.reload(test, test2)
    assert test3 and test4
开发者ID:klen,项目名称:mixer,代码行数:9,代码来源:test_main.py


示例18: test_mixer

    def test_mixer(self):
        mixer = Mixer()

        self.assertEqual(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)
        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')
开发者ID:imbaczek,项目名称:mixer,代码行数:43,代码来源:test_main.py


示例19: test_mixer

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'

    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)
    assert test.name == 'test2'

    name_gen = mixer.sequence('test{0}')
    test = mixer.blend(Test, name=name_gen)
    test = mixer.blend(Test, name=name_gen)
    assert test.name == 'test1'

    name_gen = mixer.sequence()
    test = mixer.blend(Test, name=name_gen)
    test = mixer.blend(Test, name=name_gen)
    assert test.name == 1

    mixer.register('tests.test_main.Test',
                   name='Michel', one=lambda: 'ID', unknown="No error here")
    test = mixer.blend(Test)
    assert test.one == 'ID'
    assert test.name == 'Michel'
开发者ID:klen,项目名称:mixer,代码行数:40,代码来源:test_main.py


示例20: setUp

 def setUp(self):
     super(ApiAddNodesToTreeTestCase, self).setUp()
     # get our random data from mixer
     random_data = mixer.blend(SampleContentNodeDataSchema)
     self.root_node = tree()
     self.fileobj = fileobj_video()
     self.title = random_data.title
     sample_data = {
         "root_id": self.root_node.id,
         "content_data": [
             {
                 "title": self.title,
                 "language": "en",
                 "description": random_data.description,
                 "node_id": random_data.node_id,
                 "content_id": random_data.content_id,
                 "source_domain": random_data.source_domain,
                 "source_id": random_data.source_id,
                 "author": random_data.author,
                 "files": [
                     {
                         "size": self.fileobj.file_size,
                         "preset": "video",
                         "filename": self.fileobj.filename(),
                         "original_filename": self.fileobj.original_filename,
                         "language": self.fileobj.language,
                         "source_url": self.fileobj.source_url
                     }
                 ],
                 "kind": "document",
                 "license": "CC BY",
                 "license_description": None,
                 "copyright_holder": random_data.copyright_holder,
                 "questions": [],
                 "extra_fields": "{}",
                 "role": "learner"
             }
         ]
     }
     self.resp = self.admin_client().post(
         "/api/internal/add_nodes",
         data=sample_data,
         format='json'
     )
开发者ID:fle-internal,项目名称:content-curation,代码行数:44,代码来源:test_views_internal.py



注:本文中的mixer.main.mixer.blend函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mixer_saffire_base.SaffireMixerBase类代码示例发布时间:2022-05-27
下一篇:
Python mixer.cycle函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap