diff options
| author | Torsten Marek <shlomme@gmail.com> | 2014-07-27 23:25:44 +0200 |
|---|---|---|
| committer | Torsten Marek <shlomme@gmail.com> | 2014-07-27 23:25:44 +0200 |
| commit | 8e47a20cb88b7fbf79cc897a27992d3135c77705 (patch) | |
| tree | 775af07d3651d1b94c7409ef3d653fe70f70d880 /test | |
| parent | 057e6818e1236738b7686c6578700df687cdd283 (diff) | |
| download | pylint-8e47a20cb88b7fbf79cc897a27992d3135c77705.tar.gz | |
More test cases moved to the new test framework.
Diffstat (limited to 'test')
21 files changed, 125 insertions, 96 deletions
diff --git a/test/functional/bad_open_mode.py b/test/functional/bad_open_mode.py new file mode 100644 index 0000000..dfbf037 --- /dev/null +++ b/test/functional/bad_open_mode.py @@ -0,0 +1,13 @@ +"""Warnings for using open() with an invalid mode string.""" + +open('foo.bar', 'w', 2) +open('foo.bar', 'rw') # [bad-open-mode] +open(name='foo.bar', buffering=10, mode='rw') # [bad-open-mode] +open(mode='rw', name='foo.bar') # [bad-open-mode] +open('foo.bar', 'U+') # [bad-open-mode] +open('foo.bar', 'rb+') # [bad-open-mode] +open('foo.bar', 'Uw') # [bad-open-mode] +open('foo.bar', 2) +open('foo.bar', buffering=2) +WRITE_MODE = 'w' +open('foo.bar', 'U' + WRITE_MODE + 'z') # [bad-open-mode] diff --git a/test/functional/bad_open_mode.txt b/test/functional/bad_open_mode.txt new file mode 100644 index 0000000..356e02e --- /dev/null +++ b/test/functional/bad_open_mode.txt @@ -0,0 +1,7 @@ +bad-open-mode:4::"rw" is not a valid mode for open. +bad-open-mode:5::"rw" is not a valid mode for open. +bad-open-mode:6::"rw" is not a valid mode for open. +bad-open-mode:7::"U+" is not a valid mode for open. +bad-open-mode:8::"rb+" is not a valid mode for open. +bad-open-mode:9::"Uw" is not a valid mode for open. +bad-open-mode:13::"Uwz" is not a valid mode for open. diff --git a/test/functional/invalid_encoded_data.py b/test/functional/invalid_encoded_data.py new file mode 100644 index 0000000..743031c --- /dev/null +++ b/test/functional/invalid_encoded_data.py @@ -0,0 +1,5 @@ +# coding: utf-8 +"""Test data file with encoding errors.""" + + +STR = 'СуÑествительное' # [invalid-encoded-data] diff --git a/test/functional/invalid_encoded_data.txt b/test/functional/invalid_encoded_data.txt new file mode 100644 index 0000000..dc23869 --- /dev/null +++ b/test/functional/invalid_encoded_data.txt @@ -0,0 +1 @@ +invalid-encoded-data:5::Cannot decode using encoding "utf-8", unexpected byte at position 11 diff --git a/test/functional/invalid_exceptions_caught.py b/test/functional/invalid_exceptions_caught.py new file mode 100644 index 0000000..99872d2 --- /dev/null +++ b/test/functional/invalid_exceptions_caught.py @@ -0,0 +1,47 @@ +"""Test for catching non-exceptions.""" +import socket + + +class MyException(object): + """Custom 'exception'.""" + +class MySecondException(object): + """Custom 'exception'.""" + +class MyGoodException(Exception): + """Custom exception.""" + +class MySecondGoodException(MyGoodException): + """Custom exception.""" + +class SkipException(socket.error): + """Not an exception for Python 2, but one in 3.""" + +class SecondSkipException(SkipException): + """Also a good exception.""" + +try: + 1 + 1 +except MyException: # [catching-non-exception] + print "caught" + +try: + 1 + 2 +# +1:[catching-non-exception,catching-non-exception] +except (MyException, MySecondException): + print "caught" + +try: + 1 + 3 +except MyGoodException: + print "caught" + +try: + 1 + 3 +except (MyGoodException, MySecondGoodException): + print "caught" + +try: + 1 + 3 +except (SkipException, SecondSkipException): + print "caught" diff --git a/test/functional/invalid_exceptions_caught.txt b/test/functional/invalid_exceptions_caught.txt new file mode 100644 index 0000000..530ef9a --- /dev/null +++ b/test/functional/invalid_exceptions_caught.txt @@ -0,0 +1,3 @@ +catching-non-exception:25::Catching an exception which doesn't inherit from BaseException: MyException +catching-non-exception:31::Catching an exception which doesn't inherit from BaseException: MyException +catching-non-exception:31::Catching an exception which doesn't inherit from BaseException: MySecondException diff --git a/test/functional/missing_self_argument.py b/test/functional/missing_self_argument.py new file mode 100644 index 0000000..6477fcf --- /dev/null +++ b/test/functional/missing_self_argument.py @@ -0,0 +1,20 @@ +"""Checks that missing self in method defs don't crash Pylint.""" + + + +class MyClass(object): + """A class with some methods missing self args.""" + + def __init__(self): + self.var = "var" + + def method(): # [no-method-argument] + """A method without a self argument.""" + + def setup(): # [no-method-argument] + """A method without a self argument, but usage.""" + self.var = 1 # [undefined-variable] + + def correct(self): + """Correct.""" + self.var = "correct" diff --git a/test/functional/missing_self_argument.txt b/test/functional/missing_self_argument.txt new file mode 100644 index 0000000..3f7f7f2 --- /dev/null +++ b/test/functional/missing_self_argument.txt @@ -0,0 +1,4 @@ +no-method-argument:11:MyClass.method:Method has no argument +no-method-argument:13:MyClass.met:Method has no argument +no-method-argument:14:MyClass.setup:Method has no argument +undefined-variable:16:MyClass.setup:Undefined variable 'self' diff --git a/test/functional/superfluous_parens.py b/test/functional/superfluous_parens.py new file mode 100644 index 0000000..35a8d0a --- /dev/null +++ b/test/functional/superfluous_parens.py @@ -0,0 +1,18 @@ +"""Test the superfluous-parens warning.""" + + +if (3 == 5): # [superfluous-parens] + pass +if not (3 == 5): # [superfluous-parens] + pass +if not (3 or 5): + pass +for (x) in (1, 2, 3): # [superfluous-parens] + print x +if (1) in (1, 2, 3): # [superfluous-parens] + pass +if (1, 2) in (1, 2, 3): + pass +DICT = {'a': 1, 'b': 2} +del(DICT['b']) # [superfluous-parens] +del DICT['a'] diff --git a/test/functional/superfluous_parens.txt b/test/functional/superfluous_parens.txt new file mode 100644 index 0000000..9b203ee --- /dev/null +++ b/test/functional/superfluous_parens.txt @@ -0,0 +1,5 @@ +superfluous-parens:4::Unnecessary parens after 'if' keyword +superfluous-parens:6::Unnecessary parens after 'not' keyword +superfluous-parens:10::Unnecessary parens after 'for' keyword +superfluous-parens:12::Unnecessary parens after 'if' keyword +superfluous-parens:17::Unnecessary parens after 'del' keyword diff --git a/test/input/func_bad_open_mode.py b/test/input/func_bad_open_mode.py deleted file mode 100644 index fefa399..0000000 --- a/test/input/func_bad_open_mode.py +++ /dev/null @@ -1,15 +0,0 @@ -"""Warnings for using open() with an invalid mode string.""" - -__revision__ = 0 - -open('foo.bar', 'w', 2) -open('foo.bar', 'rw') -open(name='foo.bar', buffering=10, mode='rw') -open(mode='rw', name='foo.bar') -open('foo.bar', 'U+') -open('foo.bar', 'rb+') -open('foo.bar', 'Uw') -open('foo.bar', 2) -open('foo.bar', buffering=2) -WRITE_MODE = 'w' -open('foo.bar', 'U' + WRITE_MODE + 'z') diff --git a/test/input/func_invalid_encoded_data.py b/test/input/func_invalid_encoded_data.py deleted file mode 100644 index a465e3c..0000000 --- a/test/input/func_invalid_encoded_data.py +++ /dev/null @@ -1,6 +0,0 @@ -# coding: utf-8 -"""Test data file with encoding errors.""" - -__revision__ = 0 - -STR = 'СуÑествительное' diff --git a/test/input/func_method_missing_self.py b/test/input/func_method_missing_self.py deleted file mode 100644 index 955fafc..0000000 --- a/test/input/func_method_missing_self.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Checks that missing self in method defs don't crash Pylint ! -""" - -__revision__ = '' - - -class MyClass(object): - """SimpleClass - """ - - def __init__(self): - self.var = "var" - - def met(): - """Checks that missing self dont crash Pylint ! - """ - - def correct(self): - """yo""" - self.var = "correct" - -if __name__ == '__main__': - OBJ = MyClass() - diff --git a/test/input/func_method_without_self_but_self_assignment.py b/test/input/func_method_without_self_but_self_assignment.py deleted file mode 100644 index ef1bb60..0000000 --- a/test/input/func_method_without_self_but_self_assignment.py +++ /dev/null @@ -1,15 +0,0 @@ -# pylint: disable=R0903 -"""regression test: setup() leads to "unable to load module..." -""" - -__revision__ = 1 - -class Example(object): - """bla""" - - def __init__(self): - pass - - def setup(): - "setup without self" - self.foo = 1 diff --git a/test/input/func_superfluous_parens.py b/test/input/func_superfluous_parens.py deleted file mode 100644 index 112ab2b..0000000 --- a/test/input/func_superfluous_parens.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Test the superfluous-parens warning.""" - -__revision__ = 1 - -if (3 == 5): - pass -if not (3 == 5): - pass -if not (3 or 5): - pass -for (x) in (1, 2, 3): - print x -if (1) in (1, 2, 3): - pass -if (1, 2) in (1, 2, 3): - pass -DICT = {'a': 1, 'b': 2} -del(DICT['b']) -del DICT['a'] diff --git a/test/messages/func_bad_open_mode.txt b/test/messages/func_bad_open_mode.txt deleted file mode 100644 index d785d17..0000000 --- a/test/messages/func_bad_open_mode.txt +++ /dev/null @@ -1,7 +0,0 @@ -W: 6: "rw" is not a valid mode for open. -W: 7: "rw" is not a valid mode for open. -W: 8: "rw" is not a valid mode for open. -W: 9: "U+" is not a valid mode for open. -W: 10: "rb+" is not a valid mode for open. -W: 11: "Uw" is not a valid mode for open. -W: 15: "Uwz" is not a valid mode for open. diff --git a/test/messages/func_invalid_encoded_data.txt b/test/messages/func_invalid_encoded_data.txt deleted file mode 100644 index 4a5c17e..0000000 --- a/test/messages/func_invalid_encoded_data.txt +++ /dev/null @@ -1 +0,0 @@ -W: 6: Cannot decode using encoding "utf-8", unexpected byte at position 11 diff --git a/test/messages/func_method_missing_self.txt b/test/messages/func_method_missing_self.txt deleted file mode 100644 index 861871f..0000000 --- a/test/messages/func_method_missing_self.txt +++ /dev/null @@ -1 +0,0 @@ -E: 14:MyClass.met: Method has no argument diff --git a/test/messages/func_method_without_self_but_self_assignment.txt b/test/messages/func_method_without_self_but_self_assignment.txt deleted file mode 100644 index da5ee02..0000000 --- a/test/messages/func_method_without_self_but_self_assignment.txt +++ /dev/null @@ -1,2 +0,0 @@ -E: 13:Example.setup: Method has no argument -E: 15:Example.setup: Undefined variable 'self' diff --git a/test/messages/func_superfluous_parens.txt b/test/messages/func_superfluous_parens.txt deleted file mode 100644 index 77ff186..0000000 --- a/test/messages/func_superfluous_parens.txt +++ /dev/null @@ -1,5 +0,0 @@ -C: 5: Unnecessary parens after 'if' keyword -C: 7: Unnecessary parens after 'not' keyword -C: 11: Unnecessary parens after 'for' keyword -C: 13: Unnecessary parens after 'if' keyword -C: 18: Unnecessary parens after 'del' keyword diff --git a/test/test_func.py b/test/test_func.py index e34c0a2..0c09b5e 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -47,7 +47,8 @@ class TestTests(testlib.TestCase): PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310', 'E0202', 'W0711', 'W0108', 'E0603', 'W0710', 'E0710', 'E0711', 'W1001', 'E1124', 'E1120', 'E1121', 'E1123', 'E1003', 'E1002', 'W0212', - 'W0109', 'E1004', 'W0604', 'W0601', 'W0602', 'C0112', 'C0330']) + 'W0109', 'E1004', 'W0604', 'W0601', 'W0602', 'C0112', 'C0330', + 'C0325', 'E0211', 'W1501']) @testlib.tag('coverage') def test_exhaustivity(self): |
