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


Python test_utils.mock函数代码示例

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


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

示例1: setUp

    def setUp(self):
        self.project = mock()
        self.fist_delegatee = mock()
        self.second_delegatee = mock()

        self.loader = DispatchingPluginLoader(
            mock, self.fist_delegatee, self.second_delegatee)
开发者ID:010110101001,项目名称:pybuilder,代码行数:7,代码来源:pluginloader_tests.py

示例2: test_ensure_after_action_teardown_is_executed_and_suppresses

    def test_ensure_after_action_teardown_is_executed_and_suppresses(self):
        task = mock(name="task", dependencies=[])
        when(task).execute(any(), {}).thenRaise(ValueError("simulated task error"))
        action_teardown1 = mock(name="action_teardown1", execute_before=[], execute_after=["task"], teardown=True,
                                source="task")
        when(action_teardown1).execute({}).thenRaise(ValueError("simulated action error teardown1"))
        action_teardown2 = mock(name="action_teardown2", execute_before=[], execute_after=["task"], teardown=True,
                                source="task")

        self.execution_manager.register_action(action_teardown1)
        self.execution_manager.register_action(action_teardown2)
        self.execution_manager.register_task(task)
        self.execution_manager.resolve_dependencies()

        try:
            self.execution_manager.execute_task(task)
            self.assertTrue(False, "should not have reached here")
        except Exception as e:
            self.assertEquals(type(e), ValueError)
            self.assertEquals(str(e), "simulated task error")

        verify(task).execute(any(), {})
        verify(action_teardown1).execute({})
        verify(action_teardown2).execute({})
        verify(self.execution_manager.logger).error(
            "Executing action '%s' from '%s' resulted in an error that was suppressed:\n%s", "action_teardown1",
            "task", any())
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:27,代码来源:execution_tests.py

示例3: test_should_collect_all_tasks_when_there_is_a_simple_dependency

    def test_should_collect_all_tasks_when_there_is_a_simple_dependency(self):
        one = mock(name="one", dependencies=[TaskDependency("two")])
        two = mock(name="two", dependencies=[])
        self.execution_manager.register_task(one, two)
        self.execution_manager.resolve_dependencies()

        self.assertEqual(self.execution_manager.collect_all_transitive_tasks(["one"]), set([one, two]))
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:7,代码来源:execution_tests.py

示例4: test_should_only_collect_required_tasks

    def test_should_only_collect_required_tasks(self):
        one = mock(name="one", dependencies=["three"])
        two = mock(name="two", dependencies=[])
        three = mock(name="three", dependencies=[])
        self.execution_manager.register_task(one, two, three)

        self.assertEqual(self.execution_manager.collect_all_transitive_tasks(["one"]), set([one, three]))
开发者ID:brendawong,项目名称:pybuilder,代码行数:7,代码来源:execution_tests.py

示例5: test_ensure_project_attributes_are_set_when_instantiating_project

    def test_ensure_project_attributes_are_set_when_instantiating_project(self):
        module = mock(
            version="version",
            default_task="default_task",
            summary="summary",
            home_page="home_page",
            description="description",
            authors="authors",
            license="license",
            url="url",
        )

        self.reactor.project = mock()
        self.reactor.project_module = module

        self.reactor.apply_project_attributes()

        self.assertEquals("version", self.reactor.project.version)
        self.assertEquals("default_task", self.reactor.project.default_task)
        self.assertEquals("summary", self.reactor.project.summary)
        self.assertEquals("home_page", self.reactor.project.home_page)
        self.assertEquals("description", self.reactor.project.description)
        self.assertEquals("authors", self.reactor.project.authors)
        self.assertEquals("license", self.reactor.project.license)
        self.assertEquals("url", self.reactor.project.url)
开发者ID:Vanuan,项目名称:pybuilder,代码行数:25,代码来源:reactor_tests.py

示例6: test_should_collect_all_tasks_when_several_tasks_given

    def test_should_collect_all_tasks_when_several_tasks_given(self):
        one = mock(name="one", dependencies=[], optional_dependencies=[])
        two = mock(name="two", dependencies=["three"])
        three = mock(name="three", dependencies=[], optional_dependencies=[])
        self.execution_manager.register_task(one, two, three)

        self.assertEqual(self.execution_manager.collect_all_transitive_tasks(["one", "two"]), set([one, two, three]))
开发者ID:jewishjeff,项目名称:pybuilder,代码行数:7,代码来源:execution_tests.py

示例7: test_ensure_after_action_teardown_suppression_works_when_action_fails

    def test_ensure_after_action_teardown_suppression_works_when_action_fails(self):
        task = mock(name="task", dependencies=[])
        action_regular = mock(name="action_regular", execute_before=[], execute_after=["task"], teardown=False)
        when(action_regular).execute({}).thenRaise(ValueError("simulated action error"))
        action_teardown = mock(name="action_teardown", execute_before=[], execute_after=["task"], teardown=True)
        action_after_teardown = mock(name="action_after_teardown", execute_before=[], execute_after=["task"],
                                     teardown=False)

        self.execution_manager.register_action(action_regular)
        self.execution_manager.register_action(action_teardown)
        self.execution_manager.register_action(action_after_teardown)
        self.execution_manager.register_task(task)
        self.execution_manager.resolve_dependencies()

        try:
            self.execution_manager.execute_task(task)
            self.assertTrue(False, "should not have reached here")
        except Exception as e:
            self.assertEquals(type(e), ValueError)
            self.assertEquals(str(e), "simulated action error")

        verify(task).execute(any(), {})
        verify(action_regular).execute({})
        verify(action_teardown).execute({})
        verify(action_after_teardown, times(0)).execute({})
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:25,代码来源:execution_tests.py

示例8: test_ensure_task_is_replaced_when_registering_two_tasks_with_same_name

    def test_ensure_task_is_replaced_when_registering_two_tasks_with_same_name(self):
        original = mock(name="spam")
        replacement = mock(name="spam")

        self.execution_manager.register_task(original)
        self.execution_manager.register_task(replacement)

        verify(original).extend(replacement)
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:8,代码来源:execution_tests.py

示例9: test_ensure_that_tasks_are_not_executed_multiple_times_when_being_dependencies

    def test_ensure_that_tasks_are_not_executed_multiple_times_when_being_dependencies(self):
        one = mock(name="one", dependencies=[])
        two = mock(name="two", dependencies=["one"])

        self.execution_manager.register_task(one, two)
        self.execution_manager.resolve_dependencies()

        self.assertEqual([one, two], self.execution_manager.build_execution_plan(["one", "two"]))
开发者ID:Vanuan,项目名称:pybuilder,代码行数:8,代码来源:execution_tests.py

示例10: test_ensure_that_dependencies_are_executed_before_root_task

    def test_ensure_that_dependencies_are_executed_before_root_task(self):
        one = mock(name="one", dependencies=[])
        two = mock(name="two", dependencies=["one"])

        self.execution_manager.register_task(one, two)
        self.execution_manager.resolve_dependencies()

        self.assertEqual([one, two], self.execution_manager.build_execution_plan(["two"]))
开发者ID:Vanuan,项目名称:pybuilder,代码行数:8,代码来源:execution_tests.py

示例11: test_should_return_execution_plan_with_two_tasks_when_two_tasks_are_to_be_executed

    def test_should_return_execution_plan_with_two_tasks_when_two_tasks_are_to_be_executed(self):
        one = mock(name="one", dependencies=[])
        two = mock(name="two", dependencies=[])

        self.execution_manager.register_task(one, two)
        self.execution_manager.resolve_dependencies()

        self.assertEqual([one, two], self.execution_manager.build_execution_plan(["one", "two"]))
开发者ID:Vanuan,项目名称:pybuilder,代码行数:8,代码来源:execution_tests.py

示例12: test_ensure_that_required_tasks_are_not_optionally_excluded

    def test_ensure_that_required_tasks_are_not_optionally_excluded(self):
        one = mock(name="one", dependencies=[])
        two = mock(name="two", dependencies=[TaskDependency("one")])

        self.execution_manager.register_task(one, two)
        self.execution_manager.resolve_dependencies(exclude_optional_tasks=["one"])

        self.assertRaises(RequiredTaskExclusionException, self.execution_manager.build_execution_plan, "two")
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:8,代码来源:execution_tests.py

示例13: test_ensure_project_name_is_set_from_attribute_when_instantiating_project

    def test_ensure_project_name_is_set_from_attribute_when_instantiating_project(self):
        module = mock(name="name")

        self.reactor.project = mock()
        self.reactor.project_module = module
        self.reactor.apply_project_attributes()

        self.assertEquals("name", self.reactor.project.name)
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:8,代码来源:reactor_tests.py

示例14: test_ensure_that_dependencies_are_resolved_when_simple_dependency_is_found

    def test_ensure_that_dependencies_are_resolved_when_simple_dependency_is_found(self):
        one = mock(name="one", dependencies=[])
        two = mock(name="two", dependencies=[TaskDependency("one")])

        self.execution_manager.register_task(one, two)
        self.execution_manager.resolve_dependencies()

        self.assertEquals([], self.execution_manager._task_dependencies.get("one"))
        self.assertEquals([TaskDependency(one)], self.execution_manager._task_dependencies.get("two"))
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:9,代码来源:execution_tests.py

示例15: test_ignore_second_required_dependency

    def test_ignore_second_required_dependency(self):
        one = mock(name="one", dependencies=[])
        two = mock(name="two", dependencies=[TaskDependency("one"), TaskDependency("one")])

        self.execution_manager.register_task(one, two)
        self.execution_manager.resolve_dependencies()

        self.assertEquals([], self.execution_manager._task_dependencies.get("one"))
        self.assertEquals([TaskDependency(one)], self.execution_manager._task_dependencies.get("two"))
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:9,代码来源:execution_tests.py


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