def test_output_invalidation(): graph = Graph('') n1 = graph.addNewNode('SampleNode', input='/tmp') n2 = graph.addNewNode('SampleNode') n3 = graph.addNewNode('SampleNode') graph.addEdges((n1.output, n2.input), (n1.output, n3.input)) # N1.output ----- N2.input # \ # N3.input # Compare UIDs of similar attributes on different nodes n2inputUid = n2.input.uid() n3inputUid = n3.input.uid() assert n3inputUid == n2inputUid # => UIDs are equal # Change a parameter outside UID n1.paramA.value = 'a' assert n2.input.uid() == n2inputUid # => same UID as before # Change a parameter impacting UID n1.input.value = "/a/path" assert n2.input.uid() != n2inputUid # => UID has changed assert n2.input.uid() == n3.input.uid( ) # => UIDs on both node are still equal
def test_depth_diamond_graph2(): graph = Graph('Tests tasks depth') tA = graph.addNewNode('Ls', input='/tmp') tB = graph.addNewNode('AppendText', inputText='echo B') tC = graph.addNewNode('AppendText', inputText='echo C') tD = graph.addNewNode('AppendText', inputText='echo D') tE = graph.addNewNode('AppendFiles') # C # / \ # /---/---->\ # A -> B ---> E # \ / # \ / # D graph.addEdges( (tA.output, tB.input), (tB.output, tC.input), (tB.output, tD.input), (tA.output, tE.input), (tB.output, tE.input2), (tC.output, tE.input3), (tD.output, tE.input4), ) assert tA.depth == 0 assert tB.depth == 1 assert tC.depth == 2 assert tD.depth == 2 assert tE.depth == 3 nodes, edges = graph.dfsOnFinish() assert len(nodes) == 5 assert nodes[0] == tA assert nodes[-1] == tE assert len(edges) == 7 nodes, edges = graph.dfsOnFinish(startNodes=[tE]) assert len(nodes) == 5 assert nodes[0] == tA assert nodes[-1] == tE assert len(edges) == 7 nodes, edges = graph.dfsOnFinish(startNodes=[tD]) assert len(nodes) == 3 assert nodes[0] == tA assert nodes[1] == tB assert nodes[2] == tD assert len(edges) == 2 nodes, edges = graph.dfsOnFinish(startNodes=[tB]) assert len(nodes) == 2 assert nodes[0] == tA assert nodes[-1] == tB assert len(edges) == 1
def test_inputLinkInvalidation(): """ Input links should not change the invalidation. """ graph = Graph('') n1 = graph.addNewNode('SampleNode') n2 = graph.addNewNode('SampleNode') graph.addEdges((n1.input, n2.input)) assert n1.input.uid() == n2.input.uid() assert n1.output.value == n2.output.value
def test_depth(): graph = Graph('Tests tasks depth') tA = graph.addNewNode('Ls', input='/tmp') tB = graph.addNewNode('AppendText', inputText='echo B') tC = graph.addNewNode('AppendText', inputText='echo C') graph.addEdges( (tA.output, tB.input), (tB.output, tC.input), ) assert tA.depth == 0 assert tB.depth == 1 assert tC.depth == 2
def test_transitive_reduction(): graph = Graph('Tests tasks depth') tA = graph.addNewNode('Ls', input='/tmp') tB = graph.addNewNode('AppendText', inputText='echo B') tC = graph.addNewNode('AppendText', inputText='echo C') tD = graph.addNewNode('AppendText', inputText='echo D') tE = graph.addNewNode('AppendFiles') # C # / \ # /---/---->\ # A -> B ---> E # \ / # \ / # D graph.addEdges( (tA.output, tE.input), (tA.output, tB.input), (tB.output, tC.input), (tB.output, tD.input), (tB.output, tE.input4), (tC.output, tE.input3), (tD.output, tE.input2), ) edgesScore = graph.dfsMaxEdgeLength() flowEdges = graph.flowEdges() flowEdgesRes = [(tB, tA), (tD, tB), (tC, tB), (tE, tD), (tE, tC), ] assert set(flowEdgesRes) == set(flowEdges) assert len(graph._nodesMinMaxDepths) == len(graph.nodes) for node, (minDepth, maxDepth) in graph._nodesMinMaxDepths.items(): assert node.depth == maxDepth
def test_depth_diamond_graph(): graph = Graph('Tests tasks depth') tA = graph.addNewNode('Ls', input='/tmp') tB = graph.addNewNode('AppendText', inputText='echo B') tC = graph.addNewNode('AppendText', inputText='echo C') tD = graph.addNewNode('AppendFiles') graph.addEdges( (tA.output, tB.input), (tA.output, tC.input), (tB.output, tD.input), (tC.output, tD.input2), ) assert tA.depth == 0 assert tB.depth == 1 assert tC.depth == 1 assert tD.depth == 2 nodes, edges = graph.dfsOnFinish() assert len(nodes) == 4 assert nodes[0] == tA assert nodes[-1] == tD assert len(edges) == 4 nodes, edges = graph.dfsOnFinish(startNodes=[tD]) assert len(nodes) == 4 assert nodes[0] == tA assert nodes[-1] == tD assert len(edges) == 4 nodes, edges = graph.dfsOnFinish(startNodes=[tB]) assert len(nodes) == 2 assert nodes[0] == tA assert nodes[-1] == tB assert len(edges) == 1