Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
lib2to3.tests.test_fixers.Test_imports_fixer_order Class Reference
Inheritance diagram for lib2to3.tests.test_fixers.Test_imports_fixer_order:
Inheritance graph
[legend]
Collaboration diagram for lib2to3.tests.test_fixers.Test_imports_fixer_order:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def test_after_local_imports_refactoring
def setUp
def check
def warns
def warns_unchanged
def unchanged
def assert_runs_after
def test_import_module
def test_import_from
def test_import_module_as
def test_import_from_as
def test_star
def test_import_module_usage

Public Attributes

 modules
 fixer
 refactor
 fixer_log
 filename

Detailed Description

Definition at line 1756 of file test_fixers.py.


Member Function Documentation

def lib2to3.tests.test_fixers.FixerTestCase.assert_runs_after (   self,
  names 
) [inherited]

Definition at line 56 of file test_fixers.py.

00056 
00057     def assert_runs_after(self, *names):
00058         fixes = [self.fixer]
00059         fixes.extend(names)
00060         r = support.get_refactorer("lib2to3", fixes)
00061         (pre, post) = r.get_fixers()
00062         n = "fix_" + self.fixer
00063         if post and post[-1].__class__.__module__.endswith(n):
00064             # We're the last fixer to run
00065             return
00066         if pre and pre[-1].__class__.__module__.endswith(n) and not post:
00067             # We're the last in pre and post is empty
00068             return
00069         self.fail("Fixer run order (%s) is incorrect; %s should be last."\
00070                %(", ".join([x.__class__.__module__ for x in (pre+post)]), n))

Here is the call graph for this function:

def lib2to3.tests.test_fixers.FixerTestCase.check (   self,
  before,
  after,
  ignore_warnings = False 
) [inherited]

Definition at line 36 of file test_fixers.py.

00036 
00037     def check(self, before, after, ignore_warnings=False):
00038         tree = self._check(before, after)
00039         self.assertTrue(tree.was_changed)
00040         if not ignore_warnings:
00041             self.assertEqual(self.fixer_log, [])

Here is the call graph for this function:

def lib2to3.tests.test_fixers.FixerTestCase.setUp (   self,
  fix_list = None,
  fixer_pkg = "lib2to3",
  options = None 
) [inherited]

Definition at line 18 of file test_fixers.py.

00018 
00019     def setUp(self, fix_list=None, fixer_pkg="lib2to3", options=None):
00020         if fix_list is None:
00021             fix_list = [self.fixer]
00022         self.refactor = support.get_refactorer(fixer_pkg, fix_list, options)
00023         self.fixer_log = []
00024         self.filename = "<string>"
00025 
00026         for fixer in chain(self.refactor.pre_order,
00027                            self.refactor.post_order):
00028             fixer.log = self.fixer_log

Here is the caller graph for this function:

Definition at line 1758 of file test_fixers.py.

01758 
01759     def setUp(self):
01760         super(Test_imports_fixer_order, self).setUp(['imports', 'imports2'])
01761         from ..fixes.fix_imports2 import MAPPING as mapping2
01762         self.modules = mapping2.copy()
01763         from ..fixes.fix_imports import MAPPING as mapping1
01764         for key in ('dbhash', 'dumbdbm', 'dbm', 'gdbm'):
01765             self.modules[key] = mapping1[key]

Here is the caller graph for this function:

Definition at line 1766 of file test_fixers.py.

01766 
01767     def test_after_local_imports_refactoring(self):
01768         for fix in ("imports", "imports2"):
01769             self.fixer = fix
01770             self.assert_runs_after("import")
01771 

Definition at line 1644 of file test_fixers.py.

01644 
01645     def test_import_from(self):
01646         for old, new in self.modules.items():
01647             b = "from %s import foo" % old
01648             a = "from %s import foo" % new
01649             self.check(b, a)
01650 
01651             b = "from %s import foo, bar" % old
01652             a = "from %s import foo, bar" % new
01653             self.check(b, a)
01654 
01655             b = "from %s import (yes, no)" % old
01656             a = "from %s import (yes, no)" % new
01657             self.check(b, a)

Here is the call graph for this function:

Definition at line 1668 of file test_fixers.py.

01668 
01669     def test_import_from_as(self):
01670         for old, new in self.modules.items():
01671             b = "from %s import foo as bar" % old
01672             a = "from %s import foo as bar" % new
01673             self.check(b, a)

Here is the call graph for this function:

Definition at line 1634 of file test_fixers.py.

01634 
01635     def test_import_module(self):
01636         for old, new in self.modules.items():
01637             b = "import %s" % old
01638             a = "import %s" % new
01639             self.check(b, a)
01640 
01641             b = "import foo, %s, bar" % old
01642             a = "import foo, %s, bar" % new
01643             self.check(b, a)

Here is the call graph for this function:

Definition at line 1658 of file test_fixers.py.

01658 
01659     def test_import_module_as(self):
01660         for old, new in self.modules.items():
01661             b = "import %s as foo_bar" % old
01662             a = "import %s as foo_bar" % new
01663             self.check(b, a)
01664 
01665             b = "import %s as foo_bar" % old
01666             a = "import %s as foo_bar" % new
01667             self.check(b, a)

Here is the call graph for this function:

Definition at line 1680 of file test_fixers.py.

01680 
01681     def test_import_module_usage(self):
01682         for old, new in self.modules.items():
01683             b = """
01684                 import %s
01685                 foo(%s.bar)
01686                 """ % (old, old)
01687             a = """
01688                 import %s
01689                 foo(%s.bar)
01690                 """ % (new, new)
01691             self.check(b, a)
01692 
01693             b = """
01694                 from %s import x
01695                 %s = 23
01696                 """ % (old, old)
01697             a = """
01698                 from %s import x
01699                 %s = 23
01700                 """ % (new, old)
01701             self.check(b, a)
01702 
01703             s = """
01704                 def f():
01705                     %s.method()
01706                 """ % (old,)
01707             self.unchanged(s)
01708 
01709             # test nested usage
01710             b = """
01711                 import %s
01712                 %s.bar(%s.foo)
01713                 """ % (old, old, old)
01714             a = """
01715                 import %s
01716                 %s.bar(%s.foo)
01717                 """ % (new, new, new)
01718             self.check(b, a)
01719 
01720             b = """
01721                 import %s
01722                 x.%s
01723                 """ % (old, old)
01724             a = """
01725                 import %s
01726                 x.%s
01727                 """ % (new, old)
01728             self.check(b, a)
01729 

Here is the call graph for this function:

Definition at line 1674 of file test_fixers.py.

01674 
01675     def test_star(self):
01676         for old, new in self.modules.items():
01677             b = "from %s import *" % old
01678             a = "from %s import *" % new
01679             self.check(b, a)

Here is the call graph for this function:

def lib2to3.tests.test_fixers.FixerTestCase.unchanged (   self,
  before,
  ignore_warnings = False 
) [inherited]

Definition at line 51 of file test_fixers.py.

00051 
00052     def unchanged(self, before, ignore_warnings=False):
00053         self._check(before, before)
00054         if not ignore_warnings:
00055             self.assertEqual(self.fixer_log, [])

Here is the call graph for this function:

def lib2to3.tests.test_fixers.FixerTestCase.warns (   self,
  before,
  after,
  message,
  unchanged = False 
) [inherited]

Definition at line 42 of file test_fixers.py.

00042 
00043     def warns(self, before, after, message, unchanged=False):
00044         tree = self._check(before, after)
00045         self.assertTrue(message in "".join(self.fixer_log))
00046         if not unchanged:
00047             self.assertTrue(tree.was_changed)

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.tests.test_fixers.FixerTestCase.warns_unchanged (   self,
  before,
  message 
) [inherited]

Definition at line 48 of file test_fixers.py.

00048 
00049     def warns_unchanged(self, before, message):
00050         self.warns(before, before, message, unchanged=True)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented in lib2to3.tests.test_fixers.Test_import.

Definition at line 23 of file test_fixers.py.

Definition at line 1768 of file test_fixers.py.

Definition at line 22 of file test_fixers.py.

Definition at line 1761 of file test_fixers.py.

Definition at line 21 of file test_fixers.py.


The documentation for this class was generated from the following file: