diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/checkers/unittest_refactoring.py | 10 | ||||
-rw-r--r-- | tests/functional/l/len_checks.txt | 25 | ||||
-rw-r--r-- | tests/functional/u/use/use_implicit_booleaness_not_len.py (renamed from tests/functional/l/len_checks.py) | 54 | ||||
-rw-r--r-- | tests/functional/u/use/use_implicit_booleaness_not_len.txt | 25 |
4 files changed, 59 insertions, 55 deletions
diff --git a/tests/checkers/unittest_refactoring.py b/tests/checkers/unittest_refactoring.py index 4b132e218..3c87a8d33 100644 --- a/tests/checkers/unittest_refactoring.py +++ b/tests/checkers/unittest_refactoring.py @@ -3,7 +3,7 @@ import astroid -from pylint.checkers.refactoring import LenChecker +from pylint.checkers.refactoring import ImplicitBooleanessChecker def test_class_tree_detection() -> None: @@ -24,23 +24,23 @@ class ChildClassWithoutBool(ClassWithoutBool): """ ) with_bool, without_bool, child_with_bool, child_without_bool = module.body - assert LenChecker().base_classes_of_node(with_bool) == [ + assert ImplicitBooleanessChecker().base_classes_of_node(with_bool) == [ "ClassWithBool", "list", "object", ] - assert LenChecker().base_classes_of_node(without_bool) == [ + assert ImplicitBooleanessChecker().base_classes_of_node(without_bool) == [ "ClassWithoutBool", "dict", "object", ] - assert LenChecker().base_classes_of_node(child_with_bool) == [ + assert ImplicitBooleanessChecker().base_classes_of_node(child_with_bool) == [ "ChildClassWithBool", "ClassWithBool", "list", "object", ] - assert LenChecker().base_classes_of_node(child_without_bool) == [ + assert ImplicitBooleanessChecker().base_classes_of_node(child_without_bool) == [ "ChildClassWithoutBool", "ClassWithoutBool", "dict", diff --git a/tests/functional/l/len_checks.txt b/tests/functional/l/len_checks.txt deleted file mode 100644 index f1b96e477..000000000 --- a/tests/functional/l/len_checks.txt +++ /dev/null @@ -1,25 +0,0 @@ -len-as-condition:4:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:7:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:11:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:14:11::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:55:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:60:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:63:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:66:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:69:12::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:72:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:95:11:github_issue_1331_v2:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:98:11:github_issue_1331_v3:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:101:17:github_issue_1331_v4:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:103:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:104:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:124:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:125:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:126:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:127:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:128:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:129:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:130:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -len-as-condition:171:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty -undefined-variable:183:11:github_issue_4215:Undefined variable 'undefined_var' -undefined-variable:185:11:github_issue_4215:Undefined variable 'undefined_var2' diff --git a/tests/functional/l/len_checks.py b/tests/functional/u/use/use_implicit_booleaness_not_len.py index ceeedb549..b4107ac2d 100644 --- a/tests/functional/l/len_checks.py +++ b/tests/functional/u/use/use_implicit_booleaness_not_len.py @@ -1,17 +1,17 @@ # pylint: disable=too-few-public-methods,import-error, missing-docstring, misplaced-comparison-constant # pylint: disable=useless-super-delegation,wrong-import-position,invalid-name, wrong-import-order, condition-evals-to-constant -if len('TEST'): # [len-as-condition] +if len('TEST'): # [use-implicit-booleaness-not-len] pass -if not len('TEST'): # [len-as-condition] +if not len('TEST'): # [use-implicit-booleaness-not-len] pass z = [] -if z and len(['T', 'E', 'S', 'T']): # [len-as-condition] +if z and len(['T', 'E', 'S', 'T']): # [use-implicit-booleaness-not-len] pass -if True or len('TEST'): # [len-as-condition] +if True or len('TEST'): # [use-implicit-booleaness-not-len] pass if len('TEST') == 0: # Should be fine @@ -52,24 +52,24 @@ if z or 10 > len('TEST') != 0: # Should be fine if z: pass -elif len('TEST'): # [len-as-condition] +elif len('TEST'): # [use-implicit-booleaness-not-len] pass if z: pass -elif not len('TEST'): # [len-as-condition] +elif not len('TEST'): # [use-implicit-booleaness-not-len] pass -while len('TEST'): # [len-as-condition] +while len('TEST'): # [use-implicit-booleaness-not-len] pass -while not len('TEST'): # [len-as-condition] +while not len('TEST'): # [use-implicit-booleaness-not-len] pass -while z and len('TEST'): # [len-as-condition] +while z and len('TEST'): # [use-implicit-booleaness-not-len] pass -while not len('TEST') and z: # [len-as-condition] +while not len('TEST') and z: # [use-implicit-booleaness-not-len] pass assert len('TEST') > 0 # Should be fine @@ -92,17 +92,16 @@ def github_issue_1331(*args): assert False, len(args) # Should be fine def github_issue_1331_v2(*args): - assert len(args), args # [len-as-condition] + assert len(args), args # [use-implicit-booleaness-not-len] def github_issue_1331_v3(*args): - assert len(args) or z, args # [len-as-condition] + assert len(args) or z, args # [use-implicit-booleaness-not-len] def github_issue_1331_v4(*args): - assert z and len(args), args # [len-as-condition] - -b = bool(len(z)) # [len-as-condition] -c = bool(len('TEST') or 42) # [len-as-condition] + assert z and len(args), args # [use-implicit-booleaness-not-len] +b = bool(len(z)) # [use-implicit-booleaness-not-len] +c = bool(len('TEST') or 42) # [use-implicit-booleaness-not-len] def github_issue_1879(): @@ -121,13 +120,13 @@ def github_issue_1879(): assert len(ClassWithBool()) assert len(ChildClassWithBool()) - assert len(ClassWithoutBool()) # [len-as-condition] - assert len(ChildClassWithoutBool()) # [len-as-condition] - assert len(range(0)) # [len-as-condition] - assert len([t + 1 for t in []]) # [len-as-condition] - assert len(u + 1 for u in []) # [len-as-condition] - assert len({"1":(v + 1) for v in {}}) # [len-as-condition] - assert len(set((w + 1) for w in set())) # [len-as-condition] + assert len(ClassWithoutBool()) # [use-implicit-booleaness-not-len] + assert len(ChildClassWithoutBool()) # [use-implicit-booleaness-not-len] + assert len(range(0)) # [use-implicit-booleaness-not-len] + assert len([t + 1 for t in []]) # [use-implicit-booleaness-not-len] + assert len(u + 1 for u in []) # [use-implicit-booleaness-not-len] + assert len({"1":(v + 1) for v in {}}) # [use-implicit-booleaness-not-len] + assert len(set((w + 1) for w in set())) # [use-implicit-booleaness-not-len] # pylint: disable=import-outside-toplevel import numpy @@ -168,9 +167,9 @@ def github_issue_1879(): # def function_returning_function(r): # return function_returning_generator(r) - assert len(function_returning_list(z)) # [len-as-condition] + assert len(function_returning_list(z)) # [use-implicit-booleaness-not-len] assert len(function_returning_int(z)) - # This should raise a len-as-conditions once astroid can infer it + # This should raise a use-implicit-booleaness-not-len once astroid can infer it # See https://github.com/PyCQA/pylint/pull/3821#issuecomment-743771514 # assert len(function_returning_generator(z)) # assert len(function_returning_comprehension(z)) @@ -184,3 +183,8 @@ def github_issue_4215(): pass if len(undefined_var2[0]): # [undefined-variable] pass + +# pylint: disable=len-as-condition + +if len('TEST'): + pass diff --git a/tests/functional/u/use/use_implicit_booleaness_not_len.txt b/tests/functional/u/use/use_implicit_booleaness_not_len.txt new file mode 100644 index 000000000..f5020c80e --- /dev/null +++ b/tests/functional/u/use/use_implicit_booleaness_not_len.txt @@ -0,0 +1,25 @@ +use-implicit-booleaness-not-len:4:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:7:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:11:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:14:11::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:55:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:60:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:63:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:66:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:69:12::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:72:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:95:11:github_issue_1331_v2:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:98:11:github_issue_1331_v3:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:101:17:github_issue_1331_v4:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:103:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:104:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:123:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:124:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:125:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:126:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:127:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:128:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:129:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +use-implicit-booleaness-not-len:170:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH +undefined-variable:182:11:github_issue_4215:Undefined variable 'undefined_var':HIGH +undefined-variable:184:11:github_issue_4215:Undefined variable 'undefined_var2':HIGH |