def test__Composer_get_schedules(): A = Task("A.py", "test-exe") B = Task("B.py", "test-exe") C = Task("C.py", "test-exe") Z = Task("Z.py", "test-exe") dag = DAG() dag.add_tasks({A, B, C, Z}) dag.add_dependencies({B: A, C: B}) dq = Composer(dag) priorities = dq.get_schedules() testable = {} # build a testable result dict for k, v in priorities.items(): new_set = set() if isinstance(v, Task): testable[k] = set(v) continue for vi in v: new_set.add(hash(vi)) testable[k] = new_set assert testable == {1: {hash(A), hash(Z)}, 2: {hash(B)}, 3: {hash(C)}}
def test__DAG_remove_task(): A, B = get_two_tasks() dag = DAG() dag.add_tasks({A, B}) dag.remove_task(A) assert dag.tasks == {B}
def test__DAG_remove_tasks(): A, B = get_two_tasks() C = Task("C.py") dag = DAG() dag.add_tasks({A, B, C}) dag.remove_tasks({A, B}) assert dag.tasks == {C} dag.remove_tasks(C) assert dag.tasks == set()
def test__DAG_add_tasks(): A, B = get_two_tasks() C = Task("C.py") dag = DAG() dag.add_tasks({A, B}) assert dag.tasks == {A, B}, "Test Tasks were not added to the DAG" dag.add_tasks(C) assert dag.tasks == {A, B, C}
def test__Composer_init(): """Nothing should break here """ A = Task("A.py", "test-exe") B = Task("B.py", "test-exe") C = Task("C.py", "test-exe") dag = DAG() dag.add_tasks({A, B, C}) dq = Composer(dag) return None
def test__Composer_get_task_schedules(): A = Task("A.py", "test-exe") B = Task("B.py", "test-exe") C = Task("C.py", "test-exe") Z = Task("Z.py", "test-exe") dag = DAG() dag.add_tasks({A, B, C, Z}) dag.add_dependencies({B: A, C: B}) dq = Composer(dag) priorities = dq.get_task_schedules() testable = {hash(k): v for k, v in priorities.items()} assert testable == {hash(A): 1, hash(B): 2, hash(C): 3, hash(Z): 1}
def test__Composer_init_exceptions(): """Raise expected exceptions """ A = Task("A.py", "test-exe") B = Task("B.py", "test-exe") C = Task("C.py", "test-exe") dag = DAG() dag.add_tasks({A, B, C}) with pytest.raises(TypeError): Composer() return None
def test__Composer_refresh_dag(): A = Task("A.py", "test-exe") B = Task("B.py", "test-exe") C = Task("C.py", "test-exe") dag = DAG() dag.add_tasks({A, B, C}) dq = Composer(dag) tasks = sorted(list(dq.dag.tasks)) for t in tasks: dq.dag.remove_task(t) assert dq.dag.tasks == set() dq.refresh_dag() new_tasks = sorted(list(dq.dag.tasks)) for t, nt in zip(tasks, new_tasks): assert t == nt