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 testCombinedConvenienceConstructors(self): randomChild = "hello" self.assertEquals( ParseNode(ParseNode.ARITH_EXPR, [ParseNode(ParseNode.TERM, [randomChild])]), ArithExpr_Term(randomChild)) self.assertEquals( ParseNode(ParseNode.EXPR, [ ParseNode(ParseNode.CONCAT_EXPR, [ParseNode(ParseNode.SHIFT_EXPR, [randomChild])]) ]), Expr_ConcatExpr_ShiftExpr(randomChild)) self.assertEquals( ParseNode(ParseNode.FACTOR, [ ParseNode(ParseNode.POWER, [ ParseNode(ParseNode.FL_REFERENCE, [ParseNode(ParseNode.ATOM, [randomChild])]) ]) ]), Factor_Power_FLReference_Atom(randomChild)) self.assertEquals( ParseNode(ParseNode.TEST, [ ParseNode(ParseNode.AND_TEST, [ ParseNode(ParseNode.NOT_TEST, [ParseNode(ParseNode.COMPARISON, [randomChild])]) ]) ]), Test_AndTest_NotTest_Comparison(randomChild)) self.assertEquals( ParseNode(ParseNode.EXPR, [ ParseNode(ParseNode.CONCAT_EXPR, [ ParseNode(ParseNode.SHIFT_EXPR, [ ParseNode(ParseNode.ARITH_EXPR, [ ParseNode(ParseNode.TERM, [ ParseNode(ParseNode.FACTOR, [ ParseNode(ParseNode.POWER, [ ParseNode(ParseNode.FL_REFERENCE, [ ParseNode(ParseNode.ATOM, [ ParseNode( ParseNode.NAME, [randomChild]) ]) ]) ]) ]) ]) ]) ]) ]) ]), ExprFromNameChild(randomChild)) self.assertEquals( ParseNode(ParseNode.EXPR, [ ParseNode(ParseNode.CONCAT_EXPR, [ ParseNode(ParseNode.SHIFT_EXPR, [ ParseNode(ParseNode.ARITH_EXPR, [ ParseNode(ParseNode.TERM, [ ParseNode(ParseNode.FACTOR, [ ParseNode(ParseNode.POWER, [ ParseNode(ParseNode.FL_REFERENCE, [ ParseNode(ParseNode.ATOM, [randomChild]) ]) ]) ]) ]) ]) ]) ]) ]), ExprFromAtomChild(randomChild)) self.assertEquals( ParseNode(ParseNode.TEST, [ ParseNode(ParseNode.AND_TEST, [ ParseNode(ParseNode.NOT_TEST, [ ParseNode(ParseNode.COMPARISON, [ ParseNode(ParseNode.EXPR, [ ParseNode(ParseNode.CONCAT_EXPR, [ ParseNode(ParseNode.SHIFT_EXPR, [ ParseNode(ParseNode.ARITH_EXPR, [ ParseNode(ParseNode.TERM, [ ParseNode( ParseNode.FACTOR, [ ParseNode( ParseNode.POWER, [ ParseNode( ParseNode. FL_REFERENCE, [ ParseNode( ParseNode . ATOM, [ randomChild ]) ]) ]) ]) ]) ]) ]) ]) ]) ]) ]) ]) ]), TestFromAtomChild(randomChild)) self.assertEquals( ParseNode(ParseNode.TEST, [ ParseNode(ParseNode.AND_TEST, [ ParseNode(ParseNode.NOT_TEST, [ ParseNode(ParseNode.COMPARISON, [ ParseNode(ParseNode.EXPR, [ ParseNode(ParseNode.CONCAT_EXPR, [ ParseNode(ParseNode.SHIFT_EXPR, [ ParseNode(ParseNode.ARITH_EXPR, [ ParseNode(ParseNode.TERM, [ ParseNode( ParseNode.FACTOR, [ ParseNode( ParseNode.POWER, [randomChild]) ]) ]) ]) ]) ]) ]) ]) ]) ]) ]), TestFromPowerChild(randomChild))
def testSimpleConvenienceConstructors(self): randomList = ["foo", "bar", 27] self.assertEquals(ParseNode(ParseNode.AND_TEST, randomList), AndTest(randomList)) self.assertEquals(ParseNode(ParseNode.ARG_LIST, randomList), ArgList(randomList)) self.assertEquals(ParseNode(ParseNode.ARGUMENT, randomList), Argument(randomList)) self.assertEquals(ParseNode(ParseNode.ARITH_EXPR, randomList), ArithExpr(randomList)) self.assertEquals(ParseNode(ParseNode.ATOM, randomList), Atom(randomList)) self.assertEquals(ParseNode(ParseNode.COMPARISON, randomList), Comparison(randomList)) self.assertEquals(ParseNode(ParseNode.COMP_OPERATOR, randomList), CompOperator(randomList)) self.assertEquals(ParseNode(ParseNode.CONCAT_EXPR, randomList), ConcatExpr(randomList)) self.assertEquals(ParseNode(ParseNode.DICT_MAKER, randomList), DictMaker(randomList)) self.assertEquals(ParseNode(ParseNode.EXPR, randomList), Expr(randomList)) self.assertEquals(ParseNode(ParseNode.EXPR_LIST, randomList), ExprList(randomList)) self.assertEquals(ParseNode(ParseNode.FACTOR, randomList), Factor(randomList)) self.assertEquals(FLCellRangeParseNode(randomList), FLCellRange(randomList)) self.assertEquals(FLCellReferenceParseNode(randomList), FLCellReference(randomList)) self.assertEquals(FLColumnReferenceParseNode(randomList), FLColumnReference(randomList)) self.assertEquals(FLRowReferenceParseNode(randomList), FLRowReference(randomList)) self.assertEquals(ParseNode(ParseNode.FL_DDE_CALL, randomList), FLDDECall(randomList)) self.assertEquals( ParseNode(ParseNode.FL_DELETED_REFERENCE, randomList), FLDeletedReference(randomList)) self.assertEquals( ParseNode(ParseNode.FL_INVALID_REFERENCE, randomList), FLInvalidReference(randomList)) self.assertEquals( ParseNode(ParseNode.FL_NAKED_WORKSHEET_REFERENCE, randomList), FLNakedWorksheetReference(randomList)) self.assertEquals(ParseNode(ParseNode.FL_REFERENCE, randomList), FLReference(randomList)) self.assertEquals(ParseNode(ParseNode.FL_ROOT, randomList), FLRoot(randomList)) self.assertEquals(ParseNode(ParseNode.FP_DEF, randomList), FPDef(randomList)) self.assertEquals(ParseNode(ParseNode.FP_LIST, randomList), FPList(randomList)) self.assertEquals(ParseNode(ParseNode.GEN_FOR, randomList), GenFor(randomList)) self.assertEquals(ParseNode(ParseNode.GEN_IF, randomList), GenIf(randomList)) self.assertEquals(ParseNode(ParseNode.GEN_ITER, randomList), GenIter(randomList)) self.assertEquals(ParseNode(ParseNode.LAMBDEF, randomList), LambDef(randomList)) self.assertEquals(ParseNode(ParseNode.LIST_FOR, randomList), ListFor(randomList)) self.assertEquals(ParseNode(ParseNode.LIST_IF, randomList), ListIf(randomList)) self.assertEquals(ParseNode(ParseNode.LIST_ITER, randomList), ListIter(randomList)) self.assertEquals(ParseNode(ParseNode.LIST_MAKER, randomList), ListMaker(randomList)) self.assertEquals(ParseNode(ParseNode.NAME, randomList), Name(randomList)) self.assertEquals(ParseNode(ParseNode.NOT_TEST, randomList), NotTest(randomList)) self.assertEquals(ParseNode(ParseNode.NUMBER, randomList), Number(randomList)) self.assertEquals(ParseNode(ParseNode.POWER, randomList), Power(randomList)) self.assertEquals(ParseNode(ParseNode.SHIFT_EXPR, randomList), ShiftExpr(randomList)) self.assertEquals(ParseNode(ParseNode.SLICE_OP, randomList), SliceOp(randomList)) self.assertEquals(ParseNode(ParseNode.STRINGLITERAL, randomList), StringLiteral(randomList)) self.assertEquals(ParseNode(ParseNode.SUBSCRIPT, randomList), Subscript(randomList)) self.assertEquals(ParseNode(ParseNode.SUBSCRIPT_LIST, randomList), SubscriptList(randomList)) self.assertEquals(ParseNode(ParseNode.TERM, randomList), Term(randomList)) self.assertEquals(ParseNode(ParseNode.TEST, randomList), Test(randomList)) self.assertEquals(ParseNode(ParseNode.TEST_LIST, randomList), TestList(randomList)) self.assertEquals(ParseNode(ParseNode.TEST_LIST_GEXP, randomList), TestListGexp(randomList)) self.assertEquals(ParseNode(ParseNode.TRAILER, randomList), Trailer(randomList)) self.assertEquals(ParseNode(ParseNode.VAR_ARGS_LIST, randomList), VarArgsList(randomList))