本文整理汇总了Python中doit.control.TaskDispatcher._add_task方法的典型用法代码示例。如果您正苦于以下问题:Python TaskDispatcher._add_task方法的具体用法?Python TaskDispatcher._add_task怎么用?Python TaskDispatcher._add_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类doit.control.TaskDispatcher
的用法示例。
在下文中一共展示了TaskDispatcher._add_task方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delayed_creation_target_regex
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_delayed_creation_target_regex(self):
def creator():
yield Task('foo', None, targets=['tgt1'])
delayed_loader = DelayedLoader(creator,
executed='t2', target_regex='tgt1')
tasks = {
't1': Task('t1', None, loader=delayed_loader),
't2': Task('t2', None),
}
tc = TaskControl(list(tasks.values()))
selection = tc._filter_tasks(['tgt1'])
assert ['_regex_target_tgt1:t1'] == selection
td = TaskDispatcher(tc.tasks, tc.targets, selection)
n1 = td._gen_node(None, '_regex_target_tgt1:t1')
gen = td._add_task(n1)
# first returned node is `t2` because it is an implicit task_dep
n2 = next(gen)
assert n2.task.name == 't2'
# wait until t2 is finished
n3 = next(gen)
assert n3 == 'wait'
# after t2 is done, generator is reseted
n2.run_status = 'done'
td._update_waiting(n2)
n4 = next(gen)
assert n4 == "reset generator"
# manually reset generator
n1.reset_task(td.tasks[n1.task.name], td._add_task(n1))
# get the delayed created task
gen2 = n1.generator # n1 generator was reset / replaced
# get t1 because of its target was a file_dep of _regex_target_tgt1
n5 = next(gen2)
assert n5.task.name == 'foo'
# get internal created task
n5.run_status = 'done'
td._update_waiting(n5)
n6 = next(gen2)
assert n6.name == '_regex_target_tgt1:t1'
# file_dep is removed because foo might not be task
# that creates this task (support for multi regex matches)
assert n6.file_dep == {}
示例2: test_delayed_creation_sub_task
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_delayed_creation_sub_task(self):
# usually a repeated loader is replaced by the real task
# when it is first executed, the problem arises when the
# the expected task is not actually created
def creator():
yield Task('t1:foo', None)
yield Task('t1:bar', None)
delayed_loader = DelayedLoader(creator, executed='t2')
tasks = {
't1': Task('t1', None, loader=delayed_loader),
't2': Task('t2', None),}
# simulate a sub-task from delayed created added to task_list
tasks['t1:foo'] = Task('t1:foo', None, loader=delayed_loader)
tasks['t1:xxx'] = Task('t1:xxx', None, loader=delayed_loader)
delayed_loader.basename = 't1'
td = TaskDispatcher(tasks, [], None)
n1 = td._gen_node(None, 't1:foo')
gen = td._add_task(n1)
# first returned node is `t2` because it is an implicit task_dep
n1b = next(gen)
assert n1b.task.name == 't2'
# wait until t2 is finished
n1c = next(gen)
assert n1c == 'wait'
# after t2 is done, generator is reseted
n1b.run_status = 'successful'
td._update_waiting(n1b)
n1d = next(gen)
assert n1d == "reset generator"
assert 't1:foo' in td.tasks
assert 't1:bar' in td.tasks
# finish with t1:foo
gen2 = td._add_task(n1)
n1.reset_task(td.tasks[n1.task.name], gen2)
n2 = next(gen2)
assert n2.name == 't1:foo'
pytest.raises(StopIteration, next, gen2)
# try non-existent t1:xxx
n3 = td._gen_node(None, 't1:xxx')
gen3 = td._add_task(n3)
# ? should raise a runtime error?
assert next(gen3) == 'reset generator'
示例3: test_delayed_creation
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_delayed_creation(self):
def creator():
yield Task('foo', None, loader=DelayedLoader(lambda : None))
delayed_loader = DelayedLoader(creator, executed='t2')
tasks = {'t1': Task('t1', None, loader=delayed_loader),
't2': Task('t2', None),
}
td = TaskDispatcher(tasks, [], None)
n1 = td._gen_node(None, 't1')
gen = td._add_task(n1)
# first returned node is `t2` because it is an implicit task_dep
n2 = next(gen)
assert n2.task.name == 't2'
# wait until t2 is finished
n3 = next(gen)
assert n3 == 'wait'
# after t2 is done, generator is reseted
td._update_waiting(n2)
n4 = next(gen)
assert n4 == "reset generator"
# recursive loader is preserved
assert isinstance(td.tasks['foo'].loader, DelayedLoader)
pytest.raises(AssertionError, next, gen)
示例4: test_regex_group_already_created
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_regex_group_already_created(self):
# this is required to avoid loading more tasks than required, GH-#60
def creator1():
yield Task('foo1', None, targets=['tgt1'])
delayed_loader1 = DelayedLoader(creator1, target_regex='tgt.*')
def creator2(): # pragma: no cover
yield Task('foo2', None, targets=['tgt2'])
delayed_loader2 = DelayedLoader(creator2, target_regex='tgt.*')
t1 = Task('t1', None, loader=delayed_loader1)
t2 = Task('t2', None, loader=delayed_loader2)
tc = TaskControl([t1, t2])
selection = tc._filter_tasks(['tgt1'])
assert ['_regex_target_tgt1:t1', '_regex_target_tgt1:t2'] == selection
td = TaskDispatcher(tc.tasks, tc.targets, selection)
n1 = td._gen_node(None, '_regex_target_tgt1:t1')
gen = td._add_task(n1)
# delayed loader executed, so generator is reset
n1b = next(gen)
assert n1b == "reset generator"
# manually reset generator
n1.reset_task(td.tasks[n1.task.name], td._add_task(n1))
# get the delayed created task
gen1b = n1.generator # n1 generator was reset / replaced
# get t1 because of its target was a file_dep of _regex_target_tgt1
n1c = next(gen1b)
assert n1c.task.name == 'foo1'
# get internal created task
n1c.run_status = 'done'
td._update_waiting(n1c)
n1d = next(gen1b)
assert n1d.name == '_regex_target_tgt1:t1'
## go for second selected task
n2 = td._gen_node(None, '_regex_target_tgt1:t2')
gen2 = td._add_task(n2)
# loader is not executed because target t1 was already found
pytest.raises(StopIteration, next, gen2)
示例5: test_task_deps_no_wait
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_task_deps_no_wait(self):
tasks = {'t1': Task('t1', None, task_dep=['t2']),
't2': Task('t2', None),
}
td = TaskDispatcher(tasks, [], None)
n1 = td._gen_node(None, 't1')
n2 = td._gen_node(None, 't2')
n2.run_status = 'done'
gen = td._add_task(n1)
assert tasks['t1'] == next(gen)
示例6: test_setup_task__run
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_setup_task__run(self):
tasks = {'t1': Task('t1', None, setup=['t2']),
't2': Task('t2', None),
}
td = TaskDispatcher(tasks, [], None)
n1 = td._gen_node(None, 't1')
gen = td._add_task(n1)
assert tasks['t1'] == next(gen) # first time (just select)
assert 'wait' == next(gen) # wait for select result
n1.run_status = 'run'
assert tasks['t2'] == next(gen).task # send setup task
assert 'wait' == next(gen)
assert tasks['t1'] == next(gen) # second time
示例7: test_regex_not_found
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_regex_not_found(self):
def creator1():
yield Task('foo1', None, targets=['tgt1'])
delayed_loader1 = DelayedLoader(creator1, target_regex='tgt.*')
t1 = Task('t1', None, loader=delayed_loader1)
tc = TaskControl([t1])
selection = tc._filter_tasks(['tgt666'])
assert ['_regex_target_tgt666:t1'] == selection
td = TaskDispatcher(tc.tasks, tc.targets, selection)
n1 = td._gen_node(None, '_regex_target_tgt666:t1')
gen = td._add_task(n1)
# target not found after generating all tasks from regex group
pytest.raises(InvalidCommand, next, gen)
示例8: test_task_deps
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_task_deps(self):
tasks = {'t1': Task('t1', None, task_dep=['t2', 't3']),
't2': Task('t2', None),
't3': Task('t3', None),
}
td = TaskDispatcher(tasks, [], None)
n1 = td._gen_node(None, 't1')
gen = td._add_task(n1)
n2 = next(gen)
assert tasks['t2'] == n2.task
n3 = next(gen)
assert tasks['t3'] == n3.task
assert 'wait' == next(gen)
tasks['t2'].run_status = 'done'
td._update_waiting(n2)
tasks['t3'].run_status = 'done'
td._update_waiting(n3)
assert tasks['t1'] == next(gen)
示例9: test_waiting_node_updated
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_waiting_node_updated(self):
tasks = {'t1': Task('t1', None, calc_dep=['t2'], task_dep=['t4']),
't2': Task('t2', None),
't3': Task('t3', None),
't4': Task('t4', None),
}
td = TaskDispatcher(tasks, [], None)
n1 = td._gen_node(None, 't1')
n1_gen = td._add_task(n1)
n2 = next(n1_gen)
assert 't2' == n2.task.name
assert 't4' == next(n1_gen).task.name
assert 'wait' == next(n1_gen)
assert set() == n1.calc_dep
assert td.waiting == set()
n2.run_status = 'done'
n2.task.values = {'calc_dep': ['t2', 't3'], 'task_dep':['t5']}
assert n1.calc_dep == set()
assert n1.task_dep == []
td._update_waiting(n2)
assert n1.calc_dep == set(['t3'])
assert n1.task_dep == ['t5']
示例10: test_no_deps
# 需要导入模块: from doit.control import TaskDispatcher [as 别名]
# 或者: from doit.control.TaskDispatcher import _add_task [as 别名]
def test_no_deps(self):
tasks = {'t1': Task('t1', None),
}
td = TaskDispatcher(tasks, [], None)
n1 = td._gen_node(None, 't1')
assert [tasks['t1']] == list(td._add_task(n1))