示例#1
0
def test__Dequindre_get_schedules():
    A = Task('A.py', 'test-env')
    B = Task('B.py', 'test-env')
    C = Task('C.py', 'test-env')
    Z = Task('Z.py', 'test-env')
    dag = DAG()
    dag.add_tasks({A, B, C, Z})
    dag.add_dependencies({B: A, C: B})
    dq = Dequindre(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)},
    }
示例#2
0
def test__DAG_add_dependencies():
    A, B = get_two_tasks()
    C = Task('C.py', env='test-env')
    dag = DAG()
    dag.add_dependencies({B: A})
    assert dag._edges[A] == set([B])

    dag = DAG()
    dag.add_dependencies({C: {A, B}})
    assert dag._edges[A] == set([C])
    assert dag._edges[B] == set([C])
示例#3
0
def test__DAG_add_dependency_detect_cycle():
    A, B = get_two_tasks()
    C = Task('C.py', env='test-env')

    dag = DAG()
    with pytest.raises(CyclicGraphError):
        dag.add_dependencies({
            A: C,
            B: A,
            C: B
        })
示例#4
0
def test__Dequindre_get_task_schedules():
    A = Task('A.py', 'test-env')
    B = Task('B.py', 'test-env')
    C = Task('C.py', 'test-env')
    Z = Task('Z.py', 'test-env')
    dag = DAG()
    dag.add_tasks({A, B, C, Z})
    dag.add_dependencies({B: A, C: B})
    dq = Dequindre(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}