コード例 #1
0
ファイル: test_dag.py プロジェクト: krashproof/stacker
def start_with_graph():
    global dag
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})
コード例 #2
0
def start_with_graph():
    global dag
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})
コード例 #3
0
ファイル: test_dag.py プロジェクト: acmcelwee/stacker
def basic_dag():
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'],
                   'b': ['d'],
                   'c': ['d'],
                   'd': []})
    return dag
コード例 #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') == []
コード例 #5
0
ファイル: test_dag.py プロジェクト: krashproof/stacker
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') == []
コード例 #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()
    }
コード例 #7
0
ファイル: test_dag.py プロジェクト: krashproof/stacker
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()}
コード例 #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']
コード例 #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()}
コード例 #10
0
ファイル: test_dag.py プロジェクト: krashproof/stacker
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']
コード例 #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']
コード例 #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']
コード例 #13
0
ファイル: test_dag.py プロジェクト: krashproof/stacker
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']
コード例 #14
0
def basic_dag():
    dag = DAG()
    dag.from_dict({'a': ['b', 'c'], 'b': ['d'], 'c': ['d'], 'd': []})
    return dag