def test_default_indentation(self):
   for indent in ('  ', '    ', '\t'):
     src ='def a():\n' + indent + 'b\n'
     t = pasta.parse(src)
     t.body.extend(ast.parse('def c(): d').body)
     self.assertEqual(codegen.to_str(t),
                      src + 'def c():\n' + indent + 'd\n')
Exemple #2
0
 def test(self):
   with open(filepath, 'r') as handle:
     src = handle.read()
   t = ast_utils.parse(src)
   annotator = annotate.AstAnnotator(src)
   annotator.visit(t)
   self.assertMultiLineEqual(codegen.to_str(t), src)
   self.assertEqual([], annotator.tokens._parens, 'Unmatched parens')
 def test_autoindent(self):
     src = textwrap.dedent('''\
     def a():
         b
         c
     ''')
     expected = textwrap.dedent('''\
     def a():
         b
         new_node
     ''')
     t = pasta.parse(src)
     # Repace the second node and make sure the indent level is corrected
     t.body[0].body[1] = ast.Expr(ast.Name(id='new_node'))
     self.assertMultiLineEqual(expected, codegen.to_str(t))
Exemple #4
0
 def test_autoindent(self):
     src = textwrap.dedent("""\
   def a():
       b
       c
   """)
     expected = textwrap.dedent("""\
   def a():
       b
       new_node
   """)
     t = pasta.parse(src, py_ver)
     # Repace the second node and make sure the indent level is corrected
     t.body[0].body[1] = pasta.ast(py_ver).Expr(
         pasta.ast(py_ver).Name(id='new_node'))
     self.assertMultiLineEqual(expected, codegen.to_str(t, py_ver))
Exemple #5
0
def dump(tree):
  return codegen.to_str(tree)
 def test(self):
   with open(input_file, 'r') as handle:
     src = handle.read()
   t = ast.parse(src)
   auto_formatted = codegen.to_str(t)
   self.assertMultiLineEqual(src, auto_formatted)