當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。