Ejemplo n.º 1
0
def test_faketree_add_assignment(patch, fake_tree, block):
    patch.object(FakeTree, 'assignment')
    patch.object(FakeTree, 'find_insert_pos', return_value=0)
    block.children = [1]
    block.child.return_value = None
    result = fake_tree.add_assignment('value', original_line=10)
    FakeTree.assignment.assert_called_with('value')
    assert block.children == [FakeTree.assignment(), 1]
    name = Token('NAME', FakeTree.assignment().path.child(0), line=10)
    assert result.data == 'path'
    assert result.children == [name]
Ejemplo n.º 2
0
def test_faketree_add_assignment_four_children_bottom(patch, fake_tree, block):
    patch.object(FakeTree, "assignment")
    patch.object(FakeTree, "find_insert_pos", return_value=-1)
    block.children = ["c1", "c2", "c3", fake_tree.block.last_child()]
    fake_tree.add_assignment("value", original_line=42)
    expected = ["c1", "c2", "c3", FakeTree.assignment(), block.last_child()]
    assert block.children == expected
Ejemplo n.º 3
0
def test_faketree_add_assignment_four_children_bottom(patch, fake_tree, block):
    patch.object(FakeTree, 'assignment')
    patch.object(FakeTree, 'find_insert_pos', return_value=-1)
    block.children = ['c1', 'c2', 'c3', fake_tree.block.last_child()]
    fake_tree.add_assignment('value', original_line=42)
    expected = ['c1', 'c2', 'c3', FakeTree.assignment(), block.last_child()]
    assert block.children == expected
Ejemplo n.º 4
0
def test_faketree_add_assignment(patch, fake_tree, block):
    patch.object(FakeTree, 'assignment')
    patch.object(Tree, 'create_token_from_tok')
    patch.object(FakeTree, 'find_insert_pos', return_value=0)
    block.children = [1]
    block.child.return_value = None
    result = fake_tree.add_assignment('value', original_line=10)
    FakeTree.assignment.assert_called_with('value')
    assert block.children == [FakeTree.assignment(), 1]
    path_tok = FakeTree.assignment().path.child(0)
    Tree.create_token_from_tok.assert_called_with(path_tok, 'NAME',
                                                  path_tok.value)
    name = Tree.create_token_from_tok()
    name.line = 10
    assert result.data == 'path'
    assert result.children == [name]
Ejemplo n.º 5
0
def test_faketree_add_assignment(patch, fake_tree, block):
    patch.object(FakeTree, "assignment")
    patch.object(Tree, "create_token_from_tok")
    patch.object(FakeTree, "find_insert_pos", return_value=0)
    block.children = [1]
    block.child.return_value = None
    result = fake_tree.add_assignment("value", original_line=10)
    FakeTree.assignment.assert_called_with("value")
    assert block.children == [FakeTree.assignment(), 1]
    path_tok = FakeTree.assignment().path.child(0)
    Tree.create_token_from_tok.assert_called_with(
        path_tok, "NAME", path_tok.value
    )
    name = Tree.create_token_from_tok()
    name.line = 10
    assert result.data == "path"
    assert result.children == [name]