+++ /dev/null
-"""Support code for test_*.py files"""\r
-# Author: Collin Winter\r
-\r
-# Python imports\r
-import unittest\r
-import sys\r
-import os\r
-import os.path\r
-import re\r
-from textwrap import dedent\r
-\r
-# Local imports\r
-from lib2to3 import pytree, refactor\r
-from lib2to3.pgen2 import driver\r
-\r
-test_dir = os.path.dirname(__file__)\r
-proj_dir = os.path.normpath(os.path.join(test_dir, ".."))\r
-grammar_path = os.path.join(test_dir, "..", "Grammar.txt")\r
-grammar = driver.load_grammar(grammar_path)\r
-driver = driver.Driver(grammar, convert=pytree.convert)\r
-\r
-def parse_string(string):\r
- return driver.parse_string(reformat(string), debug=True)\r
-\r
-def run_all_tests(test_mod=None, tests=None):\r
- if tests is None:\r
- tests = unittest.TestLoader().loadTestsFromModule(test_mod)\r
- unittest.TextTestRunner(verbosity=2).run(tests)\r
-\r
-def reformat(string):\r
- return dedent(string) + u"\n\n"\r
-\r
-def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None):\r
- """\r
- A convenience function for creating a RefactoringTool for tests.\r
-\r
- fixers is a list of fixers for the RefactoringTool to use. By default\r
- "lib2to3.fixes.*" is used. options is an optional dictionary of options to\r
- be passed to the RefactoringTool.\r
- """\r
- if fixers is not None:\r
- fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers]\r
- else:\r
- fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes")\r
- options = options or {}\r
- return refactor.RefactoringTool(fixers, options, explicit=True)\r
-\r
-def all_project_files():\r
- for dirpath, dirnames, filenames in os.walk(proj_dir):\r
- for filename in filenames:\r
- if filename.endswith(".py"):\r
- yield os.path.join(dirpath, filename)\r
-\r
-TestCase = unittest.TestCase\r