def test_getargs_ok(self, reporter, dep_manager): def ok(): return {'x': 1} def check_x(my_x): return my_x == 1 t1 = Task('t1', [(ok, )]) n1 = ExecNode(t1, None) t2 = Task('t2', [(check_x, )], getargs={'my_x': ('t1', 'x')}) n2 = ExecNode(t2, None) tasks_dict = {'t1': t1, 't2': t2} my_runner = runner.Runner(dep_manager, reporter) # t2 gives chance for setup tasks to be executed assert False == my_runner.select_task(n2, tasks_dict) assert ('start', t2) == reporter.log.pop(0) # execute task t1 to calculate value assert True == my_runner.select_task(n1, tasks_dict) assert ('start', t1) == reporter.log.pop(0) t1_result = my_runner.execute_task(t1) assert ('execute', t1) == reporter.log.pop(0) my_runner.process_task_result(n1, t1_result) assert ('success', t1) == reporter.log.pop(0) # t2.options are set on select_task assert True == my_runner.select_task(n2, tasks_dict) assert not reporter.log assert {'my_x': 1} == t2.options
def test_parent_status_ignore(self): n1 = ExecNode(Task('t1', None), None) n2 = ExecNode(Task('t2', None), None) n1.run_status = 'ignore' n2.parent_status(n1) assert [] == n2.bad_deps assert [n1] == n2.ignored_deps
def test_getargs_fail(self, reporter, dep_manager): # invalid getargs. Exception wil be raised and task will fail def check_x(my_x): return True t1 = Task('t1', [lambda: True]) n1 = ExecNode(t1, None) t2 = Task('t2', [(check_x, )], getargs={'my_x': ('t1', 'x')}) n2 = ExecNode(t2, None) tasks_dict = {'t1': t1, 't2': t2} my_runner = runner.Runner(dep_manager, reporter) # t2 gives chance for setup tasks to be executed assert False == my_runner.select_task(n2, tasks_dict) assert ('start', t2) == reporter.log.pop(0) # execute task t1 to calculate value assert True == my_runner.select_task(n1, tasks_dict) assert ('start', t1) == reporter.log.pop(0) t1_result = my_runner.execute_task(t1) assert ('execute', t1) == reporter.log.pop(0) my_runner.process_task_result(n1, t1_result) assert ('success', t1) == reporter.log.pop(0) # select_task t2 fails assert False == my_runner.select_task(n2, tasks_dict) assert ('fail', t2) == reporter.log.pop(0) assert not reporter.log
def test_step(self): def my_gen(): yield 1 yield 2 task = Task("t1", None) node = ExecNode(task, None) node.generator = my_gen() assert 1 == node.step() assert 2 == node.step() assert None == node.step()
def test_DependencyError(self, reporter, dep_manager): t1 = Task("taskX", [(my_print, ["out a"])], file_dep=["i_dont_exist"]) my_runner = runner.Runner(dep_manager, reporter) assert False == my_runner.select_task(ExecNode(t1, None), {}) assert ('start', t1) == reporter.log.pop(0) assert ('fail', t1) == reporter.log.pop(0) assert not reporter.log
def test_alwaysExecute(self, reporter, dep_manager): t1 = Task("taskX", [(my_print, ["out a"])]) my_runner = runner.Runner(dep_manager, reporter, always_execute=True) my_runner.dep_manager.save_success(t1) assert True == my_runner.select_task(ExecNode(t1, None), {}) assert ('start', t1) == reporter.log.pop(0) assert not reporter.log
def test_upToDate(self, reporter, dep_manager): t1 = Task("taskX", [(my_print, ["out a"])], file_dep=[__file__]) my_runner = runner.Runner(dep_manager, reporter) my_runner.dep_manager.save_success(t1) assert False == my_runner.select_task(ExecNode(t1, None), {}) assert ('start', t1) == reporter.log.pop(0) assert ('up-to-date', t1) == reporter.log.pop(0) assert not reporter.log
def test_ignore(self, reporter, dep_manager): t1 = Task("taskX", [(my_print, ["out a"])]) my_runner = runner.Runner(dep_manager, reporter) my_runner.dep_manager.ignore(t1) assert False == my_runner.select_task(ExecNode(t1, None), {}) assert ('start', t1) == reporter.log.pop(0) assert ('ignore', t1) == reporter.log.pop(0) assert not reporter.log
def test_alwaysExecute(self, reporter, dep_manager): t1 = Task("taskX", [(my_print, ["out a"])], uptodate=[True]) my_runner = runner.Runner(dep_manager, reporter, always_execute=True) my_runner.dep_manager.save_success(t1) n1 = ExecNode(t1, None) assert True == my_runner.select_task(n1, {}) # run_status is set to run even if task is up-to-date assert n1.run_status == 'run' assert ('start', t1) == reporter.log.pop(0) assert not reporter.log
def test_withSetup(self, reporter, dep_manager): t1 = Task("taskX", [(my_print, ["out a"])], setup=["taskY"]) my_runner = runner.Runner(dep_manager, reporter) # defer execution n1 = ExecNode(t1, None) assert False == my_runner.select_task(n1, {}) assert ('start', t1) == reporter.log.pop(0) assert not reporter.log # trying to select again assert True == my_runner.select_task(n1, {}) assert not reporter.log
def test_getargs_dict(self, reporter, dep_manager): def ok(): return {'x':1} t1 = Task('t1', [(ok,)]) n1 = ExecNode(t1, None) t2 = Task('t2', None, getargs={'my_x':('t1', None)}) tasks_dict = {'t1': t1, 't2':t2} my_runner = runner.Runner(dep_manager, reporter) t1_result = my_runner.execute_task(t1) my_runner.process_task_result(n1, t1_result) # t2.options are set on _get_task_args my_runner._get_task_args(t2, tasks_dict) assert {'my_x': {'x':1}} == t2.options
def test_getargs_group_value(self, reporter, dep_manager): def ok(): return {'x':1} t1 = Task('t1', None, task_dep=['t1:a'], has_subtask=True) t1a = Task('t1:a', [(ok,)], subtask_of='t1') t2 = Task('t2', None, getargs={'my_x':('t1', 'x')}) tasks_dict = {'t1': t1, 't1a':t1a, 't2':t2} my_runner = runner.Runner(dep_manager, reporter) t1a_result = my_runner.execute_task(t1a) my_runner.process_task_result(ExecNode(t1a, None), t1a_result) # t2.options are set on _get_task_args my_runner._get_task_args(t2, tasks_dict) assert {'my_x': {'a':1} } == t2.options
def test_getargs_group(self, reporter, depfile_name): def ok(): return {'x': 1} t1 = Task('t1', None, task_dep=['t1:a'], has_subtask=True) t1a = Task('t1:a', [(ok, )], is_subtask=True) t2 = Task('t2', None, getargs={'my_x': ('t1', None)}) tasks_dict = {'t1': t1, 't1a': t1a, 't2': t2} my_runner = runner.Runner(Dependency, depfile_name, reporter) t1a_result = my_runner.execute_task(t1a) my_runner.process_task_result(ExecNode(t1a, None), t1a_result) # t2.options are set on _get_task_args assert {} == t2.options my_runner._get_task_args(t2, tasks_dict) assert {'my_x': {'a': {'x': 1}}} == t2.options
def test_ready_select__not_waiting(self): task = Task("t1", None) node = ExecNode(task, None) assert False == node.wait_select
def test_repr(self): node = ExecNode(Task('t1', None), None) assert 't1' in repr(node)
def test_noSetup_ok(self, reporter, dep_manager): t1 = Task("taskX", [(my_print, ["out a"])]) my_runner = runner.Runner(dep_manager, reporter) assert True == my_runner.select_task(ExecNode(t1, None), {}) assert ('start', t1) == reporter.log.pop(0) assert not reporter.log
def test_ready(self, reporter, depfile_name): t1 = Task("taskX", [(my_print, ["out a"])]) my_runner = runner.Runner(Dependency, depfile_name, reporter) assert True == my_runner.select_task(ExecNode(t1, None), {}) assert ('start', t1) == reporter.log.pop(0) assert not reporter.log