diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-03-07 21:04:55 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-03-07 22:59:36 +0100 |
commit | 7114fa72ee425bba2524d5ccbe67d0ae84ed9284 (patch) | |
tree | 8e8975b5e592942fb07779f2d79098ec99fdb2cd | |
parent | 52fd4d0e704d1380ebbe2b2895b6abea8f53a430 (diff) | |
download | pylint-git-7114fa72ee425bba2524d5ccbe67d0ae84ed9284.tar.gz |
Migrate func_w0612.py to new functional tests
-rw-r--r-- | tests/functional/u/unused/unused_variable.py | 39 | ||||
-rw-r--r-- | tests/functional/u/unused/unused_variable.txt | 6 | ||||
-rw-r--r-- | tests/input/func_w0612.py | 37 | ||||
-rw-r--r-- | tests/messages/func_w0612.txt | 6 | ||||
-rw-r--r-- | tests/test_func.py | 3 |
5 files changed, 45 insertions, 46 deletions
diff --git a/tests/functional/u/unused/unused_variable.py b/tests/functional/u/unused/unused_variable.py index e57e2abb1..e7e934aca 100644 --- a/tests/functional/u/unused/unused_variable.py +++ b/tests/functional/u/unused/unused_variable.py @@ -65,3 +65,42 @@ def hello(arg): if arg: return True raise Exception + +# pylint: disable=redefined-outer-name, wrong-import-position,misplaced-future +from __future__ import print_function +PATH = OS = collections = deque = None + + +def function(matches): + """"yo""" + aaaa = 1 # [unused-variable] + index = -1 + for match in matches: + index += 1 + print(match) + + +def visit_if(self, node): + """increments the branches counter""" + branches = 1 + # don't double count If nodes coming from some 'elif' + if node.orelse and len(node.orelse) > 1: + branches += 1 + self.inc_branch(branches) + self.stmts += branches + + +def test_global(): + """ Test various assignments of global + variables through imports. + """ + global PATH, OS, collections, deque # [global-statement] + from os import path as PATH + import os as OS + import collections + from collections import deque + # make sure that these triggers unused-variable + from sys import platform # [unused-import] + from sys import version as VERSION # [unused-import] + import this # [unused-import] + import re as RE # [unused-import] diff --git a/tests/functional/u/unused/unused_variable.txt b/tests/functional/u/unused/unused_variable.txt index c11bc0dcc..b38362b29 100644 --- a/tests/functional/u/unused/unused_variable.txt +++ b/tests/functional/u/unused/unused_variable.txt @@ -12,3 +12,9 @@ unused-import:54:4:unused_import_from:Unused wraps imported from functools as ab unused-import:55:4:unused_import_from:Unused namedtuple imported from collections unused-import:59:4:unused_import_in_function:Unused hexdigits imported from string unused-variable:64:4:hello:Unused variable 'my_var' +unused-variable:76:4:function:Unused variable 'aaaa' +global-statement:97:4:test_global:Using the global statement +unused-import:103:4:test_global:Unused platform imported from sys +unused-import:104:4:test_global:Unused version imported from sys as VERSION +unused-import:105:4:test_global:Unused import this +unused-import:106:4:test_global:Unused re imported as RE diff --git a/tests/input/func_w0612.py b/tests/input/func_w0612.py deleted file mode 100644 index 2c6fee8b8..000000000 --- a/tests/input/func_w0612.py +++ /dev/null @@ -1,37 +0,0 @@ -"""test unused variable -""" -# pylint: disable=invalid-name, redefined-outer-name, no-absolute-import,import-outside-toplevel -from __future__ import print_function -PATH = OS = collections = deque = None - -def function(matches): - """"yo""" - aaaa = 1 - index = -1 - for match in matches: - index += 1 - print(match) - -def visit_if(self, node): - """increments the branches counter""" - branches = 1 - # don't double count If nodes coming from some 'elif' - if node.orelse and len(node.orelse) > 1: - branches += 1 - self.inc_branch(branches) - self.stmts += branches - -def test_global(): - """ Test various assignments of global - variables through imports. - """ - global PATH, OS, collections, deque - from os import path as PATH - import os as OS - import collections - from collections import deque - # make sure that these triggers unused-variable - from sys import platform - from sys import version as VERSION - import this - import re as RE diff --git a/tests/messages/func_w0612.txt b/tests/messages/func_w0612.txt deleted file mode 100644 index a6d8bdc29..000000000 --- a/tests/messages/func_w0612.txt +++ /dev/null @@ -1,6 +0,0 @@ -W: 9:function: Unused variable 'aaaa' -W: 28:test_global: Using the global statement -W: 34:test_global: Unused platform imported from sys -W: 35:test_global: Unused version imported from sys as VERSION -W: 36:test_global: Unused import this -W: 37:test_global: Unused re imported as RE diff --git a/tests/test_func.py b/tests/test_func.py index 12df30781..6b4464fa4 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -26,7 +26,6 @@ import pytest from pylint.testutils import UPDATE_FILE, UPDATE_OPTION, _get_tests_info, linter -# Configure paths INPUT_DIR = join(dirname(abspath(__file__)), "input") MSG_DIR = join(dirname(abspath(__file__)), "messages") @@ -34,8 +33,6 @@ MSG_DIR = join(dirname(abspath(__file__)), "messages") FILTER_RGX = None INFO_TEST_RGX = re.compile(r"^func_i\d\d\d\d$") -# Classes - def exception_str(self, ex): # pylint: disable=unused-argument """function used to replace default __str__ method of exception instances""" |