Ejemplo n.º 1
0
    def test_ensure_after_action_teardown_is_executed_when_action_fails(self):
        task = Mock(name="task", dependencies=[])
        action_regular = Mock(name="action_regular",
                              execute_before=[],
                              execute_after=["task"],
                              teardown=False)
        action_regular.name = "action_regular"
        action_regular.execute.side_effect = 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.assertEqual(type(e), ValueError)
            self.assertEqual(str(e), "simulated action error")

        task.execute.assert_called_with(ANY, {}, _executable=None)
        action_regular.execute.assert_called_with({})
        action_teardown.execute.assert_called_with({})
        action_after_teardown.execute.assert_not_called()
Ejemplo n.º 2
0
    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)
        action_regular.name = "action_regular"
        action_regular.execute.side_effect = 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.assertEqual(type(e), ValueError)
            self.assertEqual(str(e), "simulated action error")

        task.execute.assert_called_with(ANY, {})
        action_regular.execute.assert_called_with({})
        action_teardown.execute.assert_called_with({})
        action_after_teardown.execute.assert_not_called()
    def test_should_return_project_property_when_property_is_defined(self):
        project_mock = Mock(Project)
        project_mock.name = "my name"

        self.assertEquals("my name", ProjectDictWrapper(project_mock, Mock())["name"])

        project_mock.get_property.assert_not_called()
    def test_should_return_project_property_when_property_is_defined(self):
        project_mock = Mock(Project)
        project_mock.name = "my name"

        self.assertEqual("my name", ProjectDictWrapper(project_mock, Mock())["name"])

        project_mock.get_property.assert_not_called()