Exemplo n.º 1
0
def start_with_graph():
    global dag
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})
Exemplo n.º 2
0
def start_with_graph():
    global dag
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})
Exemplo n.º 3
0
def basic_dag():
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})
    return dag
Exemplo n.º 4
0
def test_all_downstreams_pass_graph():
    dag2 = DAG()
    dag2.from_dict({'a': ['c'],
                    'b': ['d'],
                    'c': ['d'],
                    'd': []})
    assert dag2.all_downstreams('a') == ['c', 'd']
    assert dag2.all_downstreams('b') == ['d']
    assert dag2.all_downstreams('d') == []
Exemplo n.º 5
0
def test_all_downstreams_pass_graph():
    dag2 = DAG()
    dag2.from_dict({'a': ['c'],
                    'b': ['d'],
                    'c': ['d'],
                    'd': []})
    assert dag2.all_downstreams('a') == ['c', 'd']
    assert dag2.all_downstreams('b') == ['d']
    assert dag2.all_downstreams('d') == []
Exemplo n.º 6
0
def test_transitive_reduction_no_reduction():
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'], 'b': ['d'], 'c': ['d'], 'd': []})
    dag.transitive_reduction()
    assert dag.graph == {
        'a': set(['b', 'c']),
        'b': set('d'),
        'c': set('d'),
        'd': set()
    }
Exemplo n.º 7
0
def test_transitive_reduction_no_reduction():
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})
    dag.transitive_reduction()
    assert dag.graph == {'a': set(['b', 'c']),
                         'b': set('d'),
                         'c': set('d'),
                         'd': set()}
Exemplo n.º 8
0
def test_walk():
    dag = DAG()

    # b and c should be executed at the same time.
    dag.from_dict({'a': ['b', 'c'], 'b': ['d'], 'c': ['d'], 'd': []})

    nodes = []

    def walk_func(n):
        nodes.append(n)
        return True

    dag.walk(walk_func)
    assert nodes == ['d', 'c', 'b', 'a'] or nodes == ['d', 'b', 'c', 'a']
Exemplo n.º 9
0
def test_transitive_deep_reduction():
    dag = DAG()
    # https://en.wikipedia.org/wiki/Transitive_reduction#/media/File:Tred-G.svg
    dag.from_dict({
        'a': ['b', 'd'],
        'b': ['c'],
        'c': ['d'],
        'd': [],
    })
    dag.transitive_reduction()
    # https://en.wikipedia.org/wiki/Transitive_reduction#/media/File:Tred-Gprime.svg
    assert dag.graph == {'a': set('b'),
                         'b': set('c'),
                         'c': set('d'),
                         'd': set()}
Exemplo n.º 10
0
def test_walk():
    dag = DAG()

    # b and c should be executed at the same time.
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})

    nodes = []

    def walk_func(n):
        nodes.append(n)
        return True

    dag.walk(walk_func)
    assert nodes == ['d', 'c', 'b', 'a'] or nodes == ['d', 'b', 'c', 'a']
Exemplo n.º 11
0
def test_threaded_walker():
    dag = DAG()
    walker = ThreadedWalker()

    # b and c should be executed at the same time.
    dag.from_dict({'a': ['b', 'c'], 'b': ['d'], 'c': ['d'], 'd': []})

    lock = threading.Lock()  # Protects nodes from concurrent access
    nodes = []

    def walk_func(n):
        lock.acquire()
        nodes.append(n)
        lock.release()
        return True

    walker.walk(dag, walk_func)
    assert nodes == ['d', 'c', 'b', 'a'] or nodes == ['d', 'b', 'c', 'a']
Exemplo n.º 12
0
def test_walk_failed():
    dag = DAG()

    # b and c should be executed at the same time.
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})

    nodes = []

    def walk_func(n):
        nodes.append(n)
        return False

    ok = dag.walk(walk_func)

    # Only 2 should have been hit. The rest are canceled because they depend on
    # the success of d.
    assert ok == False  # noqa: E712
    assert nodes == ['d', 'c', 'b', 'a'] or nodes == ['d', 'b', 'c', 'a']
Exemplo n.º 13
0
def test_threaded_walker():
    dag = DAG()
    walker = ThreadedWalker()

    # b and c should be executed at the same time.
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})

    lock = threading.Lock()  # Protects nodes from concurrent access
    nodes = []

    def walk_func(n):
        lock.acquire()
        nodes.append(n)
        lock.release()
        return True

    walker.walk(dag, walk_func)
    assert nodes == ['d', 'c', 'b', 'a'] or nodes == ['d', 'b', 'c', 'a']
Exemplo n.º 14
0
def basic_dag():
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'], 'b': ['d'], 'c': ['d'], 'd': []})
    return dag