Python lib2to3.fixer_util.find_binding() Examples
The following are 30
code examples of lib2to3.fixer_util.find_binding().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
lib2to3.fixer_util
, or try the search function
.
Example #1
Source File: test_util.py From Computable with MIT License | 6 votes |
def test_class_def(self): self.assertTrue(self.find_binding("a", "class a: pass")) self.assertTrue(self.find_binding("a", "class a(): pass")) self.assertTrue(self.find_binding("a", "class a(b): pass")) self.assertTrue(self.find_binding("a", "class a(b, c=8): pass")) self.assertFalse(self.find_binding("a", "class d: pass")) self.assertFalse(self.find_binding("a", "class d(a): pass")) self.assertFalse(self.find_binding("a", "class d(b, a=7): pass")) self.assertFalse(self.find_binding("a", "class d(b, *a): pass")) self.assertFalse(self.find_binding("a", "class d(b, **a): pass")) self.assertFalse(self.find_binding("a", "class d: a = 7")) s = """ class d(): class a(): pass""" self.assertFalse(self.find_binding("a", s))
Example #2
Source File: test_util.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_class_def(self): self.assertTrue(self.find_binding("a", "class a: pass")) self.assertTrue(self.find_binding("a", "class a(): pass")) self.assertTrue(self.find_binding("a", "class a(b): pass")) self.assertTrue(self.find_binding("a", "class a(b, c=8): pass")) self.assertFalse(self.find_binding("a", "class d: pass")) self.assertFalse(self.find_binding("a", "class d(a): pass")) self.assertFalse(self.find_binding("a", "class d(b, a=7): pass")) self.assertFalse(self.find_binding("a", "class d(b, *a): pass")) self.assertFalse(self.find_binding("a", "class d(b, **a): pass")) self.assertFalse(self.find_binding("a", "class d: a = 7")) s = """ class d(): class a(): pass""" self.assertFalse(self.find_binding("a", s))
Example #3
Source File: test_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_class_def(self): self.assertTrue(self.find_binding("a", "class a: pass")) self.assertTrue(self.find_binding("a", "class a(): pass")) self.assertTrue(self.find_binding("a", "class a(b): pass")) self.assertTrue(self.find_binding("a", "class a(b, c=8): pass")) self.assertFalse(self.find_binding("a", "class d: pass")) self.assertFalse(self.find_binding("a", "class d(a): pass")) self.assertFalse(self.find_binding("a", "class d(b, a=7): pass")) self.assertFalse(self.find_binding("a", "class d(b, *a): pass")) self.assertFalse(self.find_binding("a", "class d(b, **a): pass")) self.assertFalse(self.find_binding("a", "class d: a = 7")) s = """ class d(): class a(): pass""" self.assertFalse(self.find_binding("a", s))
Example #4
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_simple_import_with_package(self): self.assertTrue(self.find_binding("b", "import b")) self.assertTrue(self.find_binding("b", "import b, c, d")) self.assertFalse(self.find_binding("b", "import b", "b")) self.assertFalse(self.find_binding("b", "import b, c, d", "c"))
Example #5
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_function_def(self): self.assertTrue(self.find_binding("a", "def a(): pass")) self.assertTrue(self.find_binding("a", "def a(b, c, d): pass")) self.assertTrue(self.find_binding("a", "def a(): b = 7")) self.assertFalse(self.find_binding("a", "def d(b, (c, a), e): pass")) self.assertFalse(self.find_binding("a", "def d(a=7): pass")) self.assertFalse(self.find_binding("a", "def d(a): pass")) self.assertFalse(self.find_binding("a", "def d(): a = 7")) s = """ def d(): def a(): pass""" self.assertFalse(self.find_binding("a", s))
Example #6
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_for(self): self.assertTrue(self.find_binding("a", "for a in r: pass")) self.assertTrue(self.find_binding("a", "for a, b in r: pass")) self.assertTrue(self.find_binding("a", "for (a, b) in r: pass")) self.assertTrue(self.find_binding("a", "for c, (a,) in r: pass")) self.assertTrue(self.find_binding("a", "for c, (a, b) in r: pass")) self.assertTrue(self.find_binding("a", "for c in r: a = c")) self.assertFalse(self.find_binding("a", "for c in a: pass"))
Example #7
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_from_import_as_with_package(self): # Because it would take a lot of special-case code in the fixers # to deal with from foo import bar as baz, we'll simply always # fail if there is an "from ... import ... as ..." self.assertFalse(self.find_binding("a", "from x import b as a", "x")) self.assertFalse(self.find_binding("a", "from x import g as a, d as b", "x")) self.assertFalse(self.find_binding("a", "from x.b import t as a", "x.b")) self.assertFalse(self.find_binding("a", "from x.b import g as a, d", "x.b")) self.assertFalse(self.find_binding("a", "from a import b as t", "a")) self.assertFalse(self.find_binding("a", "from a import b as t", "b")) self.assertFalse(self.find_binding("a", "from a import b as t", "t"))
Example #8
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_from_import_as(self): self.assertTrue(self.find_binding("a", "from x import b as a")) self.assertTrue(self.find_binding("a", "from x import g as a, d as b")) self.assertTrue(self.find_binding("a", "from x.b import t as a")) self.assertTrue(self.find_binding("a", "from x.b import g as a, d")) self.assertFalse(self.find_binding("a", "from a import b as t")) self.assertFalse(self.find_binding("a", "from a.d import b as t")) self.assertFalse(self.find_binding("a", "from d.a import b as t"))
Example #9
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_import_as(self): self.assertTrue(self.find_binding("a", "import b as a")) self.assertTrue(self.find_binding("a", "import b as a, c, a as f, d")) self.assertFalse(self.find_binding("a", "import a as f")) self.assertFalse(self.find_binding("a", "import b, c as f, d as e"))
Example #10
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_from_import(self): self.assertTrue(self.find_binding("a", "from x import a")) self.assertTrue(self.find_binding("a", "from a import a")) self.assertTrue(self.find_binding("a", "from x import b, c, a, d")) self.assertTrue(self.find_binding("a", "from x.b import a")) self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d")) self.assertFalse(self.find_binding("a", "from a import b")) self.assertFalse(self.find_binding("a", "from a.d import b")) self.assertFalse(self.find_binding("a", "from d.a import b"))
Example #11
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_simple_import(self): self.assertTrue(self.find_binding("a", "import a")) self.assertTrue(self.find_binding("a", "import b, c, a, d")) self.assertFalse(self.find_binding("a", "import b")) self.assertFalse(self.find_binding("a", "import b, c, d"))
Example #12
Source File: test_util.py From Computable with MIT License | 5 votes |
def test_simple_import_with_package(self): self.assertTrue(self.find_binding("b", "import b")) self.assertTrue(self.find_binding("b", "import b, c, d")) self.assertFalse(self.find_binding("b", "import b", "b")) self.assertFalse(self.find_binding("b", "import b, c, d", "c"))
Example #13
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_if(self): self.assertTrue(self.find_binding("a", "if b in r: a = c")) self.assertFalse(self.find_binding("a", "if a in r: d = e"))
Example #14
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_for(self): self.assertTrue(self.find_binding("a", "for a in r: pass")) self.assertTrue(self.find_binding("a", "for a, b in r: pass")) self.assertTrue(self.find_binding("a", "for (a, b) in r: pass")) self.assertTrue(self.find_binding("a", "for c, (a,) in r: pass")) self.assertTrue(self.find_binding("a", "for c, (a, b) in r: pass")) self.assertTrue(self.find_binding("a", "for c in r: a = c")) self.assertFalse(self.find_binding("a", "for c in a: pass"))
Example #15
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_function_def(self): self.assertTrue(self.find_binding("a", "def a(): pass")) self.assertTrue(self.find_binding("a", "def a(b, c, d): pass")) self.assertTrue(self.find_binding("a", "def a(): b = 7")) self.assertFalse(self.find_binding("a", "def d(b, (c, a), e): pass")) self.assertFalse(self.find_binding("a", "def d(a=7): pass")) self.assertFalse(self.find_binding("a", "def d(a): pass")) self.assertFalse(self.find_binding("a", "def d(): a = 7")) s = """ def d(): def a(): pass""" self.assertFalse(self.find_binding("a", s))
Example #16
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_from_import_as_with_package(self): # Because it would take a lot of special-case code in the fixers # to deal with from foo import bar as baz, we'll simply always # fail if there is an "from ... import ... as ..." self.assertFalse(self.find_binding("a", "from x import b as a", "x")) self.assertFalse(self.find_binding("a", "from x import g as a, d as b", "x")) self.assertFalse(self.find_binding("a", "from x.b import t as a", "x.b")) self.assertFalse(self.find_binding("a", "from x.b import g as a, d", "x.b")) self.assertFalse(self.find_binding("a", "from a import b as t", "a")) self.assertFalse(self.find_binding("a", "from a import b as t", "b")) self.assertFalse(self.find_binding("a", "from a import b as t", "t"))
Example #17
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_import_as_with_package(self): self.assertFalse(self.find_binding("a", "import b.c as a", "b.c")) self.assertFalse(self.find_binding("a", "import a as f", "f")) self.assertFalse(self.find_binding("a", "import a as f", "a"))
Example #18
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_while(self): self.assertTrue(self.find_binding("a", "while b in r: a = c")) self.assertFalse(self.find_binding("a", "while a in r: d = e"))
Example #19
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_from_import_as(self): self.assertTrue(self.find_binding("a", "from x import b as a")) self.assertTrue(self.find_binding("a", "from x import g as a, d as b")) self.assertTrue(self.find_binding("a", "from x.b import t as a")) self.assertTrue(self.find_binding("a", "from x.b import g as a, d")) self.assertFalse(self.find_binding("a", "from a import b as t")) self.assertFalse(self.find_binding("a", "from a.d import b as t")) self.assertFalse(self.find_binding("a", "from d.a import b as t"))
Example #20
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_import_as(self): self.assertTrue(self.find_binding("a", "import b as a")) self.assertTrue(self.find_binding("a", "import b as a, c, a as f, d")) self.assertFalse(self.find_binding("a", "import a as f")) self.assertFalse(self.find_binding("a", "import b, c as f, d as e"))
Example #21
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_from_import(self): self.assertTrue(self.find_binding("a", "from x import a")) self.assertTrue(self.find_binding("a", "from a import a")) self.assertTrue(self.find_binding("a", "from x import b, c, a, d")) self.assertTrue(self.find_binding("a", "from x.b import a")) self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d")) self.assertFalse(self.find_binding("a", "from a import b")) self.assertFalse(self.find_binding("a", "from a.d import b")) self.assertFalse(self.find_binding("a", "from d.a import b"))
Example #22
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_simple_import(self): self.assertTrue(self.find_binding("a", "import a")) self.assertTrue(self.find_binding("a", "import b, c, a, d")) self.assertFalse(self.find_binding("a", "import b")) self.assertFalse(self.find_binding("a", "import b, c, d"))
Example #23
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_list_assignment(self): self.assertTrue(self.find_binding("a", "[a] = b")) self.assertTrue(self.find_binding("a", "[a, b, c] = [b, c, d]")) self.assertTrue(self.find_binding("a", "[c, [d, a], b] = foo()")) self.assertTrue(self.find_binding("a", "[a, b] = foo().foo[a][foo]")) self.assertFalse(self.find_binding("a", "[foo, b] = (b, a)")) self.assertFalse(self.find_binding("a", "[foo, [b, c]] = (a, b, c)"))
Example #24
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_tuple_assignment(self): self.assertTrue(self.find_binding("a", "(a,) = b")) self.assertTrue(self.find_binding("a", "(a, b, c) = [b, c, d]")) self.assertTrue(self.find_binding("a", "(c, (d, a), b) = foo()")) self.assertTrue(self.find_binding("a", "(a, b) = foo().foo[6][foo]")) self.assertFalse(self.find_binding("a", "(foo, b) = (b, a)")) self.assertFalse(self.find_binding("a", "(foo, (b, c)) = (a, b, c)"))
Example #25
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_simple_assignment(self): self.assertTrue(self.find_binding("a", "a = b")) self.assertTrue(self.find_binding("a", "a = [b, c, d]")) self.assertTrue(self.find_binding("a", "a = foo()")) self.assertTrue(self.find_binding("a", "a = foo().foo.foo[6][foo]")) self.assertFalse(self.find_binding("a", "foo = a")) self.assertFalse(self.find_binding("a", "foo = (a, b, c)"))
Example #26
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def find_binding(self, name, string, package=None): return fixer_util.find_binding(name, parse(string), package)
Example #27
Source File: test_util.py From ironpython2 with Apache License 2.0 | 5 votes |
def _find_bind_rec(self, name, node): # Search a tree for a binding -- used to find the starting # point for these tests. c = fixer_util.find_binding(name, node) if c: return c for child in node.children: c = self._find_bind_rec(name, child) if c: return c
Example #28
Source File: fix_next_call.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def start_tree(self, tree, filename): super(FixNextCall, self).start_tree(tree, filename) n = find_binding('next', tree) if n: self.warning(n, bind_warning) self.shadowed_next = True else: self.shadowed_next = False
Example #29
Source File: test_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_try_except_finally_nested(self): s = """ try: c = 6 except: b = 8 finally: try: a = 9 except: b = 9 finally: c = 9""" self.assertTrue(self.find_binding("a", s)) s = """ try: b = 8 finally: try: pass finally: a = 6""" self.assertTrue(self.find_binding("a", s)) s = """ try: b = 8 finally: try: b = 6 finally: b = 7""" self.assertFalse(self.find_binding("a", s))
Example #30
Source File: test_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_try_except_finally(self): s = """ try: c = 6 except: b = 8 finally: a = 9""" self.assertTrue(self.find_binding("a", s)) s = """ try: b = 8 finally: a = 6""" self.assertTrue(self.find_binding("a", s)) s = """ try: b = 8 finally: b = 6""" self.assertFalse(self.find_binding("a", s)) s = """ try: b = 8 except: b = 9 finally: b = 6""" self.assertFalse(self.find_binding("a", s))