Back to index

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

List of all members.

Public Member Functions

def test_while
def test_while_unchanged
def test_eq_simple
def test_eq_reverse
def test_eq_expression
def test_is_simple
def test_is_reverse
def test_is_expression
def test_is_not_simple
def test_is_not_reverse
def test_is_not_expression
def test_ne_simple
def test_ne_reverse
def test_ne_expression
def test_type_unchanged
def test_sort_list_call
def test_sort_simple_expr
def test_sort_unchanged
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 = "idioms"

Detailed Description

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

03270 
03271     def test_eq_expression(self):
03272         b = """type(x+y) == d.get('T')"""
03273         a = """isinstance(x+y, d.get('T'))"""
03274         self.check(b, a)
03275 
03276         b = """type(   x  +  y) == d.get('T')"""
03277         a = """isinstance(x  +  y, d.get('T'))"""
03278         self.check(b, a)

Here is the call graph for this function:

Definition at line 3261 of file test_fixers.py.

03261 
03262     def test_eq_reverse(self):
03263         b = """T == type(x)"""
03264         a = """isinstance(x, T)"""
03265         self.check(b, a)
03266 
03267         b = """if   T == type(x): pass"""
03268         a = """if   isinstance(x, T): pass"""
03269         self.check(b, a)

Here is the call graph for this function:

Definition at line 3252 of file test_fixers.py.

03252 
03253     def test_eq_simple(self):
03254         b = """type(x) == T"""
03255         a = """isinstance(x, T)"""
03256         self.check(b, a)
03257 
03258         b = """if   type(x) == T: pass"""
03259         a = """if   isinstance(x, T): pass"""
03260         self.check(b, a)

Here is the call graph for this function:

Definition at line 3297 of file test_fixers.py.

03297 
03298     def test_is_expression(self):
03299         b = """type(x+y) is d.get('T')"""
03300         a = """isinstance(x+y, d.get('T'))"""
03301         self.check(b, a)
03302 
03303         b = """type(   x  +  y) is d.get('T')"""
03304         a = """isinstance(x  +  y, d.get('T'))"""
03305         self.check(b, a)

Here is the call graph for this function:

Definition at line 3324 of file test_fixers.py.

03324 
03325     def test_is_not_expression(self):
03326         b = """type(x+y) is not d.get('T')"""
03327         a = """not isinstance(x+y, d.get('T'))"""
03328         self.check(b, a)
03329 
03330         b = """type(   x  +  y) is not d.get('T')"""
03331         a = """not isinstance(x  +  y, d.get('T'))"""
03332         self.check(b, a)

Here is the call graph for this function:

Definition at line 3315 of file test_fixers.py.

03315 
03316     def test_is_not_reverse(self):
03317         b = """T is not type(x)"""
03318         a = """not isinstance(x, T)"""
03319         self.check(b, a)
03320 
03321         b = """if   T is not type(x): pass"""
03322         a = """if   not isinstance(x, T): pass"""
03323         self.check(b, a)

Here is the call graph for this function:

Definition at line 3306 of file test_fixers.py.

03306 
03307     def test_is_not_simple(self):
03308         b = """type(x) is not T"""
03309         a = """not isinstance(x, T)"""
03310         self.check(b, a)
03311 
03312         b = """if   type(x) is not T: pass"""
03313         a = """if   not isinstance(x, T): pass"""
03314         self.check(b, a)

Here is the call graph for this function:

Definition at line 3288 of file test_fixers.py.

03288 
03289     def test_is_reverse(self):
03290         b = """T is type(x)"""
03291         a = """isinstance(x, T)"""
03292         self.check(b, a)
03293 
03294         b = """if   T is type(x): pass"""
03295         a = """if   isinstance(x, T): pass"""
03296         self.check(b, a)

Here is the call graph for this function:

Definition at line 3279 of file test_fixers.py.

03279 
03280     def test_is_simple(self):
03281         b = """type(x) is T"""
03282         a = """isinstance(x, T)"""
03283         self.check(b, a)
03284 
03285         b = """if   type(x) is T: pass"""
03286         a = """if   isinstance(x, T): pass"""
03287         self.check(b, a)

Here is the call graph for this function:

Definition at line 3351 of file test_fixers.py.

03351 
03352     def test_ne_expression(self):
03353         b = """type(x+y) != d.get('T')"""
03354         a = """not isinstance(x+y, d.get('T'))"""
03355         self.check(b, a)
03356 
03357         b = """type(   x  +  y) != d.get('T')"""
03358         a = """not isinstance(x  +  y, d.get('T'))"""
03359         self.check(b, a)

Here is the call graph for this function:

Definition at line 3342 of file test_fixers.py.

03342 
03343     def test_ne_reverse(self):
03344         b = """T != type(x)"""
03345         a = """not isinstance(x, T)"""
03346         self.check(b, a)
03347 
03348         b = """if   T != type(x): pass"""
03349         a = """if   not isinstance(x, T): pass"""
03350         self.check(b, a)

Here is the call graph for this function:

Definition at line 3333 of file test_fixers.py.

03333 
03334     def test_ne_simple(self):
03335         b = """type(x) != T"""
03336         a = """not isinstance(x, T)"""
03337         self.check(b, a)
03338 
03339         b = """if   type(x) != T: pass"""
03340         a = """if   not isinstance(x, T): pass"""
03341         self.check(b, a)

Here is the call graph for this function:

Definition at line 3364 of file test_fixers.py.

03364 
03365     def test_sort_list_call(self):
03366         b = """
03367             v = list(t)
03368             v.sort()
03369             foo(v)
03370             """
03371         a = """
03372             v = sorted(t)
03373             foo(v)
03374             """
03375         self.check(b, a)
03376 
03377         b = """
03378             v = list(foo(b) + d)
03379             v.sort()
03380             foo(v)
03381             """
03382         a = """
03383             v = sorted(foo(b) + d)
03384             foo(v)
03385             """
03386         self.check(b, a)
03387 
03388         b = """
03389             while x:
03390                 v = list(t)
03391                 v.sort()
03392                 foo(v)
03393             """
03394         a = """
03395             while x:
03396                 v = sorted(t)
03397                 foo(v)
03398             """
03399         self.check(b, a)
03400 
03401         b = """
03402             v = list(t)
03403             # foo
03404             v.sort()
03405             foo(v)
03406             """
03407         a = """
03408             v = sorted(t)
03409             # foo
03410             foo(v)
03411             """
03412         self.check(b, a)
03413 
03414         b = r"""
03415             v = list(   t)
03416             v.sort()
03417             foo(v)
03418             """
03419         a = r"""
03420             v = sorted(   t)
03421             foo(v)
03422             """
03423         self.check(b, a)
03424 
03425         b = r"""
03426             try:
03427                 m = list(s)
03428                 m.sort()
03429             except: pass
03430             """
03431 
03432         a = r"""
03433             try:
03434                 m = sorted(s)
03435             except: pass
03436             """
03437         self.check(b, a)
03438 
03439         b = r"""
03440             try:
03441                 m = list(s)
03442                 # foo
03443                 m.sort()
03444             except: pass
03445             """
03446 
03447         a = r"""
03448             try:
03449                 m = sorted(s)
03450                 # foo
03451             except: pass
03452             """
03453         self.check(b, a)
03454 
03455         b = r"""
03456             m = list(s)
03457             # more comments
03458             m.sort()"""
03459 
03460         a = r"""
03461             m = sorted(s)
03462             # more comments"""
03463         self.check(b, a)

Here is the call graph for this function:

Definition at line 3464 of file test_fixers.py.

03464 
03465     def test_sort_simple_expr(self):
03466         b = """
03467             v = t
03468             v.sort()
03469             foo(v)
03470             """
03471         a = """
03472             v = sorted(t)
03473             foo(v)
03474             """
03475         self.check(b, a)
03476 
03477         b = """
03478             v = foo(b)
03479             v.sort()
03480             foo(v)
03481             """
03482         a = """
03483             v = sorted(foo(b))
03484             foo(v)
03485             """
03486         self.check(b, a)
03487 
03488         b = """
03489             v = b.keys()
03490             v.sort()
03491             foo(v)
03492             """
03493         a = """
03494             v = sorted(b.keys())
03495             foo(v)
03496             """
03497         self.check(b, a)
03498 
03499         b = """
03500             v = foo(b) + d
03501             v.sort()
03502             foo(v)
03503             """
03504         a = """
03505             v = sorted(foo(b) + d)
03506             foo(v)
03507             """
03508         self.check(b, a)
03509 
03510         b = """
03511             while x:
03512                 v = t
03513                 v.sort()
03514                 foo(v)
03515             """
03516         a = """
03517             while x:
03518                 v = sorted(t)
03519                 foo(v)
03520             """
03521         self.check(b, a)
03522 
03523         b = """
03524             v = t
03525             # foo
03526             v.sort()
03527             foo(v)
03528             """
03529         a = """
03530             v = sorted(t)
03531             # foo
03532             foo(v)
03533             """
03534         self.check(b, a)
03535 
03536         b = r"""
03537             v =   t
03538             v.sort()
03539             foo(v)
03540             """
03541         a = r"""
03542             v =   sorted(t)
03543             foo(v)
03544             """
03545         self.check(b, a)

Here is the call graph for this function:

Definition at line 3546 of file test_fixers.py.

03546 
03547     def test_sort_unchanged(self):
03548         s = """
03549             v = list(t)
03550             w.sort()
03551             foo(w)
03552             """
03553         self.unchanged(s)
03554 
03555         s = """
03556             v = list(t)
03557             v.sort(u)
03558             foo(v)
03559             """
03560         self.unchanged(s)

Here is the call graph for this function:

Definition at line 3360 of file test_fixers.py.

03360 
03361     def test_type_unchanged(self):
03362         a = """type(x).__name__"""
03363         self.unchanged(a)

Here is the call graph for this function:

Definition at line 3220 of file test_fixers.py.

03220 
03221     def test_while(self):
03222         b = """while 1: foo()"""
03223         a = """while True: foo()"""
03224         self.check(b, a)
03225 
03226         b = """while   1: foo()"""
03227         a = """while   True: foo()"""
03228         self.check(b, a)
03229 
03230         b = """
03231             while 1:
03232                 foo()
03233             """
03234         a = """
03235             while True:
03236                 foo()
03237             """
03238         self.check(b, a)

Here is the call graph for this function:

Definition at line 3239 of file test_fixers.py.

03239 
03240     def test_while_unchanged(self):
03241         s = """while 11: foo()"""
03242         self.unchanged(s)
03243 
03244         s = """while 0: foo()"""
03245         self.unchanged(s)
03246 
03247         s = """while foo(): foo()"""
03248         self.unchanged(s)
03249 
03250         s = """while []: foo()"""
03251         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 3218 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: