Exemplo n.º 1
0
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)}}
Exemplo n.º 2
0
def test__Composer_repr():
    p = pathlib.Path("make_tea.py")
    make_tea = Task(p, "test-exe")
    dag = DAG()
    dag.add_task(make_tea)
    dq = Composer(dag)
    assert repr(dq) == "".join(
        ["Composer(DAG({Task(",
         p.resolve().as_posix(), ")}))"])
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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}
Exemplo n.º 5
0
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
Exemplo n.º 6
0
def test__readme_example():

    ## define tasks and environments
    pour_water = Task("./tea-tasks/pour_water.py")
    boil_water = Task("./tea-tasks/boil_water.py")
    prep_infuser = Task("./tea-tasks/prep_infuser.py")
    steep_tea = Task("./tea-tasks/steep_tea.py")

    ## define runtime dependencies
    make_tea = DAG(upstream_dependencies={
        boil_water: {pour_water},
        steep_tea: {boil_water, prep_infuser},
    })

    ## run tasks
    dq = Composer(make_tea)
    dq.get_schedules()
Exemplo n.º 7
0
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