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