def test_simple(self): ''' 3 -> 2 -> 1 ''' expected = [3, 2, 1] edges = {2: [1], 3: [2]} self.assertEqual(expected, utils.nodes_by_path(edges))
def test_order1(self): ''' 1 ──> 2 ─┬─> 3 ──> 7 └─> 4 ──> 5 ──> 6 ''' expected = [1, 2, 3, 7, 4, 5, 6] edges = {1: [2], 2: [3, 4], 4: [5], 5: [6], 3: [7]} actual = utils.nodes_by_path(edges) self.assertEqual(expected, actual)
def test_loop(self): ''' 1 ─┬─> 2 ──┬─> 3 ──> 5 │ │ └── 4 <─┘ NOTE: Loops and everything down stream are lost ''' expected = [1] edges = {1: [2], 2: [3, 4], 3: [5], 4: [2]} actual = utils.nodes_by_path(edges) # paths are kept togeather but order is not guaranted self.assertEqual(expected, actual)
def test_shared_node(self): ''' 1 ─┐ ┌─> 3 ├─> 2 ─┤ 4 ─┘ └─> 6 ''' edges = {1: [2], 2: [3, 6], 4: [2]} actual = utils.nodes_by_path(edges) # branches are arbitrarily ordered each side of the shared node self.assertIn(1, actual[0:2]) self.assertIn(4, actual[0:2]) self.assertIn(2, actual[2:3]) self.assertIn(3, actual[3:6]) self.assertIn(6, actual[3:6])
def test_extra2(self): ''' Two separate lists are extracted if the paths do not connect 1 ──> 2 ──> 3 4 ──> 5 ──> 6 ''' expected1 = [1, 2, 3] expected2 = [4, 5, 6] edges = {1: [2], 2: [3], 4: [5], 5: [6]} actual = utils.nodes_by_path(edges) # paths are kept togeather but order is not guaranted self.assertIn(expected1, [actual[0:3], actual[3:7]]) self.assertIn(expected2, [actual[0:3], actual[3:7]])
elif ((elements[tgtId]['feature'] == selectedFeature['name'] and elements[srcId]['feature'] != selectedFeature['name']) or (elements[srcId]['feature'] == selectedFeature['name'] and elements[tgtId]['feature'] != selectedFeature['name'])): # inter-feature link - encode and save as a comment comment = utils.encode_inter_feature_link( elements[srcId]['feature'], elements[srcId]['scenario'], elements[srcId]['keyword'], elements[srcId]['text'], elements[tgtId]['feature'], elements[tgtId]['scenario'], elements[tgtId]['keyword'], elements[tgtId]['text']) featureDoc['comments'].append(comment) # Now for each section take their nodes and sort them. sorted_nodes = utils.nodes_by_path(edgesInFeature) for c in selectedFeature["children"]: ret = [] found = False for s in sorted_nodes: if s in c["steps"]: found = True ret.append(elements[s]) c["steps"] = ret if not found: raise NotImplementedError(""" Unable to place all items in the section Ensure that there are no loops, and background is connected to at least one scenario """)