]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/tests/support.py
AppPkg/Applications/Python: Add Python 2.7.2 sources since the release of Python...
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / lib2to3 / tests / support.py
CommitLineData
4710c53d 1"""Support code for test_*.py files"""\r
2# Author: Collin Winter\r
3\r
4# Python imports\r
5import unittest\r
6import sys\r
7import os\r
8import os.path\r
9import re\r
10from textwrap import dedent\r
11\r
12# Local imports\r
13from lib2to3 import pytree, refactor\r
14from lib2to3.pgen2 import driver\r
15\r
16test_dir = os.path.dirname(__file__)\r
17proj_dir = os.path.normpath(os.path.join(test_dir, ".."))\r
18grammar_path = os.path.join(test_dir, "..", "Grammar.txt")\r
19grammar = driver.load_grammar(grammar_path)\r
20driver = driver.Driver(grammar, convert=pytree.convert)\r
21\r
22def parse_string(string):\r
23 return driver.parse_string(reformat(string), debug=True)\r
24\r
25def run_all_tests(test_mod=None, tests=None):\r
26 if tests is None:\r
27 tests = unittest.TestLoader().loadTestsFromModule(test_mod)\r
28 unittest.TextTestRunner(verbosity=2).run(tests)\r
29\r
30def reformat(string):\r
31 return dedent(string) + u"\n\n"\r
32\r
33def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None):\r
34 """\r
35 A convenience function for creating a RefactoringTool for tests.\r
36\r
37 fixers is a list of fixers for the RefactoringTool to use. By default\r
38 "lib2to3.fixes.*" is used. options is an optional dictionary of options to\r
39 be passed to the RefactoringTool.\r
40 """\r
41 if fixers is not None:\r
42 fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers]\r
43 else:\r
44 fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes")\r
45 options = options or {}\r
46 return refactor.RefactoringTool(fixers, options, explicit=True)\r
47\r
48def all_project_files():\r
49 for dirpath, dirnames, filenames in os.walk(proj_dir):\r
50 for filename in filenames:\r
51 if filename.endswith(".py"):\r
52 yield os.path.join(dirpath, filename)\r
53\r
54TestCase = unittest.TestCase\r