def expect_args_kwargs_passed_to_exec_func(): exec_func_mock = Mock() subject = Task('foo', TaskType.JOB, exec_func_mock) exp_args = ['hello', 'world'] exp_kwargs = {'foo': 'bar'} subject.execute(*exp_args, **exp_kwargs) exec_func_mock.assert_called_once_with(*exp_args, **exp_kwargs)
def records_timing_of_the_task_execution(): parent_mock = Mock() parent_mock.time = Mock() parent_mock.time.side_effect = [1, 5] parent_mock.exec_func = Mock() subject = Task('foo', TaskType.JOB, parent_mock.exec_func, tm=parent_mock.time) subject.execute() parent_mock.assert_has_calls([call.time(), call.exec_func(), call.time()]) assert_that(subject.runtime).is_equal_to(4)
def __init__(self, name, images, tasks, clone=True, env=None, build=None, after_failure=None, finally_task=None): super(Job, self).__init__(name) self.logger = get_logger(__name__) if type(images) is not list: images = [images] self.images = images if type(tasks) is not list: tasks = [tasks] self.tasks = [] for task in tasks: self.tasks.append(Task(task)) self.clone = clone self.env = env self.build = build self.after_failure = after_failure self.finally_task = finally_task
def records_timing_of_the_task_execution(): parent_mock = Mock() parent_mock.time = Mock() parent_mock.time.side_effect = [1, 5] parent_mock.exec_func = Mock() subject = Task('foo', TaskType.JOB, parent_mock.exec_func, tm=parent_mock.time) subject.execute() parent_mock.assert_has_calls( [call.time(), call.exec_func(), call.time()]) assert_that(subject.runtime).is_equal_to(4)
def raises_error(): with pytest.raises(ValueError) as excinfo: Task('foo', TaskType.JOB, 'foo') assert_that(str( excinfo.value)).is_equal_to('exec_func must be a callable')
def raises_error(): with pytest.raises(ValueError) as excinfo: Task(None, 'mytype', dummy_func) assert_that(str( excinfo.value)).is_equal_to('tasks must have a name')
def sets_name_property(): subject = Task('test', TaskType.JOB, dummy_func) assert_that(subject.name).is_equal_to('test')
def raises_error(): with pytest.raises(ValueError) as excinfo: Task('foo', 'mytype', dummy_func) assert_that(str(excinfo.value)).is_equal_to( 'task_type must be of type TaskType')
def sets_task_type_property(): subject = Task('test', TaskType.JOB, dummy_func) assert_that(subject.task_type).is_equal_to(TaskType.JOB)