def start_with_graph(): global dag dag = DAG() dag.from_dict({'a': ['b', 'c'], 'b': ['d'], 'c': ['d'], 'd': []})
def basic_dag(): dag = DAG() dag.from_dict({'a': ['b', 'c'], 'b': ['d'], 'c': ['d'], 'd': []}) return dag
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') == []
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()}
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']
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 ok = dag.walk(walk_func) assert ok == True # noqa: E712 assert nodes == ['d', 'c', 'b', 'a'] or nodes == ['d', 'b', 'c', 'a']
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']
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']
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() }
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()}
def blank_setup(): global dag dag = DAG()
def empty_dag(): return DAG()