当前位置: 首页>>代码示例>>Python>>正文


Python Mock.__name__方法代码示例

本文整理汇总了Python中unittest.mock.Mock.__name__方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.__name__方法的具体用法?Python Mock.__name__怎么用?Python Mock.__name__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.Mock的用法示例。


在下文中一共展示了Mock.__name__方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_run_task

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def test_run_task(self):
        target = Mock(name='Test')
        target.__name__ = 'Test'

        #Add one task
        self.sched.enter(10, 1, target)
        self.sched.enter_task(0)

        #check time that is scheduled
        scheduled_time = self.sched.queue[0].time
        #Remove from queu (emulate that its called from the scheduler)
        self.sched._queue.pop()
        #Advance time
        self.time.current_time += 20

        #Run task
        self.sched.run_task(0)

        #Check that its called
        self.assertEqual(target.call_count, 1)

        #Check that its rescheduled
        self.assertEqual(len(self.sched._queue), 1)
        self.assertNotEqual(self.sched.queue[0].time, scheduled_time)
        self.assertEqual(tuple(self.sched.queue[0]), (self.time.current_time+10, 1, self.sched.run_task, (0,), {}))
开发者ID:buluba89,项目名称:Yatcobot,代码行数:27,代码来源:test_scheduler.py

示例2: test_framework_hooks

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
def test_framework_hooks():
    test_hook = Mock(return_value='bogus')
    test_hook.__name__ = 'bogusname'
    test_hook_again = Mock(return_value='fake')
    test_hook_again.__name__ = 'bogusname'

    class MyApp(TestApp):
        class Meta:
            hooks = [
                ('pre_setup', test_hook),
                ('post_setup', test_hook),
                ('pre_run', test_hook),
                ('post_run', test_hook),
                ('pre_argument_parsing', test_hook),
                ('post_argument_parsing', test_hook),
                ('pre_close', test_hook),
                ('post_close', test_hook),
                ('signal', test_hook),
                ('pre_render', test_hook),
                ('pre_render', test_hook_again),
                ('post_render', test_hook),
                ('post_render', test_hook),
            ]

    with MyApp() as app:
        # Pre- and post- setup
        assert test_hook.call_count == 2
        test_hook.reset_mock()

        # Pre/post run (+ pre/post argparse)
        # App has no controller, so it also parses args here
        app.run()
        assert test_hook.call_count == 4
        test_hook.reset_mock()

        # pre/post render
        # two hooks each, one is test_hook_again
        app.render({1: 'bogus'})
        assert test_hook.call_count == 3
        assert test_hook_again.call_count == 1
        test_hook.reset_mock()
        test_hook_again.reset_mock()

        # TODO: Test that signal hook gets called properly

    # pre/post close
    assert test_hook.call_count == 2
开发者ID:datafolklabs,项目名称:cement,代码行数:49,代码来源:test_hook.py

示例3: test_get_module_name_alternate

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
 def test_get_module_name_alternate(self):
     """
     Should get the module name from its dunder name if the spec name
     does not exist.
     """
     target = Mock(['__name__'])
     target.__name__ = 'hello'
     self.assertEqual('hello', reloading.get_module_name(target))
开发者ID:sernst,项目名称:cauldron,代码行数:10,代码来源:test_session_reloading.py

示例4: test_multiple_ignored

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
 def test_multiple_ignored(self):
     cb = Mock()
     cb.__name__ = 'something'
     old = len(amo_models._on_change_callbacks[Addon])
     Addon.on_change(cb)
     assert len(amo_models._on_change_callbacks[Addon]) == old + 1
     Addon.on_change(cb)
     assert len(amo_models._on_change_callbacks[Addon]) == old + 1
开发者ID:diox,项目名称:olympia,代码行数:10,代码来源:test_models.py

示例5: test_pre_render_hook

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
def test_pre_render_hook():
    bogus_hook = Mock(wraps=pre_render_hook)
    bogus_hook.__name__ = 'bogus_hook'
    bogus_hook.__module__ = 'bogus_hooks'

    with TestApp() as app:
        app.hook.register('pre_render', bogus_hook)
        app.run()
        app.render({})
        assert bogus_hook.called
开发者ID:datafolklabs,项目名称:cement,代码行数:12,代码来源:test_foundation.py

示例6: test_enter_task

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def test_enter_task(self):
        target = Mock(name='Test')
        target.__name__ = 'Test'

        #Add one task
        self.sched.enter(10, 1, target)

        self.sched.enter_task(0)

        self.assertEqual(len(self.sched.queue), 1)
        self.assertEqual(tuple(self.sched.queue[0]), (self.time.current_time+10, 1, self.sched.run_task, (0,), {}))
开发者ID:buluba89,项目名称:Yatcobot,代码行数:13,代码来源:test_scheduler.py

示例7: test_depaginator_works_with_non_paginating_results_and_warns

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
def test_depaginator_works_with_non_paginating_results_and_warns():
    fetcher = Mock()
    fetcher.side_effect = [result['results']]
    fetcher.__name__ = 'test_fetcher'
    with patch('drf_depaginator.logger') as paginator_logger:
        paginator = iter(AutoDepaginator(fetcher))
        response = list(paginator)
        assert len(response) == 2
        assert response == result['results']
        assert any(str(call).startswith('call.warning') for call in paginator_logger.mock_calls), \
            'AutoDepaginator did not log warning about non-compliant API return'
开发者ID:jsbueno,项目名称:drf_depaginator,代码行数:13,代码来源:test_depaginator.py

示例8: test_enter

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def test_enter(self):
        target = Mock(name='Test')
        target.__name__ = 'Test'
        #Add one task
        self.sched.enter(10, 1, target)
        self.assertEqual(len(self.sched.tasks), 1)
        self.assertEqual(self.sched.tasks[0], (10, 1, target))

        #Add a second task
        self.sched.enter(10, 1, target)
        self.assertEqual(len(self.sched.tasks), 2)
        self.assertEqual(self.sched.tasks[1], (10, 1, target))
开发者ID:buluba89,项目名称:Yatcobot,代码行数:14,代码来源:test_scheduler.py

示例9: test_enter_task_random

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def test_enter_task_random(self):
        target = Mock(name='Test')
        target.__name__ = 'Test'

        #Add one task
        self.sched.enter_random(10, 5, 1, target)

        self.sched.enter_task(0)

        self.assertEqual(len(self.sched.queue), 1)
        self.assertGreaterEqual(self.sched.queue[0].time, self.time.current_time+10-5)
        self.assertLessEqual(self.sched.queue[0].time, self.time.current_time+10+5)
        self.assertEqual(self.sched.queue[0].action, self.sched.run_task)
开发者ID:buluba89,项目名称:Yatcobot,代码行数:15,代码来源:test_scheduler.py

示例10: get_fe

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def get_fe(self, n):
        m = Mock()
        m.i = 0
        m.running = True
        def start():
            while m.running:
                m.i += 1

        def stop():
            m.running = False

        m.__name__ = n
        m.loop = start
        m.stop = stop
        return m
开发者ID:wonkodv,项目名称:hanstool,代码行数:17,代码来源:test_lib.py

示例11: test_full_run

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def test_full_run(self, importMock):

        fe1 = self.get_fe('fe1')
        fe2 = self.get_fe('fe2')

        fe3 = Mock()
        fe3.stop = lambda:None
        fe3.loop = lambda:time.sleep(0.1)
        fe3.__name__ = 'fe3'

        importMock.side_effect = [fe1, fe2, fe3]

        lib.load_frontend('frontend1')
        lib.load_frontend('frontend2')
        lib.load_frontend('frontend3')

        lib.run_frontends()

        self.assertGreater(fe1.i, 100)
        self.assertGreater(fe2.i, 100)
开发者ID:wonkodv,项目名称:hanstool,代码行数:22,代码来源:test_lib.py

示例12: test_run

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def test_run(self):

        targets = list()
        for i in range(10):
            target = Mock(name='Test')
            target.__name__ = 'Test'
            targets.append(target)

        for t in targets:
            self.sched.enter(10, 1, t)

        #advance clock
        self.time.current_time += 10

        self.sched.run(blocking=False)

        # Test if all targets run
        for t in targets:
            self.assertEqual(t.call_count, 1)

        # Test if rescheduled
        self.assertEqual(len(self.sched.queue), 10)
        for i in range(10):
            self.assertEqual(self.sched.queue[i].time, 20)
开发者ID:buluba89,项目名称:Yatcobot,代码行数:26,代码来源:test_scheduler.py

示例13: test__name__

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
    def test__name__(self):
        mock = Mock()
        self.assertRaises(AttributeError, lambda: mock.__name__)

        mock.__name__ = 'foo'
        self.assertEqual(mock.__name__, 'foo')
开发者ID:MarkTseng,项目名称:cpython,代码行数:8,代码来源:testmock.py

示例14: test_deprecated_decorator

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import __name__ [as 别名]
 def test_deprecated_decorator(self):
     mock_func = Mock()
     mock_func.__name__ = 'foo'
     decorated_func = deprecated(mock_func)
     with self.assertWarns(DeprecationWarning):
         decorated_func()
开发者ID:uclouvain,项目名称:osis-common,代码行数:8,代码来源:test_deprecated.py


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