def _ParseAndVisit(source): mod = pythonparser.parse(source) future_features = stmt.visit_future(mod) b = block.ModuleBlock('__main__', '<test>', source, future_features) visitor = stmt.StatementVisitor(b) visitor.visit(mod) return visitor
def _ParseAndVisit(source): mod = ast.parse(source) future_features = stmt.visit_future(mod) b = block.ModuleBlock('__main__', 'grumpy', 'grumpy/lib', '<test>', source.split('\n'), future_features) visitor = stmt.StatementVisitor(b) visitor.visit(mod) return visitor
def testVisitFuture(self): testcases = [ ('from __future__ import print_function', stmt.FUTURE_PRINT_FUNCTION, 1), ("""\ "module docstring" from __future__ import print_function """, stmt.FUTURE_PRINT_FUNCTION, 3), ("""\ "module docstring" from __future__ import print_function, with_statement from __future__ import nested_scopes """, stmt.FUTURE_PRINT_FUNCTION, 4), ] for tc in testcases: source, flags, lineno = tc mod = ast.parse(textwrap.dedent(source)) future_features = stmt.visit_future(mod) self.assertEqual(future_features.parser_flags, flags) self.assertEqual(future_features.future_lineno, lineno)