Beispiel #1
0
 def test_long_integer_literals(self):
     source = "0x1L + a"
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'BinOp', ['Num' , ' ', '+', ' ', 'Name'])
     checker.check_children('Num', ['0x1L'])
Beispiel #2
0
 def test_basic_opening_double(self):
     source = '1 + ((2))\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children(
         'BinOp', ['Num', ' ', '+', ' ((', 'Num', '))'])
Beispiel #3
0
 def test_if_exp_node(self):
     source = '1 if True else 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'IfExp', ['Num', ' ', 'if', ' ', 'Name', ' ', 'else',
                   ' ', 'Num'])
Beispiel #4
0
 def test_complex_number_literals(self):
     source = "1.0e2j + a"
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'BinOp', ['Num' , ' ', '+', ' ', 'Name'])
     checker.check_children('Num', ['1.0e2j'])
Beispiel #5
0
 def test_basic_opening_biway(self):
     source = '(1) + (2)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children(
         'BinOp', ['(', 'Num', ') ', '+', ' (', 'Num', ')'])
Beispiel #6
0
 def test_with_node(self):
     source = 'from __future__ import with_statement\nwith a as b:\n    pass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'With', ['with', ' ', 'Name', ' ', 'as', ' ', 'Name', '', ':',
                  '\n    ', 'Pass'])
Beispiel #7
0
 def test_try_except_and_finally_node(self):
     source = 'try:\n    pass\nexcept:\n    pass\nfinally:\n    pass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'TryFinally', ['TryExcept', '\n', 'finally',
                        '', ':', '\n    ', 'Pass'])
Beispiel #8
0
 def test_while_node(self):
     source = 'while True:\n    pass\nelse:\n    pass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'While', ['while', ' ', 'Name', '', ':', '\n    ', 'Pass', '\n',
                   'else', '', ':', '\n    ', 'Pass'])
Beispiel #9
0
 def test_basic_closing_parens(self):
     source = '1 + (2)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children(
         'BinOp', ['Num', ' ', '+', ' (', 'Num', ')'])
Beispiel #10
0
 def test_and_node(self):
     source = 'True and True\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BoolOp', 0, len(source) - 1)
     checker.check_children(
         'BoolOp', ['Name', ' ', 'and', ' ', 'Name'])
Beispiel #11
0
 def test_simple_subscript(self):
     source = 'a[1]\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'Subscript', ['Name', '', '[', '', 'Index', '', ']'])
     checker.check_children('Index', ['Num'])
Beispiel #12
0
 def test_module_node(self):
     source = '"""docs"""\npass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Module', 0, len(source))
     checker.check_children('Module', ['', 'Expr', '\n', 'Pass', '\n'])
     checker.check_children('Str', ['"""docs"""'])
Beispiel #13
0
 def test_print_node(self):
     source = 'print >>out, 1,\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Print', 0, len(source) - 1)
     checker.check_children('Print', ['print', ' ', '>>', '', 'Name', '',
                                      ',', ' ', 'Num', '', ','])
Beispiel #14
0
 def test_lshift_node(self):
     source = '1 << 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children(
         'BinOp', ['Num', ' ', '<<', ' ', 'Num'])
Beispiel #15
0
 def test_list_node(self):
     source = '[1, 2]\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('List', 0, len(source) - 1)
     checker.check_children(
         'List', ['[', '', 'Num', '', ',', ' ', 'Num', '', ']'])
Beispiel #16
0
 def test_gen_expr_node2(self):
     source = 'zip(i for i in range(1) if i == 1)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'comprehension', ['for', ' ', 'Name', ' ', 'in', ' ', 'Call',
                           ' ', 'if', ' ', 'Compare'])
Beispiel #17
0
 def test_import_node(self):
     source = 'import a, b as c\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Import', 0, len(source) - 1)
     checker.check_children(
         'Import', ['import', ' ', 'alias', '', ',', ' ', 'alias'])
Beispiel #18
0
 def test_function_node(self):
     source = 'def f():\n    pass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Function', 0, len(source) - 1)
     checker.check_children('Function', ['def', ' ', 'f', '', '(', '', 'arguments', '',
                                         ')', '', ':', '\n    ', 'Pass'])
Beispiel #19
0
 def test_gen_expr_node_handling_surrounding_parens(self):
     source = '(i for i in x)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('GeneratorExp', 0, len(source) - 1)
     checker.check_children(
         'GeneratorExp', ['(', '', 'Name', ' ', 'comprehension', '', ')'])
Beispiel #20
0
 def test_class_with_no_bases(self):
     source = 'class A:\n    pass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Class', 0, len(source) - 1)
     checker.check_children(
         'Class', ['class', ' ', 'A', '', ':', '\n    ', 'Pass'])
Beispiel #21
0
 def test_simple_compare(self):
     source = '1 < 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Compare', 0, len(source) - 1)
     checker.check_children(
         'Compare', ['Num', ' ', '<', ' ', 'Num'])
Beispiel #22
0
 def test_call_func_and_both_varargs_and_kwargs(self):
     source = 'f(*args, **kwds)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'Call', ['Name', '', '(', '', '*', '', 'Name', '', ',',
                  ' ', '**', '', 'Name', '', ')'])
Beispiel #23
0
 def test_call_func_and_keywords(self):
     source = 'f(1, p=2)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'Call', ['Name', '', '(', '', 'Num', '', ',',
                  ' ', 'keyword', '', ')'])
Beispiel #24
0
 def test_back_quotenode(self):
     source = '`1`\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Repr', 0, len(source) - 1)
     checker.check_children(
         'Repr', ['`', '', 'Num', '', '`'])
Beispiel #25
0
 def test_bitand(self):
     source = '1 & 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children(
         'BinOp', ['Num', ' ', '&', ' ', 'Num'])
Beispiel #26
0
 def test_ass_tuple2(self):
     source = '(a, b) = range(2)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Tuple', 0, source.index('=') - 1)
     checker.check_children(
         'Tuple', ['(', '', 'Name', '', ',', ' ', 'Name', '', ')'])
Beispiel #27
0
 def test_assert2(self):
     source = 'assert True, "error"\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Assert', 0, len(source) - 1)
     checker.check_children(
         'Assert', ['assert', ' ', 'Name', '', ',', ' ', 'Str'])
Beispiel #28
0
 def test_call_func_and_start_args(self):
     source = 'f(1, *args)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'Call', ['Name', '', '(', '', 'Num', '', ',',
                  ' ', '*', '', 'Name', '', ')'])
Beispiel #29
0
 def test_ass_list_node(self):
     source = '[a, b] = 1, 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('List', 0, source.index(']') + 1)
     checker.check_children('List', ['[', '', 'Name', '', ',',
                                     ' ', 'Name', '', ']'])
Beispiel #30
0
 def test_ass_name_node(self):
     source = 'a = 10\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     start = source.index('a')
     checker.check_region('Name', start, start + 1)
     checker.check_children('Name', ['a'])
Beispiel #31
0
 def test_if_exp_node(self):
     source = '1 if True else 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'IfExp', ['Num', ' ', 'if', ' ', 'Name', ' ', 'else', ' ', 'Num'])
Beispiel #32
0
 def test_basic_closing_parens(self):
     source = '1 + (2)\n'
     ast_frag = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast_frag)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children('BinOp', ['Num', ' ', '+', ' (', 'Num', ')'])
Beispiel #33
0
 def test_and_node(self):
     source = 'True and True\n'
     ast_frag = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast_frag)
     checker.check_region('BoolOp', 0, len(source) - 1)
     checker.check_children('BoolOp', ['Name', ' ', 'and', ' ', 'Name'])
Beispiel #34
0
 def test_lshift_node(self):
     source = '1 << 2\n'
     ast_frag = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast_frag)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children('BinOp', ['Num', ' ', '<<', ' ', 'Num'])
Beispiel #35
0
 def test_handling_comments(self):
     source = '(1 + #(\n2)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('BinOp', ['Num', ' ', '+', ' #(\n', 'Num'])
Beispiel #36
0
 def test_basic_opening_double(self):
     source = '1 + ((2))\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children('BinOp', ['Num', ' ', '+', ' ((', 'Num', '))'])
Beispiel #37
0
 def test_delete_node(self):
     source = 'del a, b\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Delete',
                            ['del', ' ', 'Name', '', ',', ' ', 'Name'])
Beispiel #38
0
 def test_how_to_handle_old_not_equals(self):
     source = '1 <> 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Compare', ['Num', ' ', '<>', ' ', 'Num'])
Beispiel #39
0
 def test_simple_sliceobj(self):
     source = 'a[1::3]\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Slice', ['Num', '', ':', '', ':', '', 'Num'])
Beispiel #40
0
 def test_semicolon(self):
     source = '1;\n'
     ast = patchedast.get_patched_ast(source, True)
Beispiel #41
0
 def test_ignoring_comments(self):
     source = '#1\n1\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     start = source.rindex('1')
     checker.check_region('Num', start, start + 1)
Beispiel #42
0
 def test_ignoring_strings_that_start_with_a_char(self):
     source = 'r"""("""\n1\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Module', ['', 'Expr', '\n', 'Expr', '\n'])
Beispiel #43
0
 def test_empty_tuple_node(self):
     source = '()\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Tuple', ['(', '', ')'])
Beispiel #44
0
 def test_basic_opening_parens(self):
     source = '(1) + 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children('BinOp', ['(', 'Num', ') ', '+', ' ', 'Num'])
Beispiel #45
0
 def test_empty_return_node(self):
     source = 'def f():\n    return\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Return', ['return'])
Beispiel #46
0
 def test_yield_node(self):
     source = 'def f():\n    yield None\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Yield', ['yield', ' ', 'Name'])
Beispiel #47
0
 def test_not_and_or_nodes(self):
     source = 'not True or False\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Expr', ['BoolOp'])
     checker.check_children('BoolOp', ['UnaryOp', ' ', 'or', ' ', 'Name'])
Beispiel #48
0
 def test_tuple_node2(self):
     source = '#(\n1, 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('Tuple', ['Num', '', ',', ' ', 'Num'])
Beispiel #49
0
 def test_ext_slice_node(self):
     source = 'x = xs[0,:]\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('ExtSlice', 7, len(source) - 2)
     checker.check_children('ExtSlice', ['Index', '', ',', '', 'Slice'])
Beispiel #50
0
 def test_printnl_node(self):
     source = 'print 1\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Print', 0, len(source) - 1)
     checker.check_children('Print', ['print', ' ', 'Num'])
Beispiel #51
0
 def test_add_node(self):
     source = '1 + 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('BinOp', 0, len(source) - 1)
     checker.check_children('BinOp', ['Num', ' ', '+', ' ', 'Num'])
Beispiel #52
0
 def test_simple_module_node(self):
     source = 'pass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Module', 0, len(source))
     checker.check_children('Module', ['', 'Pass', '\n'])
Beispiel #53
0
 def test_both_varargs_and_kwargs(self):
     source = 'def f(*args, **kwds):\n    pass\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'arguments', ['*', '', 'args', '', ',', ' ', '**', '', 'kwds'])
Beispiel #54
0
 def test_get_attr_node(self):
     source = 'a.b\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Attribute', 0, len(source) - 1)
     checker.check_children('Attribute', ['Name', '', '.', '', 'b'])
Beispiel #55
0
 def test_call_func_and_only_dstart_args(self):
     source = 'f(**kwds)\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children(
         'Call', ['Name', '', '(', '', '**', '', 'Name', '', ')'])
Beispiel #56
0
 def test_simple_exec_node(self):
     source = 'exec ""\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Exec', 0, len(source) - 1)
     checker.check_children('Exec', ['exec', ' ', 'Str'])
Beispiel #57
0
 def test_integer_literals_and_sorted_children(self):
     source = 'a = 10\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     start = source.index('10')
     checker.check_children('Num', ['10'])
Beispiel #58
0
 def test_simple_compare(self):
     source = '1 < 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Compare', 0, len(source) - 1)
     checker.check_children('Compare', ['Num', ' ', '<', ' ', 'Num'])
Beispiel #59
0
 def test_back_quotenode(self):
     source = '`1`\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_region('Repr', 0, len(source) - 1)
     checker.check_children('Repr', ['`', '', 'Num', '', '`'])
Beispiel #60
0
 def test_bitor(self):
     source = '1 | 2\n'
     ast = patchedast.get_patched_ast(source, True)
     checker = _ResultChecker(self, ast)
     checker.check_children('BinOp', ['Num', ' ', '|', ' ', 'Num'])