Ejemplo n.º 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)},
    }
Ejemplo n.º 2
0
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}
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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}
Ejemplo n.º 5
0
def test__Dequindre_init():
    """Nothing should break here
    """
    A = Task('A.py', 'test-env')
    B = Task('B.py', 'test-env')
    C = Task('C.py', 'test-env')

    dag = DAG()
    dag.add_tasks({A, B, C})
    dq = Dequindre(dag)

    return None
Ejemplo n.º 6
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}
Ejemplo n.º 7
0
def test__Dequindre_init_exceptions():
    """Raise expected exceptions
    """
    A = Task('A.py', 'test-env')
    B = Task('B.py', 'test-env')
    C = Task('C.py', 'test-env')

    dag = DAG()
    dag.add_tasks({A, B, C})

    with pytest.raises(TypeError):
        Dequindre()

    return None
Ejemplo n.º 8
0
def test__Dequindre_refresh_dag():
    A = Task('A.py', 'test-env')
    B = Task('B.py', 'test-env')
    C = Task('C.py', 'test-env')
    dag = DAG()
    dag.add_tasks({A, B, C})
    dq = Dequindre(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