fmartingr
/
jeeves
Archived
1
0
Fork 0
This repository has been archived on 2021-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
jeeves/jeeves/core/tests/test_executor.py

55 lines
1.9 KiB
Python

import os.path
from unittest import mock
from jeeves.core.executor import Executor
from jeeves.core.tests.factories import FlowFactory, TaskFactory
def test_executor_success_task_ok():
task = TaskFactory(type="jeeves.core.actions.stub:StubSuccessAction")
flow = FlowFactory(tasks=[task])
runner = Executor(flow)
runner.start()
assert runner._execution.steps[0].result
assert runner._execution.steps[0].result.success is True
assert runner._execution.success is True
def test_executor_non_success_task_ok():
task = TaskFactory(type="jeeves.core.actions.stub:StubNonSuccessAction")
flow = FlowFactory(tasks=[task])
runner = Executor(flow)
runner.start()
assert runner._execution.steps[0].result
assert runner._execution.steps[0].result.success is False
assert runner._execution.success is False
def test_executor_uncaught_exception_in_task_ok():
task = TaskFactory(type="jeeves.core.actions.stub:StubUncaughtExceptionAction")
flow = FlowFactory(tasks=[task])
runner = Executor(flow)
runner.start()
assert runner._execution.steps[0].result
assert runner._execution.steps[0].result.success is False
assert runner._execution.success is False
@mock.patch("jeeves.core.actions.stub.StubSuccessAction.execute")
def test_executor_run_action_with_workpsace_ok(execute_mock):
task = TaskFactory(type="jeeves.core.actions.stub:StubSuccessAction")
flow = FlowFactory(tasks=[task])
runner = Executor(flow)
runner.start()
assert execute_mock.called
execute_mock.assert_called_with(workspace=runner._execution.workspace)
def test_executor_cleans_workspace_after_ok():
task = TaskFactory(type="jeeves.core.actions.stub:StubSuccessAction")
flow = FlowFactory(tasks=[task])
runner = Executor(flow)
path = runner._execution.workspace.path
runner.start()
assert not os.path.isdir(path)