Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 refactor
 fixer_log
 filename

Static Public Attributes

string fixer = "urllib"

Detailed Description

Definition at line 1772 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 1782 of file test_fixers.py.

01782 
01783     def test_import_from(self):
01784         for old, changes in self.modules.items():
01785             all_members = []
01786             for new, members in changes:
01787                 for member in members:
01788                     all_members.append(member)
01789                     b = "from %s import %s" % (old, member)
01790                     a = "from %s import %s" % (new, member)
01791                     self.check(b, a)
01792 
01793                     s = "from foo import %s" % member
01794                     self.unchanged(s)
01795 
01796                 b = "from %s import %s" % (old, ", ".join(members))
01797                 a = "from %s import %s" % (new, ", ".join(members))
01798                 self.check(b, a)
01799 
01800                 s = "from foo import %s" % ", ".join(members)
01801                 self.unchanged(s)
01802 
01803             # test the breaking of a module into multiple replacements
01804             b = "from %s import %s" % (old, ", ".join(all_members))
01805             a = "\n".join(["from %s import %s" % (new, ", ".join(members))
01806                             for (new, members) in changes])
01807             self.check(b, a)

Here is the call graph for this function:

Definition at line 1813 of file test_fixers.py.

01813 
01814     def test_import_from_as(self):
01815         for old, changes in self.modules.items():
01816             for new, members in changes:
01817                 for member in members:
01818                     b = "from %s import %s as foo_bar" % (old, member)
01819                     a = "from %s import %s as foo_bar" % (new, member)
01820                     self.check(b, a)
01821                     b = "from %s import %s as blah, %s" % (old, member, member)
01822                     a = "from %s import %s as blah, %s" % (new, member, member)
01823                     self.check(b, a)

Here is the call graph for this function:

Definition at line 1776 of file test_fixers.py.

01776 
01777     def test_import_module(self):
01778         for old, changes in self.modules.items():
01779             b = "import %s" % old
01780             a = "import %s" % ", ".join(map(itemgetter(0), changes))
01781             self.check(b, a)

Here is the call graph for this function:

Definition at line 1808 of file test_fixers.py.

01808 
01809     def test_import_module_as(self):
01810         for old in self.modules:
01811             s = "import %s as foo" % old
01812             self.warns_unchanged(s, "This module is now multiple modules")

Here is the call graph for this function:

Definition at line 1856 of file test_fixers.py.

01856 
01857     def test_import_module_usage(self):
01858         for old, changes in self.modules.items():
01859             for new, members in changes:
01860                 for member in members:
01861                     new_import = ", ".join([n for (n, mems)
01862                                             in self.modules[old]])
01863                     b = """
01864                         import %s
01865                         foo(%s.%s)
01866                         """ % (old, old, member)
01867                     a = """
01868                         import %s
01869                         foo(%s.%s)
01870                         """ % (new_import, new, member)
01871                     self.check(b, a)
01872                     b = """
01873                         import %s
01874                         %s.%s(%s.%s)
01875                         """ % (old, old, member, old, member)
01876                     a = """
01877                         import %s
01878                         %s.%s(%s.%s)
01879                         """ % (new_import, new, member, new, member)
01880                     self.check(b, a)
01881 

Here is the call graph for this function:

Definition at line 1829 of file test_fixers.py.

01829 
01830     def test_indented(self):
01831         b = """
01832 def foo():
01833     from urllib import urlencode, urlopen
01834 """
01835         a = """
01836 def foo():
01837     from urllib.parse import urlencode
01838     from urllib.request import urlopen
01839 """
01840         self.check(b, a)
01841 
01842         b = """
01843 def foo():
01844     other()
01845     from urllib import urlencode, urlopen
01846 """
01847         a = """
01848 def foo():
01849     other()
01850     from urllib.parse import urlencode
01851     from urllib.request import urlopen
01852 """
01853         self.check(b, a)
01854 
01855 

Here is the call graph for this function:

Definition at line 1824 of file test_fixers.py.

01824 
01825     def test_star(self):
01826         for old in self.modules:
01827             s = "from %s import *" % old
01828             self.warns_unchanged(s, "Cannot handle star imports")

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

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