Beispiel #1
0
    def testParseNodeShould(self):
        "test ParseNode should allow registering of node classes"

        class CustomParseNode(ParseNode):
            def __init__(self, children):
                ParseNode.__init__(self, "CUSTOM_NODE_TYPE", children)

        ParseNode.register_node_type("CUSTOM_NODE_TYPE", CustomParseNode)
        try:

            node = ParseNode.construct_node("CUSTOM_NODE_TYPE", [])
            self.assertEquals(
                type(node), CustomParseNode,
                "ParseNode.construct_node didn't dispatch to CustomParseNode")
            self.assertEquals(node.type, "CUSTOM_NODE_TYPE",
                              "Wrong type attribute")
            self.assertEquals(node.children, [], "Wrong children")

            node = ParseNode.construct_node("FISH BOWL", ["gox blamp"])
            self.assertEquals(
                type(node), ParseNode,
                "ParseNode.construct_node didn't fall back to ParseNode")
            self.assertEquals(node.type, "FISH BOWL", "Wrong type attribute")
            self.assertEquals(node.children, ["gox blamp"], "Wrong children")

            self.assertIsNotNone(ParseNode.classRegistry,
                                 "ParseNode didn't have a class registry")
        finally:
            del ParseNode.classRegistry["CUSTOM_NODE_TYPE"]
 def testRegisteredWithParse(self):
     "test registered with ParseNode"
     self.assertEquals(
         type(ParseNode.construct_node(
             ParseNode.FL_CELL_RANGE, ['a1', ':', 'b4'])),
         FLCellRangeParseNode,
         "Class is not registered with ParseNode")
Beispiel #3
0
 def testRegisteredWithParse(self):
     "test registered with ParseNode"
     self.assertEquals(
         type(
             ParseNode.construct_node(ParseNode.FL_CELL_RANGE,
                                      ['a1', ':', 'b4'])),
         FLCellRangeParseNode, "Class is not registered with ParseNode")
Beispiel #4
0
 def testRegisteredWithParse(self):
     "test registered with ParseNode"
     self.assertEquals(
         type(
             ParseNode.construct_node(ParseNode.FL_NAMED_COLUMN_REFERENCE,
                                      ['dfytjdky'])),
         FLNamedColumnReferenceParseNode,
         "Class is not registered with ParseNode")
Beispiel #5
0
    def test_rewrite_parse_node_should_return_parse_node_with_children_rewritten(
            self, mock_recursive_rewrite):
        node_type = "junk node type"
        children = [ParseNode(node_type, None), ParseNode(node_type, None)]
        input = ParseNode(node_type, children)

        mock_recursive_results = [object(), object()]

        def mock_recursive_results_generator_func(*args):
            yield mock_recursive_results[0]
            yield mock_recursive_results[1]

        mock_recursive_results_generator = mock_recursive_results_generator_func(
        )
        mock_recursive_rewrite.side_effect = lambda *_: mock_recursive_results_generator.next(
        )

        self.assertEquals(id(rewrite(input)), id(input))
        self.assertEquals(mock_recursive_rewrite.call_args_list,
                          [((children[0], ), {}), ((children[1], ), {})])
        self.assertEquals(input.children, mock_recursive_results)
    def testParseNodeShould(self):
        "test ParseNode should allow registering of node classes"
        class CustomParseNode(ParseNode):
            def __init__(self, children):
                ParseNode.__init__(self, "CUSTOM_NODE_TYPE", children)

        ParseNode.register_node_type("CUSTOM_NODE_TYPE", CustomParseNode)
        try:

            node = ParseNode.construct_node("CUSTOM_NODE_TYPE", [])
            self.assertEquals(type(node), CustomParseNode, "ParseNode.construct_node didn't dispatch to CustomParseNode")
            self.assertEquals(node.type, "CUSTOM_NODE_TYPE", "Wrong type attribute")
            self.assertEquals(node.children, [], "Wrong children")


            node = ParseNode.construct_node("FISH BOWL", ["gox blamp"])
            self.assertEquals(type(node), ParseNode, "ParseNode.construct_node didn't fall back to ParseNode")
            self.assertEquals(node.type, "FISH BOWL", "Wrong type attribute")
            self.assertEquals(node.children, ["gox blamp"], "Wrong children")


            self.assertIsNotNone(ParseNode.classRegistry, "ParseNode didn't have a class registry")
        finally:
            del ParseNode.classRegistry["CUSTOM_NODE_TYPE"]
def FLDDECall(children):
    return ParseNode.construct_node(ParseNode.FL_DDE_CALL, children)
def ArithExpr(children):
    return ParseNode.construct_node(ParseNode.ARITH_EXPR, children)
def Name(children):
    return ParseNode.construct_node(ParseNode.NAME, children)
def ListFor(children):
    return ParseNode.construct_node(ParseNode.LIST_FOR, children)
def GenFor(children):
    return ParseNode.construct_node(ParseNode.GEN_FOR, children)
def ExprList(children):
    return ParseNode.construct_node(ParseNode.EXPR_LIST, children)
def Comparison(children):
    return ParseNode.construct_node(ParseNode.COMPARISON, children)
Beispiel #14
0
def DictMaker(children):
    return ParseNode.construct_node(ParseNode.DICT_MAKER, children)
Beispiel #15
0
def CompOperator(children):
    return ParseNode.construct_node(ParseNode.COMP_OPERATOR, children)
Beispiel #16
0
def Comparison(children):
    return ParseNode.construct_node(ParseNode.COMPARISON, children)
Beispiel #17
0
def FLRoot(children):
    return ParseNode.construct_node(ParseNode.FL_ROOT, children)
Beispiel #18
0
def FLReference(children):
    return ParseNode.construct_node(ParseNode.FL_REFERENCE, children)
Beispiel #19
0
def FLNakedWorksheetReference(children):
    return ParseNode.construct_node(ParseNode.FL_NAKED_WORKSHEET_REFERENCE,
                                    children)
def FLInvalidReference(children):
    return ParseNode.construct_node(ParseNode.FL_INVALID_REFERENCE, children)
def FLReference(children):
    return ParseNode.construct_node(ParseNode.FL_REFERENCE, children)
Beispiel #22
0
def ExprList(children):
    return ParseNode.construct_node(ParseNode.EXPR_LIST, children)
def DictMaker(children):
    return ParseNode.construct_node(ParseNode.DICT_MAKER, children)
Beispiel #24
0
def Factor(children):
    return ParseNode.construct_node(ParseNode.FACTOR, children)
def FPDef(children):
    return ParseNode.construct_node(ParseNode.FP_DEF, children)
Beispiel #26
0
def FPDef(children):
    return ParseNode.construct_node(ParseNode.FP_DEF, children)
def GenIter(children):
    return ParseNode.construct_node(ParseNode.GEN_ITER, children)
Beispiel #28
0
def FPList(children):
    return ParseNode.construct_node(ParseNode.FP_LIST, children)
def ListIter(children):
    return ParseNode.construct_node(ParseNode.LIST_ITER, children)
Beispiel #30
0
def GenFor(children):
    return ParseNode.construct_node(ParseNode.GEN_FOR, children)
Beispiel #31
0
def FLInvalidReference(children):
    return ParseNode.construct_node(ParseNode.FL_INVALID_REFERENCE, children)
Beispiel #32
0
def GenIf(children):
    return ParseNode.construct_node(ParseNode.GEN_IF, children)
def Atom(children):
    return ParseNode.construct_node(ParseNode.ATOM, children)
Beispiel #34
0
    localReference = property(__getLocalReference, __setLocalReference)

    @property
    def coords(self):
        return cell_name_to_coordinates(self.plainCellName)

    def offset(self, dx, dy, move_absolute=False):
        (col, row) = cell_name_to_coordinates(self.plainCellName)

        if move_absolute or not self.colAbsolute:
            col += dx
        if move_absolute or not self.rowAbsolute:
            row += dy

        newName = coordinates_to_cell_name(col,
                                           row,
                                           colAbsolute=self.colAbsolute,
                                           rowAbsolute=self.rowAbsolute)
        if newName is None:
            newName = "#Invalid!"

        self.localReference = newName + self.whitespace

    def canonicalise(self, wsNames):
        self.localReference = self.localReference.upper()
        FLReferenceParseNode.canonicalise(self, wsNames)


ParseNode.register_node_type(ParseNode.FL_CELL_REFERENCE,
                             FLCellReferenceParseNode)
def FLDeletedReference(children):
    return ParseNode.construct_node(ParseNode.FL_DELETED_REFERENCE, children)
Beispiel #36
0
 def __init__(self, nodeType, children):
     assert len(children) in (1, 3)
     ParseNode.__init__(self, nodeType, children)
def FLNakedWorksheetReference(children):
    return ParseNode.construct_node(ParseNode.FL_NAKED_WORKSHEET_REFERENCE, children)
Beispiel #38
0
    @property
    def rowIndex(self):
        return int(self.plainRowName)


    @property
    def coords(self):
        return 0, self.rowIndex


    def offset(self, _, count, moveAbsolute=False):
        if not moveAbsolute and self.isAbsolute:
            return
        newIndex = self.rowIndex + count
        if newIndex > 0:
            self.plainRowName = str(newIndex)
        else:
            self.localReference = '#Invalid!' + self.whitespace


    def __getLocalReference(self):
        return self.children[-1]
    def __setLocalReference(self, newRow):
        self.children[-1] = newRow
    localReference = property(__getLocalReference, __setLocalReference)


ParseNode.register_node_type(ParseNode.FL_ROW_REFERENCE, FLRowReferenceParseNode)

def FLRoot(children):
    return ParseNode.construct_node(ParseNode.FL_ROOT, children)
Beispiel #40
0
 def __init__(self, children):
     ParseNode.__init__(self, ParseNode.FL_ROW_REFERENCE, children)
def CompOperator(children):
    return ParseNode.construct_node(ParseNode.COMP_OPERATOR, children)
Beispiel #42
0
def Expr(children):
    return ParseNode.construct_node(ParseNode.EXPR, children)
def Expr(children):
    return ParseNode.construct_node(ParseNode.EXPR, children)
Beispiel #44
0
def Name(children):
    return ParseNode.construct_node(ParseNode.NAME, children)
def Factor(children):
    return ParseNode.construct_node(ParseNode.FACTOR, children)
Beispiel #46
0
def ShiftExpr(children):
    return ParseNode.construct_node(ParseNode.SHIFT_EXPR, children)
def FPList(children):
    return ParseNode.construct_node(ParseNode.FP_LIST, children)
Beispiel #48
0
def FLDDECall(children):
    return ParseNode.construct_node(ParseNode.FL_DDE_CALL, children)
def GenIf(children):
    return ParseNode.construct_node(ParseNode.GEN_IF, children)
Beispiel #50
0
 def __init__(self, children):
     ParseNode.__init__(self, "CUSTOM_NODE_TYPE", children)
def LambDef(children):
    return ParseNode.construct_node(ParseNode.LAMBDEF, children)
Beispiel #52
0
 def testRegisteredWithParse(self):
     "test registered with ParseNode"
     self.assertEquals(type(ParseNode.construct_node(ParseNode.FL_ROW_REFERENCE, [])), FLRowReferenceParseNode,
                       "Class is not registered with ParseNode")
def ListIf(children):
    return ParseNode.construct_node(ParseNode.LIST_IF, children)
Beispiel #54
0
class FLCellRangeParseNode(ParseNode):
    def __init__(self, children):
        assert len(children) == 3
        ParseNode.__init__(self, ParseNode.FL_CELL_RANGE, children)

    def __get_first_cell_reference(self):
        return self.children[0]

    def __set_first_cell_reference(self, cellRef):
        self.children[0] = cellRef

    first_cell_reference = property(__get_first_cell_reference,
                                    __set_first_cell_reference)

    def __get_second_cell_reference(self):
        return self.children[2]

    def __set_second_cell_reference(self, cellRef):
        self.children[2] = cellRef

    second_cell_reference = property(__get_second_cell_reference,
                                     __set_second_cell_reference)

    @property
    def colon(self):
        return self.children[1]


ParseNode.register_node_type(ParseNode.FL_CELL_RANGE, FLCellRangeParseNode)
def ListMaker(children):
    return ParseNode.construct_node(ParseNode.LIST_MAKER, children)
def Argument(children):
    return ParseNode.construct_node(ParseNode.ARGUMENT, children)
def AndTest(children):
    return ParseNode.construct_node(ParseNode.AND_TEST, children)
Beispiel #58
0
def FLDeletedReference(children):
    return ParseNode.construct_node(ParseNode.FL_DELETED_REFERENCE, children)
Beispiel #59
0
 def __init__(self, children):
     assert len(children) == 3
     ParseNode.__init__(self, ParseNode.FL_CELL_RANGE, children)
def ArgList(children):
    return ParseNode.construct_node(ParseNode.ARG_LIST, children)