Beispiel #1
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]
Beispiel #2
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]
Beispiel #3
0
    def add_assignment(self, value, original_line):
        """
        Creates an assignments and adds it to the current block
        Returns a fake path reference to this assignment
        """
        assert len(self.block.children) >= 1

        assignment = self.assignment(value)

        self.insert_node(assignment, original_line)

        # we need a new node, s.t. already inserted
        # fake nodes don't get changed
        path_tok = assignment.path.child(0)
        name = Tree.create_token_from_tok(path_tok, 'NAME', path_tok.value)
        name.line = original_line
        return Tree('path', [name])