Back to index

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

List of all members.

Public Member Functions

def test_prefix_preservation
def test_callable_call
def test_global_import
def test_callable_should_not_change
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 = "callable"

Detailed Description

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

02840 
02841     def test_callable_call(self):
02842         b = """callable(x)"""
02843         a = """import collections\nisinstance(x, collections.Callable)"""
02844         self.check(b, a)

Here is the call graph for this function:

Definition at line 2907 of file test_fixers.py.

02907 
02908     def test_callable_should_not_change(self):
02909         a = """callable(*x)"""
02910         self.unchanged(a)
02911 
02912         a = """callable(x, y)"""
02913         self.unchanged(a)
02914 
02915         a = """callable(x, kw=y)"""
02916         self.unchanged(a)
02917 
02918         a = """callable()"""
02919         self.unchanged(a)

Here is the call graph for this function:

Definition at line 2845 of file test_fixers.py.

02845 
02846     def test_global_import(self):
02847         b = """
02848 def spam(foo):
02849     callable(foo)"""[1:]
02850         a = """
02851 import collections
02852 def spam(foo):
02853     isinstance(foo, collections.Callable)"""[1:]
02854         self.check(b, a)
02855 
02856         b = """
02857 import collections
02858 def spam(foo):
02859     callable(foo)"""[1:]
02860         # same output if it was already imported
02861         self.check(b, a)
02862 
02863         b = """
02864 from collections import *
02865 def spam(foo):
02866     callable(foo)"""[1:]
02867         a = """
02868 from collections import *
02869 import collections
02870 def spam(foo):
02871     isinstance(foo, collections.Callable)"""[1:]
02872         self.check(b, a)
02873 
02874         b = """
02875 do_stuff()
02876 do_some_other_stuff()
02877 assert callable(do_stuff)"""[1:]
02878         a = """
02879 import collections
02880 do_stuff()
02881 do_some_other_stuff()
02882 assert isinstance(do_stuff, collections.Callable)"""[1:]
02883         self.check(b, a)
02884 
02885         b = """
02886 if isinstance(do_stuff, Callable):
02887     assert callable(do_stuff)
02888     do_stuff(do_stuff)
02889     if not callable(do_stuff):
02890         exit(1)
02891     else:
02892         assert callable(do_stuff)
02893 else:
02894     assert not callable(do_stuff)"""[1:]
02895         a = """
02896 import collections
02897 if isinstance(do_stuff, Callable):
02898     assert isinstance(do_stuff, collections.Callable)
02899     do_stuff(do_stuff)
02900     if not isinstance(do_stuff, collections.Callable):
02901         exit(1)
02902     else:
02903         assert isinstance(do_stuff, collections.Callable)
02904 else:
02905     assert not isinstance(do_stuff, collections.Callable)"""[1:]
02906         self.check(b, a)

Here is the call graph for this function:

Definition at line 2830 of file test_fixers.py.

02830 
02831     def test_prefix_preservation(self):
02832         b = """callable(    x)"""
02833         a = """import collections\nisinstance(    x, collections.Callable)"""
02834         self.check(b, a)
02835 
02836         b = """if     callable(x): pass"""
02837         a = """import collections
02838 if     isinstance(x, collections.Callable): pass"""
02839         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 2828 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: