summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCosmin Poieana <cmin@ropython.org>2014-12-05 18:25:50 +0200
committerCosmin Poieana <cmin@ropython.org>2014-12-05 18:25:50 +0200
commit4598e5f719661cb2f40548fa14f1bcfda87d7a6d (patch)
treefab5b244f8d0c4a67cae5ba4aedb160049b23b62 /test
parent1931de081093394f4a9523da77b3f924a91b8ce2 (diff)
parentda5fe0d419cea817af97b04e167e00892089d821 (diff)
downloadpylint-git-4598e5f719661cb2f40548fa14f1bcfda87d7a6d.tar.gz
Merge; Fix open mode bug
--HG-- branch : open_mode
Diffstat (limited to 'test')
-rw-r--r--test/functional/bad_open_mode.py3
-rw-r--r--test/functional/bad_open_mode.txt1
-rw-r--r--test/functional/bad_open_mode_py3.py1
-rw-r--r--test/functional/bad_open_mode_py3.txt1
-rw-r--r--test/functional/invalid_exceptions_caught.py6
-rw-r--r--test/functional/invalid_exceptions_caught.txt3
-rw-r--r--test/functional/super_checks.py16
-rw-r--r--test/functional/super_checks.txt1
-rw-r--r--test/input/func_dangerous_default.py12
-rw-r--r--test/input/func_typecheck_non_callable_call.py47
-rw-r--r--test/messages/func_dangerous_default.txt6
-rw-r--r--test/messages/func_dangerous_default_py30.txt6
12 files changed, 97 insertions, 6 deletions
diff --git a/test/functional/bad_open_mode.py b/test/functional/bad_open_mode.py
index 26d25c944..86598502e 100644
--- a/test/functional/bad_open_mode.py
+++ b/test/functional/bad_open_mode.py
@@ -12,7 +12,8 @@ open('foo.bar', buffering=2)
WRITE_MODE = 'w'
open('foo.bar', 'U' + WRITE_MODE + 'z') # [bad-open-mode]
open('foo.bar', 'br') # [bad-open-mode]
-open('foo.bar', 'wU') # [bad-open-mode]
+open('foo.bar', 'wU') # [bad-open-mode]
open('foo.bar', 'r+b')
open('foo.bar', 'r+')
open('foo.bar', 'w+')
+open('foo.bar', 'xb') # [bad-open-mode]
diff --git a/test/functional/bad_open_mode.txt b/test/functional/bad_open_mode.txt
index cd8c14b2b..775c97912 100644
--- a/test/functional/bad_open_mode.txt
+++ b/test/functional/bad_open_mode.txt
@@ -6,3 +6,4 @@ bad-open-mode:10::"""2"" is not a valid mode for open."
bad-open-mode:13::"""Uwz"" is not a valid mode for open."
bad-open-mode:14::"""br"" is not a valid mode for open."
bad-open-mode:15::"""wU"" is not a valid mode for open."
+bad-open-mode:19::"""xb"" is not a valid mode for open."
diff --git a/test/functional/bad_open_mode_py3.py b/test/functional/bad_open_mode_py3.py
index c8bfb0ed3..7229ecada 100644
--- a/test/functional/bad_open_mode_py3.py
+++ b/test/functional/bad_open_mode_py3.py
@@ -11,3 +11,4 @@ open(NAME, "xb")
open(NAME, "rwx") # [bad-open-mode]
open(NAME, "rr") # [bad-open-mode]
open(NAME, "+") # [bad-open-mode]
+open(NAME, "xw") # [bad-open-mode]
diff --git a/test/functional/bad_open_mode_py3.txt b/test/functional/bad_open_mode_py3.txt
index d712ec580..ba3443c32 100644
--- a/test/functional/bad_open_mode_py3.txt
+++ b/test/functional/bad_open_mode_py3.txt
@@ -1,3 +1,4 @@
bad-open-mode:11::"""rwx"" is not a valid mode for open."
bad-open-mode:12::"""rr"" is not a valid mode for open."
bad-open-mode:13::"""+"" is not a valid mode for open."
+bad-open-mode:14::"""xw"" is not a valid mode for open."
diff --git a/test/functional/invalid_exceptions_caught.py b/test/functional/invalid_exceptions_caught.py
index a30378e10..0b54ed710 100644
--- a/test/functional/invalid_exceptions_caught.py
+++ b/test/functional/invalid_exceptions_caught.py
@@ -63,3 +63,9 @@ try:
1 + 46
except EXCEPTION:
print "caught"
+
+try:
+ 1 + 42
+# +1:[catching-non-exception,catching-non-exception,catching-non-exception]
+except (list([4, 5, 6]), None, ZeroDivisionError, 4):
+ print "caught"
diff --git a/test/functional/invalid_exceptions_caught.txt b/test/functional/invalid_exceptions_caught.txt
index ce9ab2a8c..85c721d2e 100644
--- a/test/functional/invalid_exceptions_caught.txt
+++ b/test/functional/invalid_exceptions_caught.txt
@@ -4,3 +4,6 @@ catching-non-exception:31::"Catching an exception which doesn't inherit from Bas
catching-non-exception:52::"Catching an exception which doesn't inherit from BaseException: None"
catching-non-exception:52::"Catching an exception which doesn't inherit from BaseException: list()"
catching-non-exception:57::"Catching an exception which doesn't inherit from BaseException: None"
+catching-non-exception:70::"Catching an exception which doesn't inherit from BaseException: 4"
+catching-non-exception:70::"Catching an exception which doesn't inherit from BaseException: None"
+catching-non-exception:70::"Catching an exception which doesn't inherit from BaseException: list([4, 5, 6])"
diff --git a/test/functional/super_checks.py b/test/functional/super_checks.py
index 287ed5e44..368c60cf4 100644
--- a/test/functional/super_checks.py
+++ b/test/functional/super_checks.py
@@ -44,3 +44,19 @@ class CrashSuper(object):
""" test a crash with this checker """
def __init__(self):
super(Getattr.name, self).__init__() # [bad-super-call]
+
+class Empty(object):
+ """Just an empty class."""
+
+class SuperDifferentScope(object):
+ """Don'emit bad-super-call when the super call is in another scope.
+ For reference, see https://bitbucket.org/logilab/pylint/issue/403.
+ """
+ @staticmethod
+ def test():
+ """Test that a bad-super-call is not emitted for this case."""
+ class FalsePositive(Empty):
+ """The following super is in another scope than `test`."""
+ def __init__(self, arg):
+ super(FalsePositive, self).__init__(arg)
+ super(object, 1).__init__() # [bad-super-call]
diff --git a/test/functional/super_checks.txt b/test/functional/super_checks.txt
index 79f6ae137..8e7da6c89 100644
--- a/test/functional/super_checks.txt
+++ b/test/functional/super_checks.txt
@@ -6,3 +6,4 @@ missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super():INFERENC
bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE
bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super():INFERENCE
bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE
+bad-super-call:62:SuperDifferentScope.test:Bad first argument 'object' given to super():INFERENCE
diff --git a/test/input/func_dangerous_default.py b/test/input/func_dangerous_default.py
index 768f70fec..dcf73805a 100644
--- a/test/input/func_dangerous_default.py
+++ b/test/input/func_dangerous_default.py
@@ -62,3 +62,15 @@ OINK = {
def function13(value=OINK):
"""dictionaries with items should not output item values in error message"""
print value
+
+def function14(value=dict([(1, 2), (1, 2, 3)])):
+ """a dictionary which will not be inferred to a syntax AST, but to an
+ astroid.Instance.
+ """
+ return value
+
+INVALID_DICT = dict([(1, 2), (1, 2, 3)])
+
+def function15(value=INVALID_DICT):
+ """The same situation as function14."""
+ return value
diff --git a/test/input/func_typecheck_non_callable_call.py b/test/input/func_typecheck_non_callable_call.py
index 6d56b90f7..832657d24 100644
--- a/test/input/func_typecheck_non_callable_call.py
+++ b/test/input/func_typecheck_non_callable_call.py
@@ -1,4 +1,4 @@
-# pylint: disable=R0903
+# pylint: disable=R0903,missing-docstring,no-self-use
"""
'E1102': ('%s is not callable',
'Used when an object being called has been infered to a non \
@@ -71,3 +71,48 @@ class PropertyTest(object):
PROP = PropertyTest()
PROP.test(40)
PROP.custom()
+
+# Safe from not-callable when using properties.
+
+class SafeProperty(object):
+ @property
+ def static(self):
+ return staticmethod
+
+ @property
+ def klass(self):
+ return classmethod
+
+ @property
+ def get_lambda(self):
+ return lambda: None
+
+ @property
+ def other_function(self):
+ def function(arg):
+ return arg
+ return function
+
+ @property
+ def dict_builtin(self):
+ return dict
+
+ @property
+ def range_builtin(self):
+ return range
+
+ @property
+ def instance(self):
+ class Empty(object):
+ def __call__(self):
+ return 42
+ return Empty()
+
+PROP1 = SafeProperty()
+PROP1.static(2)
+PROP1.klass(2)
+PROP1.get_lambda()
+PROP1.other_function(4)
+PROP1.dict_builtin()
+PROP1.range_builtin(4)
+PROP1.instance()
diff --git a/test/messages/func_dangerous_default.txt b/test/messages/func_dangerous_default.txt
index ddf94f4dd..8980b7c50 100644
--- a/test/messages/func_dangerous_default.txt
+++ b/test/messages/func_dangerous_default.txt
@@ -1,5 +1,5 @@
W: 7:function1: Dangerous default value [] as argument
-W: 11:function2: Dangerous default value HEHE ({}) as argument
+W: 11:function2: Dangerous default value HEHE (__builtin__.dict) as argument
W: 19:function4: Dangerous default value set() (__builtin__.set) as argument
W: 29:function6: Dangerous default value GLOBAL_SET (__builtin__.set) as argument
W: 33:function7: Dangerous default value dict() (__builtin__.dict) as argument
@@ -8,4 +8,6 @@ W: 41:function9: Dangerous default value [] as argument
W: 45:function10: Dangerous default value {} as argument
W: 49:function11: Dangerous default value list() (__builtin__.list) as argument
W: 53:function12: Dangerous default value dict() (__builtin__.dict) as argument
-W: 62:function13: Dangerous default value OINK ({}) as argument
+W: 62:function13: Dangerous default value OINK (__builtin__.dict) as argument
+W: 66:function14: Dangerous default value dict() (__builtin__.dict) as argument
+W: 74:function15: Dangerous default value INVALID_DICT (__builtin__.dict) as argument
diff --git a/test/messages/func_dangerous_default_py30.txt b/test/messages/func_dangerous_default_py30.txt
index 1a6dbf0b1..eb05c8739 100644
--- a/test/messages/func_dangerous_default_py30.txt
+++ b/test/messages/func_dangerous_default_py30.txt
@@ -1,5 +1,5 @@
W: 7:function1: Dangerous default value [] as argument
-W: 11:function2: Dangerous default value HEHE ({}) as argument
+W: 11:function2: Dangerous default value HEHE (builtins.dict) as argument
W: 19:function4: Dangerous default value set() (builtins.set) as argument
W: 29:function6: Dangerous default value GLOBAL_SET (builtins.set) as argument
W: 33:function7: Dangerous default value dict() (builtins.dict) as argument
@@ -8,4 +8,6 @@ W: 41:function9: Dangerous default value [] as argument
W: 45:function10: Dangerous default value {} as argument
W: 49:function11: Dangerous default value list() (builtins.list) as argument
W: 53:function12: Dangerous default value dict() (builtins.dict) as argument
-W: 62:function13: Dangerous default value OINK ({}) as argument
+W: 62:function13: Dangerous default value OINK (builtins.dict) as argument
+W: 66:function14: Dangerous default value dict() (builtins.dict) as argument
+W: 74:function15: Dangerous default value INVALID_DICT (builtins.dict) as argument