Back to index

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

List of all members.

Public Member Functions

def setUp
def tearDown
def check_both
def test_files_checked
def test_not_in_package
def test_with_absolute_import_enabled
def test_in_package
def test_import_from_package
def test_already_relative_import
def test_comments_and_indent
def test_from
def test_dotted_from
def test_from_as
def test_import
def test_import_as
def test_local_and_absolute
def test_dotted_import
def test_dotted_import_as
def test_prefix
def setUp
def check
def warns
def warns_unchanged
def unchanged
def assert_runs_after

Public Attributes

 files_checked
 present_files
 always_exists
 filename
 refactor
 fixer_log

Static Public Attributes

string fixer = "import"

Detailed Description

Definition at line 3736 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:

Here is the caller 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.Test_import.check_both (   self,
  b,
  a 
)

Definition at line 3757 of file test_fixers.py.

03757 
03758     def check_both(self, b, a):
03759         self.always_exists = True
03760         super(Test_import, self).check(b, a)
03761         self.always_exists = False
03762         super(Test_import, self).unchanged(b)

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 3739 of file test_fixers.py.

03739 
03740     def setUp(self):
03741         super(Test_import, self).setUp()
03742         # Need to replace fix_import's exists method
03743         # so we can check that it's doing the right thing
03744         self.files_checked = []
03745         self.present_files = set()
03746         self.always_exists = True
03747         def fake_exists(name):
03748             self.files_checked.append(name)
03749             return self.always_exists or (name in self.present_files)
03750 
03751         from lib2to3.fixes import fix_import
03752         fix_import.exists = fake_exists

Here is the caller graph for this function:

Definition at line 3753 of file test_fixers.py.

03753 
03754     def tearDown(self):
03755         from lib2to3.fixes import fix_import
03756         fix_import.exists = os.path.exists

Here is the caller graph for this function:

Definition at line 3813 of file test_fixers.py.

03813 
03814     def test_already_relative_import(self):
03815         s = "from . import bar"
03816         self.unchanged(s)

Here is the call graph for this function:

Definition at line 3817 of file test_fixers.py.

03817 
03818     def test_comments_and_indent(self):
03819         b = "import bar # Foo"
03820         a = "from . import bar # Foo"
03821         self.check(b, a)

Here is the call graph for this function:

Definition at line 3835 of file test_fixers.py.

03835 
03836     def test_dotted_from(self):
03837         b = "from green.eggs import ham"
03838         a = "from .green.eggs import ham"
03839         self.check_both(b, a)

Here is the call graph for this function:

Definition at line 3878 of file test_fixers.py.

03878 
03879     def test_dotted_import(self):
03880         b = "import foo.bar"
03881         a = "from . import foo.bar"
03882         self.check_both(b, a)

Here is the call graph for this function:

Definition at line 3883 of file test_fixers.py.

03883 
03884     def test_dotted_import_as(self):
03885         b = "import foo.bar as bang"
03886         a = "from . import foo.bar as bang"
03887         self.check_both(b, a)

Here is the call graph for this function:

Definition at line 3763 of file test_fixers.py.

03763 
03764     def test_files_checked(self):
03765         def p(path):
03766             # Takes a unix path and returns a path with correct separators
03767             return os.path.pathsep.join(path.split("/"))
03768 
03769         self.always_exists = False
03770         self.present_files = set(['__init__.py'])
03771         expected_extensions = ('.py', os.path.sep, '.pyc', '.so', '.sl', '.pyd')
03772         names_to_test = (p("/spam/eggs.py"), "ni.py", p("../../shrubbery.py"))
03773 
03774         for name in names_to_test:
03775             self.files_checked = []
03776             self.filename = name
03777             self.unchanged("import jam")
03778 
03779             if os.path.dirname(name):
03780                 name = os.path.dirname(name) + '/jam'
03781             else:
03782                 name = 'jam'
03783             expected_checks = set(name + ext for ext in expected_extensions)
03784             expected_checks.add("__init__.py")
03785 
03786             self.assertEqual(set(self.files_checked), expected_checks)

Here is the call graph for this function:

Definition at line 3822 of file test_fixers.py.

03822 
03823     def test_from(self):
03824         b = "from foo import bar, baz"
03825         a = "from .foo import bar, baz"
03826         self.check_both(b, a)
03827 
03828         b = "from foo import bar"
03829         a = "from .foo import bar"
03830         self.check_both(b, a)
03831 
03832         b = "from foo import (bar, baz)"
03833         a = "from .foo import (bar, baz)"
03834         self.check_both(b, a)

Here is the call graph for this function:

Definition at line 3840 of file test_fixers.py.

03840 
03841     def test_from_as(self):
03842         b = "from green.eggs import ham as spam"
03843         a = "from .green.eggs import ham as spam"
03844         self.check_both(b, a)

Here is the call graph for this function:

Definition at line 3845 of file test_fixers.py.

03845 
03846     def test_import(self):
03847         b = "import foo"
03848         a = "from . import foo"
03849         self.check_both(b, a)
03850 
03851         b = "import foo, bar"
03852         a = "from . import foo, bar"
03853         self.check_both(b, a)
03854 
03855         b = "import foo, bar, x"
03856         a = "from . import foo, bar, x"
03857         self.check_both(b, a)
03858 
03859         b = "import x, y, z"
03860         a = "from . import x, y, z"
03861         self.check_both(b, a)

Here is the call graph for this function:

Definition at line 3862 of file test_fixers.py.

03862 
03863     def test_import_as(self):
03864         b = "import foo as x"
03865         a = "from . import foo as x"
03866         self.check_both(b, a)
03867 
03868         b = "import a as b, b as c, c as d"
03869         a = "from . import a as b, b as c, c as d"
03870         self.check_both(b, a)

Here is the call graph for this function:

Definition at line 3806 of file test_fixers.py.

03806 
03807     def test_import_from_package(self):
03808         b = "import bar"
03809         a = "from . import bar"
03810         self.always_exists = False
03811         self.present_files = set(["__init__.py", "bar" + os.path.sep])
03812         self.check(b, a)

Here is the call graph for this function:

Definition at line 3799 of file test_fixers.py.

03799 
03800     def test_in_package(self):
03801         b = "import bar"
03802         a = "from . import bar"
03803         self.always_exists = False
03804         self.present_files = set(["__init__.py", "bar.py"])
03805         self.check(b, a)

Here is the call graph for this function:

Definition at line 3871 of file test_fixers.py.

03871 
03872     def test_local_and_absolute(self):
03873         self.always_exists = False
03874         self.present_files = set(["foo.py", "__init__.py"])
03875 
03876         s = "import foo, bar"
03877         self.warns_unchanged(s, "absolute and local imports together")

Here is the call graph for this function:

Definition at line 3787 of file test_fixers.py.

03787 
03788     def test_not_in_package(self):
03789         s = "import bar"
03790         self.always_exists = False
03791         self.present_files = set(["bar.py"])
03792         self.unchanged(s)

Here is the call graph for this function:

Definition at line 3888 of file test_fixers.py.

03888 
03889     def test_prefix(self):
03890         b = """
03891         # prefix
03892         import foo.bar
03893         """
03894         a = """
03895         # prefix
03896         from . import foo.bar
03897         """
03898         self.check_both(b, a)
03899 

Here is the call graph for this function:

Definition at line 3793 of file test_fixers.py.

03793 
03794     def test_with_absolute_import_enabled(self):
03795         s = "from __future__ import absolute_import\nimport bar"
03796         self.always_exists = False
03797         self.present_files = set(["__init__.py", "bar.py"])
03798         self.unchanged(s)

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

Definition at line 3745 of file test_fixers.py.

Reimplemented from lib2to3.tests.test_fixers.FixerTestCase.

Definition at line 3775 of file test_fixers.py.

Definition at line 3743 of file test_fixers.py.

Definition at line 3737 of file test_fixers.py.

Definition at line 22 of file test_fixers.py.

Definition at line 3744 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: