Back to index

python3.2  3.2.2
Public Member Functions
lib2to3.tests.test_util.Test_find_binding Class Reference

List of all members.

Public Member Functions

def find_binding
def test_simple_assignment
def test_tuple_assignment
def test_list_assignment
def test_invalid_assignments
def test_simple_import
def test_from_import
def test_import_as
def test_from_import_as
def test_simple_import_with_package
def test_from_import_with_package
def test_import_as_with_package
def test_from_import_as_with_package
def test_function_def
def test_class_def
def test_for
def test_for_nested
def test_if
def test_if_nested
def test_while
def test_while_nested
def test_try_except
def test_try_except_nested
def test_try_except_finally
def test_try_except_finally_nested

Detailed Description

Definition at line 150 of file test_util.py.


Member Function Documentation

def lib2to3.tests.test_util.Test_find_binding.find_binding (   self,
  name,
  string,
  package = None 
)

Definition at line 151 of file test_util.py.

00151 
00152     def find_binding(self, name, string, package=None):
00153         return fixer_util.find_binding(name, parse(string), package)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 266 of file test_util.py.

00266 
00267     def test_class_def(self):
00268         self.assertTrue(self.find_binding("a", "class a: pass"))
00269         self.assertTrue(self.find_binding("a", "class a(): pass"))
00270         self.assertTrue(self.find_binding("a", "class a(b): pass"))
00271         self.assertTrue(self.find_binding("a", "class a(b, c=8): pass"))
00272         self.assertFalse(self.find_binding("a", "class d: pass"))
00273         self.assertFalse(self.find_binding("a", "class d(a): pass"))
00274         self.assertFalse(self.find_binding("a", "class d(b, a=7): pass"))
00275         self.assertFalse(self.find_binding("a", "class d(b, *a): pass"))
00276         self.assertFalse(self.find_binding("a", "class d(b, **a): pass"))
00277         self.assertFalse(self.find_binding("a", "class d: a = 7"))
00278 
00279         s = """
00280             class d():
00281                 class a():
00282                     pass"""
00283         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 284 of file test_util.py.

00284 
00285     def test_for(self):
00286         self.assertTrue(self.find_binding("a", "for a in r: pass"))
00287         self.assertTrue(self.find_binding("a", "for a, b in r: pass"))
00288         self.assertTrue(self.find_binding("a", "for (a, b) in r: pass"))
00289         self.assertTrue(self.find_binding("a", "for c, (a,) in r: pass"))
00290         self.assertTrue(self.find_binding("a", "for c, (a, b) in r: pass"))
00291         self.assertTrue(self.find_binding("a", "for c in r: a = c"))
00292         self.assertFalse(self.find_binding("a", "for c in a: pass"))

Here is the call graph for this function:

Definition at line 293 of file test_util.py.

00293 
00294     def test_for_nested(self):
00295         s = """
00296             for b in r:
00297                 for a in b:
00298                     pass"""
00299         self.assertTrue(self.find_binding("a", s))
00300 
00301         s = """
00302             for b in r:
00303                 for a, c in b:
00304                     pass"""
00305         self.assertTrue(self.find_binding("a", s))
00306 
00307         s = """
00308             for b in r:
00309                 for (a, c) in b:
00310                     pass"""
00311         self.assertTrue(self.find_binding("a", s))
00312 
00313         s = """
00314             for b in r:
00315                 for (a,) in b:
00316                     pass"""
00317         self.assertTrue(self.find_binding("a", s))
00318 
00319         s = """
00320             for b in r:
00321                 for c, (a, d) in b:
00322                     pass"""
00323         self.assertTrue(self.find_binding("a", s))
00324 
00325         s = """
00326             for b in r:
00327                 for c in b:
00328                     a = 7"""
00329         self.assertTrue(self.find_binding("a", s))
00330 
00331         s = """
00332             for b in r:
00333                 for c in b:
00334                     d = a"""
00335         self.assertFalse(self.find_binding("a", s))
00336 
00337         s = """
00338             for b in r:
00339                 for c in a:
00340                     d = 7"""
00341         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 190 of file test_util.py.

00190 
00191     def test_from_import(self):
00192         self.assertTrue(self.find_binding("a", "from x import a"))
00193         self.assertTrue(self.find_binding("a", "from a import a"))
00194         self.assertTrue(self.find_binding("a", "from x import b, c, a, d"))
00195         self.assertTrue(self.find_binding("a", "from x.b import a"))
00196         self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d"))
00197         self.assertFalse(self.find_binding("a", "from a import b"))
00198         self.assertFalse(self.find_binding("a", "from a.d import b"))
00199         self.assertFalse(self.find_binding("a", "from d.a import b"))

Here is the call graph for this function:

Definition at line 206 of file test_util.py.

00206 
00207     def test_from_import_as(self):
00208         self.assertTrue(self.find_binding("a", "from x import b as a"))
00209         self.assertTrue(self.find_binding("a", "from x import g as a, d as b"))
00210         self.assertTrue(self.find_binding("a", "from x.b import t as a"))
00211         self.assertTrue(self.find_binding("a", "from x.b import g as a, d"))
00212         self.assertFalse(self.find_binding("a", "from a import b as t"))
00213         self.assertFalse(self.find_binding("a", "from a.d import b as t"))
00214         self.assertFalse(self.find_binding("a", "from d.a import b as t"))

Here is the call graph for this function:

Definition at line 239 of file test_util.py.

00239 
00240     def test_from_import_as_with_package(self):
00241         # Because it would take a lot of special-case code in the fixers
00242         # to deal with from foo import bar as baz, we'll simply always
00243         # fail if there is an "from ... import ... as ..."
00244         self.assertFalse(self.find_binding("a", "from x import b as a", "x"))
00245         self.assertFalse(self.find_binding("a", "from x import g as a, d as b", "x"))
00246         self.assertFalse(self.find_binding("a", "from x.b import t as a", "x.b"))
00247         self.assertFalse(self.find_binding("a", "from x.b import g as a, d", "x.b"))
00248         self.assertFalse(self.find_binding("a", "from a import b as t", "a"))
00249         self.assertFalse(self.find_binding("a", "from a import b as t", "b"))
00250         self.assertFalse(self.find_binding("a", "from a import b as t", "t"))

Here is the call graph for this function:

Definition at line 221 of file test_util.py.

00221 
00222     def test_from_import_with_package(self):
00223         self.assertTrue(self.find_binding("a", "from x import a", "x"))
00224         self.assertTrue(self.find_binding("a", "from a import a", "a"))
00225         self.assertTrue(self.find_binding("a", "from x import *", "x"))
00226         self.assertTrue(self.find_binding("a", "from x import b, c, a, d", "x"))
00227         self.assertTrue(self.find_binding("a", "from x.b import a", "x.b"))
00228         self.assertTrue(self.find_binding("a", "from x.b import *", "x.b"))
00229         self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d", "x.b"))
00230         self.assertFalse(self.find_binding("a", "from a import b", "a"))
00231         self.assertFalse(self.find_binding("a", "from a.d import b", "a.d"))
00232         self.assertFalse(self.find_binding("a", "from d.a import b", "a.d"))
00233         self.assertFalse(self.find_binding("a", "from x.y import *", "a.b"))

Here is the call graph for this function:

Definition at line 251 of file test_util.py.

00251 
00252     def test_function_def(self):
00253         self.assertTrue(self.find_binding("a", "def a(): pass"))
00254         self.assertTrue(self.find_binding("a", "def a(b, c, d): pass"))
00255         self.assertTrue(self.find_binding("a", "def a(): b = 7"))
00256         self.assertFalse(self.find_binding("a", "def d(b, (c, a), e): pass"))
00257         self.assertFalse(self.find_binding("a", "def d(a=7): pass"))
00258         self.assertFalse(self.find_binding("a", "def d(a): pass"))
00259         self.assertFalse(self.find_binding("a", "def d(): a = 7"))
00260 
00261         s = """
00262             def d():
00263                 def a():
00264                     pass"""
00265         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 342 of file test_util.py.

00342 
00343     def test_if(self):
00344         self.assertTrue(self.find_binding("a", "if b in r: a = c"))
00345         self.assertFalse(self.find_binding("a", "if a in r: d = e"))

Here is the call graph for this function:

Definition at line 346 of file test_util.py.

00346 
00347     def test_if_nested(self):
00348         s = """
00349             if b in r:
00350                 if c in d:
00351                     a = c"""
00352         self.assertTrue(self.find_binding("a", s))
00353 
00354         s = """
00355             if b in r:
00356                 if c in d:
00357                     c = a"""
00358         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 200 of file test_util.py.

00200 
00201     def test_import_as(self):
00202         self.assertTrue(self.find_binding("a", "import b as a"))
00203         self.assertTrue(self.find_binding("a", "import b as a, c, a as f, d"))
00204         self.assertFalse(self.find_binding("a", "import a as f"))
00205         self.assertFalse(self.find_binding("a", "import b, c as f, d as e"))

Here is the call graph for this function:

Definition at line 234 of file test_util.py.

00234 
00235     def test_import_as_with_package(self):
00236         self.assertFalse(self.find_binding("a", "import b.c as a", "b.c"))
00237         self.assertFalse(self.find_binding("a", "import a as f", "f"))
00238         self.assertFalse(self.find_binding("a", "import a as f", "a"))

Here is the call graph for this function:

Definition at line 178 of file test_util.py.

00178 
00179     def test_invalid_assignments(self):
00180         self.assertFalse(self.find_binding("a", "foo.a = 5"))
00181         self.assertFalse(self.find_binding("a", "foo[a] = 5"))
00182         self.assertFalse(self.find_binding("a", "foo(a) = 5"))
00183         self.assertFalse(self.find_binding("a", "foo(a, b) = 5"))

Here is the call graph for this function:

Definition at line 170 of file test_util.py.

00170 
00171     def test_list_assignment(self):
00172         self.assertTrue(self.find_binding("a", "[a] = b"))
00173         self.assertTrue(self.find_binding("a", "[a, b, c] = [b, c, d]"))
00174         self.assertTrue(self.find_binding("a", "[c, [d, a], b] = foo()"))
00175         self.assertTrue(self.find_binding("a", "[a, b] = foo().foo[a][foo]"))
00176         self.assertFalse(self.find_binding("a", "[foo, b] = (b, a)"))
00177         self.assertFalse(self.find_binding("a", "[foo, [b, c]] = (a, b, c)"))

Here is the call graph for this function:

Definition at line 154 of file test_util.py.

00154 
00155     def test_simple_assignment(self):
00156         self.assertTrue(self.find_binding("a", "a = b"))
00157         self.assertTrue(self.find_binding("a", "a = [b, c, d]"))
00158         self.assertTrue(self.find_binding("a", "a = foo()"))
00159         self.assertTrue(self.find_binding("a", "a = foo().foo.foo[6][foo]"))
00160         self.assertFalse(self.find_binding("a", "foo = a"))
00161         self.assertFalse(self.find_binding("a", "foo = (a, b, c)"))

Here is the call graph for this function:

Definition at line 184 of file test_util.py.

00184 
00185     def test_simple_import(self):
00186         self.assertTrue(self.find_binding("a", "import a"))
00187         self.assertTrue(self.find_binding("a", "import b, c, a, d"))
00188         self.assertFalse(self.find_binding("a", "import b"))
00189         self.assertFalse(self.find_binding("a", "import b, c, d"))

Here is the call graph for this function:

Definition at line 215 of file test_util.py.

00215 
00216     def test_simple_import_with_package(self):
00217         self.assertTrue(self.find_binding("b", "import b"))
00218         self.assertTrue(self.find_binding("b", "import b, c, d"))
00219         self.assertFalse(self.find_binding("b", "import b", "b"))
00220         self.assertFalse(self.find_binding("b", "import b, c, d", "c"))

Here is the call graph for this function:

Definition at line 376 of file test_util.py.

00376 
00377     def test_try_except(self):
00378         s = """
00379             try:
00380                 a = 6
00381             except:
00382                 b = 8"""
00383         self.assertTrue(self.find_binding("a", s))
00384 
00385         s = """
00386             try:
00387                 b = 8
00388             except:
00389                 a = 6"""
00390         self.assertTrue(self.find_binding("a", s))
00391 
00392         s = """
00393             try:
00394                 b = 8
00395             except KeyError:
00396                 pass
00397             except:
00398                 a = 6"""
00399         self.assertTrue(self.find_binding("a", s))
00400 
00401         s = """
00402             try:
00403                 b = 8
00404             except:
00405                 b = 6"""
00406         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 484 of file test_util.py.

00484 
00485     def test_try_except_finally(self):
00486         s = """
00487             try:
00488                 c = 6
00489             except:
00490                 b = 8
00491             finally:
00492                 a = 9"""
00493         self.assertTrue(self.find_binding("a", s))
00494 
00495         s = """
00496             try:
00497                 b = 8
00498             finally:
00499                 a = 6"""
00500         self.assertTrue(self.find_binding("a", s))
00501 
00502         s = """
00503             try:
00504                 b = 8
00505             finally:
00506                 b = 6"""
00507         self.assertFalse(self.find_binding("a", s))
00508 
00509         s = """
00510             try:
00511                 b = 8
00512             except:
00513                 b = 9
00514             finally:
00515                 b = 6"""
00516         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 517 of file test_util.py.

00517 
00518     def test_try_except_finally_nested(self):
00519         s = """
00520             try:
00521                 c = 6
00522             except:
00523                 b = 8
00524             finally:
00525                 try:
00526                     a = 9
00527                 except:
00528                     b = 9
00529                 finally:
00530                     c = 9"""
00531         self.assertTrue(self.find_binding("a", s))
00532 
00533         s = """
00534             try:
00535                 b = 8
00536             finally:
00537                 try:
00538                     pass
00539                 finally:
00540                     a = 6"""
00541         self.assertTrue(self.find_binding("a", s))
00542 
00543         s = """
00544             try:
00545                 b = 8
00546             finally:
00547                 try:
00548                     b = 6
00549                 finally:
00550                     b = 7"""
00551         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 407 of file test_util.py.

00407 
00408     def test_try_except_nested(self):
00409         s = """
00410             try:
00411                 try:
00412                     a = 6
00413                 except:
00414                     pass
00415             except:
00416                 b = 8"""
00417         self.assertTrue(self.find_binding("a", s))
00418 
00419         s = """
00420             try:
00421                 b = 8
00422             except:
00423                 try:
00424                     a = 6
00425                 except:
00426                     pass"""
00427         self.assertTrue(self.find_binding("a", s))
00428 
00429         s = """
00430             try:
00431                 b = 8
00432             except:
00433                 try:
00434                     pass
00435                 except:
00436                     a = 6"""
00437         self.assertTrue(self.find_binding("a", s))
00438 
00439         s = """
00440             try:
00441                 try:
00442                     b = 8
00443                 except KeyError:
00444                     pass
00445                 except:
00446                     a = 6
00447             except:
00448                 pass"""
00449         self.assertTrue(self.find_binding("a", s))
00450 
00451         s = """
00452             try:
00453                 pass
00454             except:
00455                 try:
00456                     b = 8
00457                 except KeyError:
00458                     pass
00459                 except:
00460                     a = 6"""
00461         self.assertTrue(self.find_binding("a", s))
00462 
00463         s = """
00464             try:
00465                 b = 8
00466             except:
00467                 b = 6"""
00468         self.assertFalse(self.find_binding("a", s))
00469 
00470         s = """
00471             try:
00472                 try:
00473                     b = 8
00474                 except:
00475                     c = d
00476             except:
00477                 try:
00478                     b = 6
00479                 except:
00480                     t = 8
00481                 except:
00482                     o = y"""
00483         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:

Definition at line 162 of file test_util.py.

00162 
00163     def test_tuple_assignment(self):
00164         self.assertTrue(self.find_binding("a", "(a,) = b"))
00165         self.assertTrue(self.find_binding("a", "(a, b, c) = [b, c, d]"))
00166         self.assertTrue(self.find_binding("a", "(c, (d, a), b) = foo()"))
00167         self.assertTrue(self.find_binding("a", "(a, b) = foo().foo[6][foo]"))
00168         self.assertFalse(self.find_binding("a", "(foo, b) = (b, a)"))
00169         self.assertFalse(self.find_binding("a", "(foo, (b, c)) = (a, b, c)"))

Here is the call graph for this function:

Definition at line 359 of file test_util.py.

00359 
00360     def test_while(self):
00361         self.assertTrue(self.find_binding("a", "while b in r: a = c"))
00362         self.assertFalse(self.find_binding("a", "while a in r: d = e"))

Here is the call graph for this function:

Definition at line 363 of file test_util.py.

00363 
00364     def test_while_nested(self):
00365         s = """
00366             while b in r:
00367                 while c in d:
00368                     a = c"""
00369         self.assertTrue(self.find_binding("a", s))
00370 
00371         s = """
00372             while b in r:
00373                 while c in d:
00374                     c = a"""
00375         self.assertFalse(self.find_binding("a", s))

Here is the call graph for this function:


The documentation for this class was generated from the following file: