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


Python Reactor.get_tasks方法代码示例

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


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

示例1: ReactorTest

# 需要导入模块: from pybuilder.reactor import Reactor [as 别名]
# 或者: from pybuilder.reactor.Reactor import get_tasks [as 别名]
class ReactorTest(unittest.TestCase):
    def setUp(self):
        self.plugin_loader_mock = mock(PluginLoader)
        self.logger = mock()
        self.execution_manager = mock(ExecutionManager)
        self.reactor = Reactor(
            self.logger, self.execution_manager, self.plugin_loader_mock)

    def tearDown(self):
        unstub()

    def test_should_return_tasks_from_execution_manager_when_calling_get_tasks(self):
        self.execution_manager.tasks = ["spam"]
        self.assertEquals(["spam"], self.reactor.get_tasks())

    def test_should_raise_exception_when_importing_plugin_and_plugin_not_found(self):
        when(self.plugin_loader_mock).load_plugin(
            any(), "not_found", any(), any()).thenRaise(MissingPluginException("not_found"))

        self.assertRaises(
            MissingPluginException, self.reactor.import_plugin, "not_found")

        verify(self.plugin_loader_mock).load_plugin(any(), "not_found", None, None)

    def test_should_collect_single_task(self):
        def task():
            pass

        setattr(task, TASK_ATTRIBUTE, True)

        module = mock()
        module.task = task

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        verify(self.execution_manager).register_task(TaskNameMatcher("task"))

    def test_should_collect_single_task_with_overridden_name(self):
        def task():
            pass

        setattr(task, TASK_ATTRIBUTE, True)
        setattr(task, NAME_ATTRIBUTE, "overridden_name")

        module = mock()
        module.task = task

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        verify(self.execution_manager).register_task(
            TaskNameMatcher("overridden_name"))

    def test_should_collect_multiple_tasks(self):
        def task():
            pass

        setattr(task, TASK_ATTRIBUTE, True)

        def task2():
            pass

        setattr(task2, TASK_ATTRIBUTE, True)

        module = mock()
        module.task = task
        module.task2 = task2

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        verify(self.execution_manager, times(2)).register_task(any(Task))

    def test_task_dependencies(self):
        import pybuilder.reactor

        when(pybuilder.reactor).Task().thenReturn(mock())

        @task
        def task1():
            pass

        @task
        @depends(task1)
        def task2():
            pass

        @task
        def task3():
            pass

        @task
        @depends(optional(task3))
        @dependents("task6")
        def task4():
            pass

        @task
        @dependents("task6", optional(task3))
        def task5():
            pass

#.........这里部分代码省略.........
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:103,代码来源:reactor_tests.py

示例2: ReactorTest

# 需要导入模块: from pybuilder.reactor import Reactor [as 别名]
# 或者: from pybuilder.reactor.Reactor import get_tasks [as 别名]
class ReactorTest(unittest.TestCase):
    def setUp(self):
        self.old_reactor = Reactor.current_instance()
        self.plugin_loader_mock = Mock(PluginLoader)
        self.logger = Mock()
        self.execution_manager = Mock(ExecutionManager)
        self.reactor = Reactor(
            self.logger, self.execution_manager, self.plugin_loader_mock)

    def tearDown(self):
        Reactor._set_current_instance(self.old_reactor)

    def test_should_return_tasks_from_execution_manager_when_calling_get_tasks(self):
        self.execution_manager.tasks = ["spam"]
        self.assertEquals(["spam"], self.reactor.get_tasks())

    def test_should_raise_exception_when_importing_plugin_and_plugin_not_found(self):
        self.plugin_loader_mock.load_plugin.side_effect = MissingPluginException("not_found")

        self.assertRaises(
            MissingPluginException, self.reactor.import_plugin, "not_found")

        self.plugin_loader_mock.load_plugin.assert_called_with(ANY, "not_found", None, None)

    def test_should_collect_single_task(self):
        def task():
            pass

        setattr(task, TASK_ATTRIBUTE, True)

        module = ModuleType("mock_module")
        module.task = task

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        self.assertEquals(len(self.execution_manager.register_task.call_args_list), 1)
        self.assertTrue(isinstance(self.execution_manager.register_task.call_args[0][0], Task) and len(
            self.execution_manager.register_task.call_args[0]) == 1)
        self.assertEquals(self.execution_manager.register_task.call_args[0][0].name, "task")

    def test_should_collect_single_task_with_overridden_name(self):
        def task():
            pass

        setattr(task, TASK_ATTRIBUTE, True)
        setattr(task, NAME_ATTRIBUTE, "overridden_name")

        module = ModuleType("mock_module")
        module.task = task

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        self.assertEquals(len(self.execution_manager.register_task.call_args_list), 1)
        self.assertTrue(isinstance(self.execution_manager.register_task.call_args[0][0], Task) and len(
            self.execution_manager.register_task.call_args[0]) == 1)
        self.assertEquals(self.execution_manager.register_task.call_args[0][0].name, "overridden_name")

    def test_should_collect_multiple_tasks(self):
        def task():
            pass

        setattr(task, TASK_ATTRIBUTE, True)

        def task2():
            pass

        setattr(task2, TASK_ATTRIBUTE, True)

        module = ModuleType("mock_module")
        module.task = task
        module.task2 = task2

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        self.assertEquals(len(self.execution_manager.register_task.call_args_list), 2)
        for call_args in self.execution_manager.register_task.call_args_list:
            self.assertTrue(isinstance(call_args[0][0], Task) and len(call_args[0]) == 1)

    def test_task_dependencies(self):
        import pybuilder.reactor

        with patch("pybuilder.reactor.Task"):
            @task
            def task1():
                pass

            @task
            @depends(task1)
            def task2():
                pass

            @task
            def task3():
                pass

            @task
            @depends(optional(task3))
            @dependents("task6")
            def task4():
                pass
#.........这里部分代码省略.........
开发者ID:wenlien,项目名称:pybuilder,代码行数:103,代码来源:reactor_tests.py


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