Back to index

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

List of all members.

Public Member Functions

def test_unchanged
def test_comments
def test_meta
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 = 'metaclass'

Detailed Description

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

04144 
04145     def test_comments(self):
04146         b = """
04147         class X:
04148             # hi
04149             __metaclass__ = AppleMeta
04150         """
04151         a = """
04152         class X(metaclass=AppleMeta):
04153             # hi
04154             pass
04155         """
04156         self.check(b, a)
04157 
04158         b = """
04159         class X:
04160             __metaclass__ = Meta
04161             # Bedtime!
04162         """
04163         a = """
04164         class X(metaclass=Meta):
04165             pass
04166             # Bedtime!
04167         """
04168         self.check(b, a)

Here is the call graph for this function:

Definition at line 4169 of file test_fixers.py.

04169 
04170     def test_meta(self):
04171         # no-parent class, odd body
04172         b = """
04173         class X():
04174             __metaclass__ = Q
04175             pass
04176         """
04177         a = """
04178         class X(metaclass=Q):
04179             pass
04180         """
04181         self.check(b, a)
04182 
04183         # one parent class, no body
04184         b = """class X(object): __metaclass__ = Q"""
04185         a = """class X(object, metaclass=Q): pass"""
04186         self.check(b, a)
04187 
04188 
04189         # one parent, simple body
04190         b = """
04191         class X(object):
04192             __metaclass__ = Meta
04193             bar = 7
04194         """
04195         a = """
04196         class X(object, metaclass=Meta):
04197             bar = 7
04198         """
04199         self.check(b, a)
04200 
04201         b = """
04202         class X:
04203             __metaclass__ = Meta; x = 4; g = 23
04204         """
04205         a = """
04206         class X(metaclass=Meta):
04207             x = 4; g = 23
04208         """
04209         self.check(b, a)
04210 
04211         # one parent, simple body, __metaclass__ last
04212         b = """
04213         class X(object):
04214             bar = 7
04215             __metaclass__ = Meta
04216         """
04217         a = """
04218         class X(object, metaclass=Meta):
04219             bar = 7
04220         """
04221         self.check(b, a)
04222 
04223         # redefining __metaclass__
04224         b = """
04225         class X():
04226             __metaclass__ = A
04227             __metaclass__ = B
04228             bar = 7
04229         """
04230         a = """
04231         class X(metaclass=B):
04232             bar = 7
04233         """
04234         self.check(b, a)
04235 
04236         # multiple inheritance, simple body
04237         b = """
04238         class X(clsA, clsB):
04239             __metaclass__ = Meta
04240             bar = 7
04241         """
04242         a = """
04243         class X(clsA, clsB, metaclass=Meta):
04244             bar = 7
04245         """
04246         self.check(b, a)
04247 
04248         # keywords in the class statement
04249         b = """class m(a, arg=23): __metaclass__ = Meta"""
04250         a = """class m(a, arg=23, metaclass=Meta): pass"""
04251         self.check(b, a)
04252 
04253         b = """
04254         class X(expression(2 + 4)):
04255             __metaclass__ = Meta
04256         """
04257         a = """
04258         class X(expression(2 + 4), metaclass=Meta):
04259             pass
04260         """
04261         self.check(b, a)
04262 
04263         b = """
04264         class X(expression(2 + 4), x**4):
04265             __metaclass__ = Meta
04266         """
04267         a = """
04268         class X(expression(2 + 4), x**4, metaclass=Meta):
04269             pass
04270         """
04271         self.check(b, a)
04272 
04273         b = """
04274         class X:
04275             __metaclass__ = Meta
04276             save.py = 23
04277         """
04278         a = """
04279         class X(metaclass=Meta):
04280             save.py = 23
04281         """
04282         self.check(b, a)
04283 

Here is the call graph for this function:

Definition at line 4123 of file test_fixers.py.

04123 
04124     def test_unchanged(self):
04125         self.unchanged("class X(): pass")
04126         self.unchanged("class X(object): pass")
04127         self.unchanged("class X(object1, object2): pass")
04128         self.unchanged("class X(object1, object2, object3): pass")
04129         self.unchanged("class X(metaclass=Meta): pass")
04130         self.unchanged("class X(b, arg=23, metclass=Meta): pass")
04131         self.unchanged("class X(b, arg=23, metaclass=Meta, other=42): pass")
04132 
04133         s = """
04134         class X:
04135             def __metaclass__(self): pass
04136         """
04137         self.unchanged(s)
04138 
04139         s = """
04140         class X:
04141             a[23] = 74
04142         """
04143         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

Reimplemented in lib2to3.tests.test_fixers.Test_import.

Definition at line 23 of file test_fixers.py.

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