~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/lib2to3/tests/support.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import re
10
10
from textwrap import dedent
11
11
 
12
 
#sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
13
 
 
14
12
# Local imports
15
 
from .. import pytree
16
 
from .. import refactor
17
 
from ..pgen2 import driver
 
13
from lib2to3 import pytree, refactor
 
14
from lib2to3.pgen2 import driver
18
15
 
19
16
test_dir = os.path.dirname(__file__)
20
17
proj_dir = os.path.normpath(os.path.join(test_dir, ".."))
25
22
def parse_string(string):
26
23
    return driver.parse_string(reformat(string), debug=True)
27
24
 
28
 
# Python 2.3's TestSuite is not iter()-able
29
 
if sys.version_info < (2, 4):
30
 
    def TestSuite_iter(self):
31
 
        return iter(self._tests)
32
 
    unittest.TestSuite.__iter__ = TestSuite_iter
33
 
 
34
25
def run_all_tests(test_mod=None, tests=None):
35
26
    if tests is None:
36
27
        tests = unittest.TestLoader().loadTestsFromModule(test_mod)
37
28
    unittest.TextTestRunner(verbosity=2).run(tests)
38
29
 
39
30
def reformat(string):
40
 
    return dedent(string) + "\n\n"
 
31
    return dedent(string) + u"\n\n"
41
32
 
42
 
def get_refactorer(fixers=None, options=None):
 
33
def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None):
43
34
    """
44
35
    A convenience function for creating a RefactoringTool for tests.
45
36
 
48
39
    be passed to the RefactoringTool.
49
40
    """
50
41
    if fixers is not None:
51
 
        fixers = ["lib2to3.fixes.fix_" + fix for fix in fixers]
 
42
        fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers]
52
43
    else:
53
 
        fixers = refactor.get_fixers_from_package("lib2to3.fixes")
 
44
        fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes")
54
45
    options = options or {}
55
46
    return refactor.RefactoringTool(fixers, options, explicit=True)
56
47