def test_sorted_tasks_with_invalid_start_task(): """ t1 -> t2 -> t3 -> t4 t3 -> t5 """ f = Flow(name="test") t1 = Task("1") t2 = Task("2") t3 = Task("3") f.add_edge(t1, t2) with pytest.raises(ValueError) as exc: f.sorted_tasks(root_tasks=[t3]) assert "not found in Flow" in str(exc.value)
def test_cache_survives_pickling(self): f = Flow(name="test") t1 = Task() t2 = Task() t3 = Task() f.add_edge(t1, t2) f.sorted_tasks() key = ("_sorted_tasks", (("root_tasks", ()), )) f._cache[key] = 1 assert f.sorted_tasks() == 1 f2 = cloudpickle.loads(cloudpickle.dumps(f)) assert f2.sorted_tasks() == 1 f2.add_edge(t2, t3) assert f2.sorted_tasks() != 1
def test_sorted_tasks_with_ambiguous_sort(): """ t1 -> bottleneck t2 -> bottleneck t3 -> bottleneck bottleneck -> t4 bottleneck -> t5 bottleneck -> t6 """ f = Flow(name="test") t1 = Task("1") t2 = Task("2") t3 = Task("3") t4 = Task("4") t5 = Task("5") t6 = Task("6") bottleneck = Task("bottleneck") f.add_edge(t1, bottleneck) f.add_edge(t2, bottleneck) f.add_edge(t3, bottleneck) f.add_edge(bottleneck, t4) f.add_edge(bottleneck, t5) f.add_edge(bottleneck, t6) tasks = f.sorted_tasks() assert set(tasks[:3]) == set([t1, t2, t3]) assert list(tasks)[3] is bottleneck assert set(tasks[4:]) == set([t4, t5, t6])
def test_sorted_tasks_with_start_task(): """ t1 -> t2 -> t3 -> t4 t3 -> t5 """ f = Flow(name="test") t1 = Task("1") t2 = Task("2") t3 = Task("3") t4 = Task("4") t5 = Task("5") f.add_edge(t1, t2) f.add_edge(t2, t3) f.add_edge(t3, t4) f.add_edge(t3, t5) assert set(f.sorted_tasks(root_tasks=[])) == set([t1, t2, t3, t4, t5]) assert set(f.sorted_tasks(root_tasks=[t3])) == set([t3, t4, t5])
def test_cache_sorted_tasks(self): f = Flow(name="test") t1 = Task() t2 = Task() t3 = Task() f.add_edge(t1, t2) f.sorted_tasks() # check that cache holds result key = ("_sorted_tasks", (("root_tasks", ()), )) assert f._cache[key] == (t1, t2) # check that cache is read f._cache[key] = 1 assert f.sorted_tasks() == 1 f.add_edge(t2, t3) assert f.sorted_tasks() == (t1, t2, t3)
def test_sorted_tasks(): """ t1 -> t2 -> t3 -> t4 """ f = Flow(name="test") t1 = Task("1") t2 = Task("2") t3 = Task("3") t4 = Task("4") f.add_edge(t1, t2) f.add_edge(t2, t3) f.add_edge(t3, t4) assert f.sorted_tasks() == (t1, t2, t3, t4)