def test_targeted_flow_bad_target(self): f = gf.TargetedFlow("test") task1 = _task('task1', provides=['a'], requires=[]) task2 = _task('task2', provides=['b'], requires=['a']) f.add(task1) self.assertRaisesRegexp(ValueError, '^Item .* not found', f.set_target, task2)
def test_targeted_flow_one_node(self): f = gf.TargetedFlow("test") task1 = _task('task1', provides=['a'], requires=[]) f.add(task1) f.set_target(task1) self.assertEqual(len(f), 1) self.assertItemsEqual(f, [task1])
def test_recache_on_add_no_deps(self): f = gf.TargetedFlow("test") task1 = _task('task1', provides=[], requires=[]) f.add(task1) f.set_target(task1) self.assertEqual(1, len(f)) task2 = _task('task2', provides=[], requires=[]) f.add(task2) self.assertEqual(1, len(f))
def test_recache_on_add_no_deps(self): wf = gw.TargetedFlow("test") test_1 = utils.ProvidesRequiresTask('test-1', provides=[], requires=[]) wf.add(test_1) wf.set_target(test_1) self.assertEqual(1, len(wf.graph)) test_2 = utils.ProvidesRequiresTask('test-2', provides=[], requires=[]) wf.add(test_2) self.assertEqual(1, len(wf.graph))
def test_recache_on_link(self): wf = gw.TargetedFlow("test") test_1 = utils.ProvidesRequiresTask('test-1', provides=[], requires=[]) test_2 = utils.ProvidesRequiresTask('test-2', provides=[], requires=[]) wf.add(test_1, test_2) wf.set_target(test_1) self.assertEqual(1, len(wf.graph)) wf.link(test_2, test_1) self.assertEqual(2, len(wf.graph)) self.assertEqual([(test_2, test_1)], list(wf.graph.edges()))
def test_targeted_flow_one_node(self): wf = gw.TargetedFlow("test") test_1 = utils.ProvidesRequiresTask('test-1', provides=['a'], requires=[]) wf.add(test_1) wf.set_target(test_1) g = fu.flatten(wf) self.assertEqual(1, len(g)) self.assertTrue(g.has_node(test_1))
def test_targeted_flow_restricts(self): f = gf.TargetedFlow("test") task1 = _task('task1', provides=['a'], requires=[]) task2 = _task('task2', provides=['b'], requires=['a']) task3 = _task('task3', provides=[], requires=['b']) task4 = _task('task4', provides=[], requires=['b']) f.add(task1, task2, task3, task4) f.set_target(task3) self.assertEqual(len(f), 3) self.assertItemsEqual(f, [task1, task2, task3]) self.assertNotIn('c', f.provides)
def test_targeted_flow_bad_target(self): wf = gw.TargetedFlow("test") test_1 = utils.ProvidesRequiresTask('test-1', provides=['a'], requires=[]) test_2 = utils.ProvidesRequiresTask('test-2', provides=['b'], requires=['a']) wf.add(test_1) self.assertRaisesRegexp(ValueError, '^Item .* not found', wf.set_target, test_2)
def test_targeted_flow_reset(self): f = gf.TargetedFlow("test") task1 = _task('task1', provides=['a'], requires=[]) task2 = _task('task2', provides=['b'], requires=['a']) task3 = _task('task3', provides=[], requires=['b']) task4 = _task('task4', provides=['c'], requires=['b']) f.add(task1, task2, task3, task4) f.set_target(task3) f.reset_target() self.assertEqual(4, len(f)) self.assertCountEqual(f, [task1, task2, task3, task4]) self.assertIn('c', f.provides)
def test_recache_on_link(self): f = gf.TargetedFlow("test") task1 = _task('task1', provides=[], requires=[]) task2 = _task('task2', provides=[], requires=[]) f.add(task1, task2) f.set_target(task1) self.assertEqual(1, len(f)) f.link(task2, task1) self.assertEqual(2, len(f)) self.assertEqual(list(f.iter_links()), [(task2, task1, { 'manual': True })])
def test_targeted_flow_reset(self): wf = gw.TargetedFlow("test") test_1 = utils.ProvidesRequiresTask('test-1', provides=['a'], requires=[]) test_2 = utils.ProvidesRequiresTask('test-2', provides=['b'], requires=['a']) test_3 = utils.ProvidesRequiresTask('test-3', provides=[], requires=['b']) test_4 = utils.ProvidesRequiresTask('test-4', provides=['c'], requires=['b']) wf.add(test_1, test_2, test_3, test_4) wf.set_target(test_3) wf.reset_target() g = fu.flatten(wf) self.assertEqual(4, len(g)) self.assertTrue(g.has_node(test_4))
def make_flow_and_store(source_files, executable_only=False): flow = gf.TargetedFlow('build flow') object_targets = [] store = {} for source in source_files: source_stored = '%s-source' % source object_stored = '%s-object' % source store[source_stored] = source object_targets.append(object_stored) flow.add(CompileTask(name='compile-%s' % source, rebind={'source_filename': source_stored}, provides=object_stored)) flow.add(BuildDocsTask(requires=list(store.keys()))) # Try this to see executable_only switch broken: object_targets.append('docs') link_task = LinkTask('build/executable', requires=object_targets) flow.add(link_task) if executable_only: flow.set_target(link_task) return flow, store
g_f = graph_flow.Flow("test_graphflow") flow = linear_flow.Flow('test_lf').add(t7) g_f.add(t1, t2, t3, t4, t5, t6, flow) g_f.link(t1, t2) g_f.link(t1, t3) g_f.link(t2, t4) g_f.link(t3, t4, decider=allow, decider_depth='FLOW') g_f.link(t4, t5) g_f.link(t5, t6) g_f.link(t6, flow) e = engines.load(g_f) e.run() #Targeted Flow print("\n #####Example for Targeted Graph Flow#####\n") targetedg_f = graph_flow.TargetedFlow("test_targetedgraphflow") targetedg_f.add(t1, t2, t3, t4, t5) targetedg_f.link(t1, t2) targetedg_f.link(t2, t3) targetedg_f.link(t2, t4) targetedg_f.link(t4, t5) targetedg_f.set_target(t5) e = engines.load(targetedg_f) #e = engines.load(targetedg_f,engine='workers') e.run() print("Done")