本文整理汇总了Python中doit.control.TaskControl类的典型用法代码示例。如果您正苦于以下问题:Python TaskControl类的具体用法?Python TaskControl怎么用?Python TaskControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDetectCyclicReference
def testDetectCyclicReference(self):
tasks = [Task("taskX",None,task_dep=["taskY"]),
Task("taskY",None,task_dep=["taskX"])]
tc = TaskControl(tasks)
tc.process(None)
gen = tc._add_task(0, "taskX", False)
py.test.raises(InvalidDodoFile, gen.next)
示例2: testSystemExitRaises
def testSystemExitRaises(self, reporter, RunnerClass, depfile):
t1 = Task("x", [_exit])
my_runner = RunnerClass(depfile.name, reporter)
tc = TaskControl([t1])
tc.process(None)
pytest.raises(SystemExit, my_runner.run_tasks, tc)
my_runner.finish()
示例3: testPosParam
def testPosParam(self):
tasks = list(TASKS_SAMPLE)
tasks.append(Task("tP", [""],[],[], pos_arg='myp'))
tc = TaskControl(tasks)
args = ["tP", "hello option!", "t1"]
assert ['tP',] == tc._filter_tasks(args)
assert ["hello option!", "t1"] == tc.tasks['tP'].pos_arg_val
示例4: doit_auto
def doit_auto(dependency_file, task_list, filter_tasks, loop_callback=None):
"""Re-execute tasks automatically a depedency changes
@param filter_tasks (list -str): print only tasks from this list
@loop_callback: used to stop loop on unittests
"""
task_control = TaskControl(task_list)
task_control.process(filter_tasks)
tasks_to_run = list(set([t for t in task_control.task_dispatcher(True)]))
watch_tasks = [t.name for t in tasks_to_run]
watch_files = list(itertools.chain(*[s.file_dep for s in tasks_to_run]))
watch_files = list(set(watch_files))
class DoitAutoRun(FileModifyWatcher):
"""Execute doit on event handler of file changes """
def handle_event(self, event):
doit_run(dependency_file, task_list, sys.stdout,
watch_tasks, reporter='executed-only')
# reset run_status
for task in task_list:
task.run_status = None
file_watcher = DoitAutoRun(watch_files)
# always run once when started
file_watcher.handle_event(None)
file_watcher.loop(loop_callback)
示例5: test_delayed_creation
def test_delayed_creation(self):
def creator():
yield {'name': 'foo1', 'actions': None, 'file_dep': ['bar']}
yield {'name': 'foo2', 'actions': None, 'targets': ['bar']}
delayed_loader = DelayedLoader(creator, executed='t2')
tasks = [Task('t0', None, task_dep=['t1']),
Task('t1', None, loader=delayed_loader),
Task('t2', None)]
control = TaskControl(tasks)
control.process(['t0'])
disp = control.task_dispatcher()
gen = disp.generator
nt2 = next(gen)
assert nt2.task.name == "t2"
# wait for t2 to be executed
assert "hold on" == next(gen)
assert "hold on" == next(gen) # hold until t2 is done
# delayed creation of tasks for t1 does not mess existing info
assert disp.nodes['t1'].waiting_me == set([disp.nodes['t0']])
nf2 = gen.send(nt2)
assert disp.nodes['t1'].waiting_me == set([disp.nodes['t0']])
assert nf2.task.name == "t1:foo2"
nf1 = gen.send(nf2)
assert nf1.task.name == "t1:foo1"
assert nf1.task.task_dep == ['t1:foo2'] # implicit dep added
nt1 = gen.send(nf1)
assert nt1.task.name == "t1"
nt0 = gen.send(nt1)
assert nt0.task.name == "t0"
pytest.raises(StopIteration, lambda gen: next(gen), gen)
示例6: testChangeOrder_AddJustOnce
def testChangeOrder_AddJustOnce(self):
tasks = [Task("taskX",None,task_dep=["taskY"]),
Task("taskY",None,)]
tc = TaskControl(tasks)
tc.process(None)
assert [tasks[1], tasks[0]] == [x for x in tc._add_task(0, 'taskX', False)]
# both tasks were already added. so no tasks left..
assert [] == [x for x in tc._add_task(0, 'taskY', False)]
示例7: test_filter_delayed_subtask
def test_filter_delayed_subtask(self):
t1 = Task("taskX", None)
t2 = Task("taskY", None, loader=DelayedLoader(lambda: None))
control = TaskControl([t1, t2])
control._filter_tasks(['taskY:foo'])
assert isinstance(t2.loader, DelayedLoader)
# sub-task will use same loader, and keep parent basename
assert control.tasks['taskY:foo'].loader.basename == 'taskY'
assert control.tasks['taskY:foo'].loader is t2.loader
示例8: testSetupInvalid
def testSetupInvalid(self):
tasks = [Task("taskX",None,setup=["taskZZZZZZZZ"]),
Task("taskY",None,)]
tc = TaskControl(tasks)
tc.process(['taskX'])
gen = tc._add_task(0, 'taskX', False)
assert tasks[0] == gen.next() # tasks with setup are yield twice
tasks[0].run_status = 'run' # should be executed
py.test.raises(InvalidTask, gen.next) # execute setup before
示例9: test_successRunOnce
def test_successRunOnce(self, reporter, RunnerClass):
tasks = [Task("taskX", [my_print], run_once=True)]
my_runner = RunnerClass(TESTDB, reporter)
tc = TaskControl(tasks)
tc.process(None)
my_runner.run_tasks(tc)
assert runner.SUCCESS == my_runner.finish()
d = Dependency(TESTDB)
assert '1' == d._get('taskX', 'run-once:')
示例10: test_reporter_runtime_error
def test_reporter_runtime_error(self, reporter):
t1 = Task('t1', [], setup=['make_invalid'])
my_runner = runner.Runner(TESTDB, reporter)
tc = TaskControl([t1])
tc.process(None)
my_runner.run_all(tc)
assert ('start', t1) == reporter.log.pop(0)
assert ('runtime_error',) == reporter.log.pop(0)
assert not reporter.log
示例11: testSetupTasksDontRun
def testSetupTasksDontRun(self):
tasks = [Task("taskX",None,setup=["taskY"]),
Task("taskY",None,)]
tc = TaskControl(tasks)
tc.process(['taskX'])
gen = tc._add_task(0, 'taskX', False)
assert tasks[0] == gen.next()
# X is up-to-date
tasks[0].run_status = 'up-to-date'
py.test.raises(StopIteration, gen.next)
示例12: test_teardown
def test_teardown(self, reporter, RunnerClass):
t1 = Task('t1', [], teardown=[ok])
t2 = Task('t2', [])
my_runner = RunnerClass(TESTDB, reporter)
tc = TaskControl([t1, t2])
tc.process(None)
assert [] == my_runner.teardown_list
my_runner.run_tasks(tc)
my_runner.finish()
assert ('teardown', t1) == reporter.log[-1]
示例13: test_include_setup
def test_include_setup(self):
tasks = [Task("t1", None, task_dep=["t2"]),
Task("t2", None,)]
control = TaskControl(tasks)
control.process(['t1'])
gen = control.task_dispatcher(include_setup=True).generator
# dont wait for tasks
assert tasks[0] == gen.send(None).task
assert tasks[1] == gen.send(None).task
pytest.raises(StopIteration, gen.send, None)
示例14: test_stop_running
def test_stop_running(self, reporter):
t1 = Task('t1', [])
t2 = Task('t2', [])
tc = TaskControl([t1, t2])
tc.process(None)
run = runner.MRunner(TESTDB, reporter)
run._run_tasks_init(tc)
assert t1 == run.get_next_task()
run._stop_running = True
assert None == run.get_next_task()
示例15: testParallel
def testParallel(self):
tasks = [Task("taskX",None,task_dep=["taskY"]),
Task("taskY",None)]
tc = TaskControl(tasks)
tc.process(None)
gen1 = tc._add_task(0, "taskX", False)
assert tasks[1] == gen1.next()
# gen2 wont get any task, because it was already being processed
gen2 = tc._add_task(1, "taskY", False)
py.test.raises(StopIteration, gen2.next)