示例#1
0
def test_edge_identity():
    """Edges created with the same parameters are identical."""
    e1 = Edge('n', 3, 4)
    e2 = Edge('n', 2, 6)
    assert e1 == e1
    assert not (e1 != e1)
    assert not (e1 != Edge('n', 3, 4))
    assert e1 != e2
示例#2
0
    def test_graph_add(self):
        e1 = self.graph.add(Edge('', 1, 1))
        self.assertListEqual([e1], self.graph.edges)

        e2 = self.graph.add(Edge('', 3, 1))
        self.assertEqual(2, len(self.graph))
        self.assertListEqual([e1, e2], self.graph.edges)

        self.graph.add(Edge('', 3, 1))
        self.assertEqual(2, len(self.graph))
示例#3
0
def test_connect():
    """
    This test assures that a connection is being made from Edge 1 to 2.
    """
    graph = Graph('')
    e1 = graph.add(Edge('', 1, 1))
    e2 = graph.add(Edge('', 2, 1))
    graph.connect(e1, e2)
    assert graph[e2] == []
    assert graph[e1] == [e2]
示例#4
0
def test_can_t_connect_twice():
    """
    This test assures that edges which already have been connected will
    not result in an additional edge again.
    """
    graph = Graph('')
    e1 = Edge('', 1, 1)
    e2 = Edge('', 1, 2)
    for i in range(5):
        graph.connect(e1, e2)

    assert graph[e1] == [e2]
示例#5
0
def test_does_not_prematurely_delete_dependencies():
    """
    This test assures, that dependencies are not prematurely deleted
    during the visiting process.

    Example: Starting with the slice criterion *c* in c = 2 * b, the
    dependency tree includes the assignments to the variable a two lines
    down.
    """
    start = Edge('c', 29, 4)
    result = get_sliced_testdata('binsearch.py', start)
    assert Edge('a', 27, 4) not in result
    assert Edge('a', 31, 4) in result
示例#6
0
def test_no_overlapping_slice_result():
    """
    Test verifies, that slice result does not include independent
    functions if the naming of the variables is the same.
    """
    start = Edge('a', 2, 4)
    result = get_sliced_testdata('overlapping.py', start)
    expected = [
        start,
        Edge('a', 3, 8),
        Edge('a', 4, 11),
        Edge('a', 3, 4),
    ]
    assert expected == result
示例#7
0
def test_fix_issue_1_slices_a():
    """
    This test assures that the slice criterion starting whith `a = 1`
    includes all the additional dependencies, which are basically
    assignments to `a`.
    """
    start = Edge('a', 27, 4)
    result = get_sliced_testdata('binsearch.py', start)

    expected = [
        start,
        Edge('a', 30, 8),
        Edge('a', 31, 8),
        Edge('a', 32, 8),
        Edge('a', 34, 11),
        Edge('a', 30, 4),
        Edge('a', 31, 4),
        Edge('a', 32, 4),
        Edge('a', 33, 4),
    ]
    assert expected == result
示例#8
0
 def test_graph__getitem__(self):
     data = ('n', 1, 1)
     self.graph.add(Edge(*data))
     self.assertListEqual([], self.graph[Edge(*data)])
示例#9
0
 def test_graph_in(self):
     data = ('n', 1, 1)
     self.graph.add(Edge(*data))
     e2 = Edge(*data)
     self.assertTrue(e2 in self.graph)
示例#10
0
def test_edge_create_from_astnode():
    node = ast.Name('n', 0)
    node.col_offset = 0
    node.lineno = 0
    edge = Edge.create_from_astnode(node)
    assert ('n', 0, 0) == (edge.name, edge.lineno, edge.column)
示例#11
0
def test_repr():
    graph = Graph('foo')
    graph.add(Edge('o', 3, 4))
    expected = '<Graph foo [(<Edge o at #3@4>, [])]>'
    assert expected == repr(graph)
示例#12
0
def test_edge_create_from_astnode():
    node = ast.Name("n", 0)
    node.col_offset = 0
    node.lineno = 0
    edge = Edge.create_from_astnode(node)
    assert ("n", 0, 0) == (edge.name, edge.lineno, edge.column)
示例#13
0
def test_slices_over_while_and_branches():
    """
    Tests that the slice result includes items in the while and if
    constructs.
    """
    start = Edge('min', 12, 4)
    result = get_sliced_testdata('binsearch.py', start)
    expected = [
        start,
        Edge('min', 15, 14),
        Edge('min', 15, 37),
        Edge('min', 16, 18),
        Edge('min', 16, 31),
        Edge('mid', 16, 8),
        Edge('mid', 17, 23),
        Edge('mid', 19, 18),
        Edge('mid', 21, 18),
        Edge('mid', 23, 19),
        Edge('x', 17, 8),
        Edge('max', 19, 12),
        Edge('min', 21, 12),
        Edge('x', 18, 11),
        Edge('x', 20, 13),
        Edge('x', 22, 13),
        Edge('max', 16, 25),
    ]
    assert Edge('x', 14, 4) not in result
    assert expected == result