summaryrefslogtreecommitdiff
path: root/test/functional/undefined_variable.py
diff options
context:
space:
mode:
authorTorsten Marek <shlomme@gmail.com>2014-07-25 16:01:49 +0200
committerTorsten Marek <shlomme@gmail.com>2014-07-25 16:01:49 +0200
commit42089c9c81a4c7c4c581ab50f22eb1b68669bb03 (patch)
tree56a4f3d21d3f528f2da55a705fb985b0faefee55 /test/functional/undefined_variable.py
parentf73e3ee23822322772a816673c8221ac5e7a44e0 (diff)
downloadpylint-git-42089c9c81a4c7c4c581ab50f22eb1b68669bb03.tar.gz
Port more testcases to the new framework.
Diffstat (limited to 'test/functional/undefined_variable.py')
-rw-r--r--test/functional/undefined_variable.py116
1 files changed, 116 insertions, 0 deletions
diff --git a/test/functional/undefined_variable.py b/test/functional/undefined_variable.py
new file mode 100644
index 000000000..25f014596
--- /dev/null
+++ b/test/functional/undefined_variable.py
@@ -0,0 +1,116 @@
+"""Test warnings about access to undefined variables."""
+# pylint: disable=too-few-public-methods, no-init, no-self-use
+
+DEFINED = 1
+
+if DEFINED != 1:
+ if DEFINED in (unknown, DEFINED): # [undefined-variable]
+ DEFINED += 1
+
+
+def in_method(var):
+ """method doc"""
+ var = nomoreknown # [undefined-variable]
+ assert var
+
+DEFINED = {DEFINED:__revision__} # [undefined-variable]
+# +1:[undefined-variable]
+DEFINED[__revision__] = OTHER = 'move this is astroid test'
+
+OTHER += '$'
+
+def bad_default(var, default=unknown2): # [undefined-variable]
+ """function with defaut arg's value set to an unexistant name"""
+ print var, default
+ print xxxx # [undefined-variable]
+ augvar += 1 # [undefined-variable,unused-variable]
+ del vardel # [undefined-variable]
+
+LMBD = lambda x, y=doesnotexist: x+y # [undefined-variable]
+LMBD2 = lambda x, y: x+z # [undefined-variable]
+
+try:
+ POUET # don't catch me
+except NameError:
+ POUET = 'something'
+
+try:
+ POUETT # don't catch me
+except Exception: # pylint:disable = broad-except
+ POUETT = 'something'
+
+try:
+ POUETTT # don't catch me
+except: # pylint:disable = bare-except
+ POUETTT = 'something'
+
+print POUET, POUETT, POUETTT
+
+
+try:
+ PLOUF # [used-before-assignment]
+except ValueError:
+ PLOUF = 'something'
+
+print PLOUF
+
+def if_branch_test(something):
+ """hop"""
+ if something == 0:
+ if xxx == 1: # [used-before-assignment]
+ pass
+ else:
+ print xxx
+ xxx = 3
+
+
+def decorator(arg):
+ """Decorator with one argument."""
+ return lambda: list(arg)
+
+
+@decorator(arg=[i * 2 for i in range(15)])
+def func1():
+ """A function with a decorator that contains a listcomp."""
+
+@decorator(arg=(i * 2 for i in range(15)))
+def func2():
+ """A function with a decorator that contains a genexpr."""
+
+@decorator(lambda x: x > 0)
+def main():
+ """A function with a decorator that contains a lambda."""
+
+# Test shared scope.
+
+def test_arguments(arg=TestClass): # [used-before-assignment]
+ """ TestClass isn't defined yet. """
+ return arg
+
+class TestClass(Ancestor): # [used-before-assignment]
+ """ contains another class, which uses an undefined ancestor. """
+
+ class MissingAncestor(Ancestor1): # [used-before-assignment]
+ """ no op """
+
+ def test1(self):
+ """ It should trigger here, because the two classes
+ have the same scope.
+ """
+ class UsingBeforeDefinition(Empty): # [used-before-assignment]
+ """ uses Empty before definition """
+ class Empty(object):
+ """ no op """
+ return UsingBeforeDefinition
+
+ def test(self):
+ """ Ancestor isn't defined yet, but we don't care. """
+ class MissingAncestor1(Ancestor):
+ """ no op """
+ return MissingAncestor1
+
+class Ancestor(object):
+ """ No op """
+
+class Ancestor1(object):
+ """ No op """