diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-11-22 15:21:27 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-11-23 09:50:24 +0100 |
commit | 72d3525b058d264bdef1a7f3276b12e4a64162e6 (patch) | |
tree | 79a3be1d8c224162c3fb832ca36bf4dbeaa6b4ec /tests/extensions | |
parent | 9e32192fe7bf77281d0dfbc107984b751983e113 (diff) | |
download | pylint-git-72d3525b058d264bdef1a7f3276b12e4a64162e6.tar.gz |
Migrate test for extension to functional tests
This permit to upgrade the fixtures in pre-commit.
Diffstat (limited to 'tests/extensions')
21 files changed, 0 insertions, 1100 deletions
diff --git a/tests/extensions/data/bad_builtin.py b/tests/extensions/data/bad_builtin.py deleted file mode 100644 index fd3e5c054..000000000 --- a/tests/extensions/data/bad_builtin.py +++ /dev/null @@ -1,4 +0,0 @@ -# pylint: disable=missing-docstring - -TEST = map(str, (1, 2, 3)) # [bad-builtin] -TEST1 = filter(str, (1, 2, 3)) # [bad-builtin] diff --git a/tests/extensions/data/broad_try_clause.py b/tests/extensions/data/broad_try_clause.py deleted file mode 100644 index 2bbc4e7a2..000000000 --- a/tests/extensions/data/broad_try_clause.py +++ /dev/null @@ -1,49 +0,0 @@ -# pylint: disable=missing-docstring, invalid-name - -MY_DICTIONARY = {"key_one": 1, "key_two": 2, "key_three": 3} - -try: # [max-try-statements] - value = MY_DICTIONARY["key_one"] - value += 1 - print("This one has an except clause only.") -except KeyError: - pass - -try: # [max-try-statements] - value = MY_DICTIONARY["key_one"] - value += 1 - print("This one has a finally clause only.") -finally: - pass - -try: # [max-try-statements] - value = MY_DICTIONARY["key_one"] - value += 1 - print("This one has an except clause...") - print("and also a finally clause!") -except KeyError: - pass -finally: - pass - -try: # [max-try-statements] - if "key_one" in MY_DICTIONARY: - entered_if_body = True - print("This verifies that content inside of an if statement is counted too.") - else: - entered_if_body = False - - while False: - print("This verifies that content inside of a while loop is counted too.") - - for item in []: - print("This verifies that content inside of a for loop is counted too.") - - -except KeyError: - pass - -try: - value = MY_DICTIONARY["key_one"] -except KeyError: - value = 0 diff --git a/tests/extensions/data/compare_to_zero.py b/tests/extensions/data/compare_to_zero.py deleted file mode 100644 index 29fd13994..000000000 --- a/tests/extensions/data/compare_to_zero.py +++ /dev/null @@ -1,28 +0,0 @@ -# pylint: disable=literal-comparison,missing-docstring - -X = 123 -Y = len('test') - -if X is 0: # [compare-to-zero] - pass - -if Y is not 0: # [compare-to-zero] - pass - -if X == 0: # [compare-to-zero] - pass - -if Y != 0: # [compare-to-zero] - pass - -if X > 0: - pass - -if X < 0: - pass - -if 0 < X: - pass - -if 0 > X: - pass diff --git a/tests/extensions/data/docstring.py b/tests/extensions/data/docstring.py deleted file mode 100644 index 8f34c657f..000000000 --- a/tests/extensions/data/docstring.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Checks of Dosctrings 'docstring-first-line-empty' 'bad-docstring-quotes'""" - - -def check_messages(*messages): - """ - docstring""" - return messages - -def function2(): - """Test Ok""" - -class FFFF: - """ - Test Docstring First Line Empty - """ - - def method1(self): - ''' - Test Triple Single Quotes docstring - ''' - - def method2(self): - "bad docstring 1" - - def method3(self): - 'bad docstring 2' - - def method4(self): - ' """bad docstring 3 ' - - @check_messages('bad-open-mode', 'redundant-unittest-assert', - 'deprecated-module') - def method5(self): - """Test OK 1 with decorators""" - - def method6(self): - r"""Test OK 2 with raw string""" - - def method7(self): - u"""Test OK 3 with unicode string""" diff --git a/tests/extensions/data/elif.py b/tests/extensions/data/elif.py deleted file mode 100644 index 22e79c1db..000000000 --- a/tests/extensions/data/elif.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Checks use of "else if" triggers a refactor message""" - -def my_function(): - """docstring""" - myint = 2 - if myint > 5: - pass - else: - if myint <= 5: - pass - else: - myint = 3 - if myint > 2: - if myint > 3: - pass - elif myint == 3: - pass - elif myint < 3: - pass - else: - if myint: - pass - else: - if myint: - pass - myint = 4 diff --git a/tests/extensions/data/empty_comment.py b/tests/extensions/data/empty_comment.py deleted file mode 100644 index 8a18df2eb..000000000 --- a/tests/extensions/data/empty_comment.py +++ /dev/null @@ -1,9 +0,0 @@ -"""empty-comment test-case""" -A = 5 # -# -A = '#' + '1' -print(A) # -print("A=", A) # should not be an error# -A = "#pe\0ace#love#" # -A = "peace#love" # \0 peace'#'''' love#peace'''-'#love'-"peace#love"# -####### diff --git a/tests/extensions/data/empty_string_comparison.py b/tests/extensions/data/empty_string_comparison.py deleted file mode 100644 index c6dcf8ea8..000000000 --- a/tests/extensions/data/empty_string_comparison.py +++ /dev/null @@ -1,16 +0,0 @@ -# pylint: disable=literal-comparison,missing-docstring - -X = '' -Y = 'test' - -if X is '': # [compare-to-empty-string] - pass - -if Y is not "": # [compare-to-empty-string] - pass - -if X == "": # [compare-to-empty-string] - pass - -if Y != '': # [compare-to-empty-string] - pass diff --git a/tests/extensions/data/mccabe.py b/tests/extensions/data/mccabe.py deleted file mode 100644 index fdbdb5f0c..000000000 --- a/tests/extensions/data/mccabe.py +++ /dev/null @@ -1,205 +0,0 @@ -"""Checks use of "too-complex" check""" - - -def f1(): - """McCabe rating: 1""" - pass - - -def f2(n): - """McCabe rating: 1""" - k = n + 4 - s = k + n - return s - - -def f3(n): - """McCabe rating: 3""" - if n > 3: - return "bigger than three" - elif n > 4: - return "is never executed" - else: - return "smaller than or equal to three" - - -def f4(): - """McCabe rating: 2""" - for i in range(10): - print(i) - - -def f5(mylist): - """McCabe rating: 2""" - for i in mylist: - print(i) - else: - print(None) - - -def f6(n): - """McCabe rating: 2""" - if n > 4: - return f(n - 1) - else: - return n - - -def f7(): - """McCabe rating: 3""" - def b(): - """McCabe rating: 2""" - def c(): - """McCabe rating: 1""" - pass - c() - b() - - -def f8(): - """McCabe rating: 4""" - try: - print(1) - except TypeA: - print(2) - except TypeB: - print(3) - else: - print(4) - - -def f9(): - """McCabe rating: 9""" - myint = 2 - if myint > 5: - pass - else: - if myint <= 5: - pass - else: - myint = 3 - if myint > 2: - if myint > 3: - pass - elif myint == 3: - pass - elif myint < 3: - pass - else: - if myint: - pass - else: - if myint: - pass - myint = 4 - - -def f10(): - """McCabe rating: 11""" - myint = 2 - if myint == 5: - return myint - elif myint == 6: - return myint - elif myint == 7: - return myint - elif myint == 8: - return myint - elif myint == 9: - return myint - elif myint == 10: - if myint == 8: - while True: - return True - elif myint == 8: - with myint: - return 8 - else: - if myint == 2: - return myint - return myint - return myint - - -class MyClass1(object): - """Class of example to test mccabe""" - _name = 'MyClass' # To force a tail.node=None - - def method1(): - """McCabe rating: 1""" - pass - - def method2(self, param1): - """McCabe rating: 18""" - if not param1: - pass - pass - if param1: - pass - else: - pass - - pass - - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - pass - if param1: - for value in range(5): - pass - - pass - for count in range(6): - with open('myfile') as fp: - count += 1 - pass - pass - try: - pass - if not param1: - pass - else: - pass - if param1: - raise BaseException('Error') - with open('myfile2') as fp2: - pass - pass - finally: - if param1 is not None: - pass - for count2 in range(8): - try: - pass - except BaseException('Error2'): - pass - return param1 - - -for count in range(10): - if count == 1: - exit(0) - elif count == 2: - exit(1) - else: - exit(2) - - -def method3(self): - try: - if True: - pass - else: - pass - finally: - pass - return True diff --git a/tests/extensions/data/overlapping_exceptions.py b/tests/extensions/data/overlapping_exceptions.py deleted file mode 100644 index 5ee50f314..000000000 --- a/tests/extensions/data/overlapping_exceptions.py +++ /dev/null @@ -1,45 +0,0 @@ -# pylint: disable=missing-docstring - -class SomeException(Exception): - pass - -class SubclassException(SomeException): - pass - -AliasException = SomeException - -try: - pass -except (SomeException, SomeException): # [overlapping-except] - pass - -try: - pass -except (SomeException, SubclassException): # [overlapping-except] - pass - -try: - pass -except (SomeException, AliasException): # [overlapping-except] - pass - -try: - pass -except (AliasException, SubclassException): # [overlapping-except] - pass - -try: - pass -# +1:[overlapping-except, overlapping-except, overlapping-except] -except (SomeException, AliasException, SubclassException): - pass - -try: - pass -except (ArithmeticError, FloatingPointError): # [overlapping-except] - pass - -try: - pass -except (ValueError, UnicodeDecodeError): # [overlapping-except] - pass diff --git a/tests/extensions/data/overlapping_exceptions_py33.py b/tests/extensions/data/overlapping_exceptions_py33.py deleted file mode 100644 index 16d5c30d1..000000000 --- a/tests/extensions/data/overlapping_exceptions_py33.py +++ /dev/null @@ -1,18 +0,0 @@ -# pylint: disable=missing-docstring - -import socket - -try: - pass -except (IOError, OSError): # [overlapping-except] - pass - -try: - pass -except (socket.error, OSError): # [overlapping-except] - pass - -try: - pass -except (ConnectionError, socket.error): # [overlapping-except] - pass diff --git a/tests/extensions/data/redefined.py b/tests/extensions/data/redefined.py deleted file mode 100644 index 8829c4383..000000000 --- a/tests/extensions/data/redefined.py +++ /dev/null @@ -1,85 +0,0 @@ -"""Checks variable types aren't redefined within a method or a function""" - -# pylint: disable=too-few-public-methods,missing-docstring,unused-variable,invalid-name, useless-object-inheritance - -_OK = True - -class MyClass(object): - - class Klass(object): - def __init__(self): - self.var2 = 'var' - - def __init__(self): - self.var = True - self.var1 = 2 - self.var2 = 1. - self.var1 = 2. # [redefined-variable-type] - self.a_str = "hello" - a_str = False - (a_str, b_str) = (1, 2) # no support for inference on tuple assignment - a_str = 2.0 if self.var else 1.0 - - def _getter(self): - return self.a_str - def _setter(self, val): - self.a_str = val - var2 = property(_getter, _setter) - - def some_method(self): - def func(): - var = 1 - test = 'bar' - var = 'baz' # [redefined-variable-type] - self.var = 1 # the rule checks for redefinitions in the scope of a function or method - test = 'foo' - myint = 2 - myint = False # [redefined-variable-type] - -_OK = "This is OK" # [redefined-variable-type] - -if _OK: - SOME_FLOAT = 1. - -def dummy_function(): - return 2 - -def other_function(): - instance = MyClass() - instance = True # [redefined-variable-type] - -SOME_FLOAT = dummy_function() # [redefined-variable-type] - -A_GLOB = None -A_GLOB = [1, 2, 3] - -def func2(x): - if x: - var = 'foo' - else: - var = True - - if x: - var2 = 'foo' - elif not x: - var2 = 2 - else: - pass - - if x: - var3 = 'foo' - var3 = 2 # [redefined-variable-type] - else: - pass - - var = 2 # [redefined-variable-type] - - if x: - pass - elif not x: - var4 = True - elif _OK: - pass - else: - var4 = 2. - var4 = 'baz' # [redefined-variable-type] diff --git a/tests/extensions/test_bad_builtin.py b/tests/extensions/test_bad_builtin.py deleted file mode 100644 index 4512873f0..000000000 --- a/tests/extensions/test_bad_builtin.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2016-2018, 2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com> -# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2020 Damien Baty <damien.baty@polyconseil.fr> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.bad_builtin -""" -from os import path as osp - -import pytest - -from pylint.extensions.bad_builtin import BadBuiltinChecker -from pylint.lint import fix_import_path -from pylint.lint.pylinter import PyLinter - -EXPECTED = [ - "Used builtin function 'map'. Using a list comprehension can be clearer.", - "Used builtin function 'filter'. Using a list comprehension can be clearer.", -] - - -@pytest.fixture(scope="module") -def checker(): - return BadBuiltinChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_types_redefined(linter: PyLinter) -> None: - elif_test = osp.join(osp.dirname(osp.abspath(__file__)), "data", "bad_builtin.py") - with fix_import_path([elif_test]): - linter.check([elif_test]) - msgs = sorted(linter.reporter.messages, key=lambda item: item.line) - assert len(msgs) == 2 - for msg, expected in zip(msgs, EXPECTED): - assert msg.symbol == "bad-builtin" - assert msg.msg == expected diff --git a/tests/extensions/test_broad_try_clause.py b/tests/extensions/test_broad_try_clause.py deleted file mode 100644 index 4e38adb23..000000000 --- a/tests/extensions/test_broad_try_clause.py +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright (c) 2019-2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2019-2020 Tyler Thieding <tyler@thieding.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2020 Damien Baty <damien.baty@polyconseil.fr> -# Copyright (c) 2020 Anthony Sottile <asottile@umich.edu> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.broad_try_clause`""" -import unittest -from os import path as osp -from typing import TYPE_CHECKING, Optional - -from pylint import checkers -from pylint.extensions.broad_try_clause import BroadTryClauseChecker -from pylint.lint import PyLinter -from pylint.reporters import BaseReporter - -if TYPE_CHECKING: - from pylint.reporters.ureports.nodes import Section - - -class BroadTryClauseTestReporter(BaseReporter): - def on_set_current_module(self, module: str, filepath: Optional[str]) -> None: - self.messages = [] - - def _display(self, layout: "Section") -> None: - pass - - -class BroadTryClauseTC(unittest.TestCase): - _linter = PyLinter() - - @classmethod - def setUpClass(cls): - cls._linter.set_reporter(BroadTryClauseTestReporter()) - checkers.initialize(cls._linter) - cls._linter.register_checker(BroadTryClauseChecker(cls._linter)) - cls._linter.disable("I") - - def test_broad_try_clause_message(self) -> None: - broad_try_clause_test = osp.join( - osp.dirname(osp.abspath(__file__)), "data", "broad_try_clause.py" - ) - self._linter.check([broad_try_clause_test]) - msgs = self._linter.reporter.messages - self.assertEqual(len(msgs), 4) - - self.assertEqual(msgs[0].symbol, "too-many-try-statements") - self.assertEqual( - msgs[0].msg, "try clause contains 3 statements, expected at most 1" - ) - self.assertEqual(msgs[0].line, 5) - - self.assertEqual(msgs[1].symbol, "too-many-try-statements") - self.assertEqual( - msgs[1].msg, "try clause contains 3 statements, expected at most 1" - ) - self.assertEqual(msgs[1].line, 12) - - self.assertEqual(msgs[2].symbol, "too-many-try-statements") - self.assertEqual( - msgs[2].msg, "try clause contains 4 statements, expected at most 1" - ) - self.assertEqual(msgs[2].line, 19) - - self.assertEqual(msgs[3].symbol, "too-many-try-statements") - self.assertEqual( - msgs[3].msg, "try clause contains 7 statements, expected at most 1" - ) - self.assertEqual(msgs[3].line, 29) diff --git a/tests/extensions/test_check_mccabe.py b/tests/extensions/test_check_mccabe.py deleted file mode 100644 index 14d2d37ad..000000000 --- a/tests/extensions/test_check_mccabe.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2016-2018, 2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com> -# Copyright (c) 2016 Moises Lopez <moylop260@vauxoo.com> -# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2020 Damien Baty <damien.baty@polyconseil.fr> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_mccabe""" -# pylint: disable=redefined-outer-name - -from os import path as osp -from typing import List - -import pytest - -from pylint.extensions import mccabe -from pylint.lint.pylinter import PyLinter - -EXPECTED_MSGS = [ - "'f1' is too complex. The McCabe rating is 1", - "'f2' is too complex. The McCabe rating is 1", - "'f3' is too complex. The McCabe rating is 3", - "'f4' is too complex. The McCabe rating is 2", - "'f5' is too complex. The McCabe rating is 2", - "'f6' is too complex. The McCabe rating is 2", - "'f7' is too complex. The McCabe rating is 3", - "'f8' is too complex. The McCabe rating is 4", - "'f9' is too complex. The McCabe rating is 9", - "'method1' is too complex. The McCabe rating is 1", - "This 'for' is too complex. The McCabe rating is 4", - "'method3' is too complex. The McCabe rating is 2", - "'f10' is too complex. The McCabe rating is 11", - "'method2' is too complex. The McCabe rating is 18", -] - - -@pytest.fixture(scope="module") -def enable(): - return ["too-complex"] - - -@pytest.fixture(scope="module") -def disable(): - return ["all"] - - -@pytest.fixture(scope="module") -def register(): - return mccabe.register - - -@pytest.fixture -def fname_mccabe_example() -> str: - return osp.join(osp.dirname(osp.abspath(__file__)), "data", "mccabe.py") - - -@pytest.mark.parametrize( - "complexity, expected", [(0, EXPECTED_MSGS), (9, EXPECTED_MSGS[-2:])] -) -def test_max_mccabe_rate( - linter: PyLinter, fname_mccabe_example: str, complexity: int, expected: List[str] -) -> None: - linter.global_set_option("max-complexity", complexity) - linter.check([fname_mccabe_example]) - real_msgs = [message.msg for message in linter.reporter.messages] - assert sorted(expected) == sorted(real_msgs) diff --git a/tests/extensions/test_comparetozero.py b/tests/extensions/test_comparetozero.py deleted file mode 100644 index 7b5bb1624..000000000 --- a/tests/extensions/test_comparetozero.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2016 Alexander Todorov <atodorov@otb.bg> -# Copyright (c) 2016 Łukasz Rogalski <rogalski.91@gmail.com> -# Copyright (c) 2017-2018, 2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2020 Anthony Sottile <asottile@umich.edu> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.emptystring""" - -import os -import unittest -from typing import TYPE_CHECKING, Optional - -from pylint import checkers -from pylint.extensions.comparetozero import CompareToZeroChecker -from pylint.lint import PyLinter -from pylint.reporters import BaseReporter - -if TYPE_CHECKING: - from pylint.reporters.ureports.nodes import Section - - -class CompareToZeroTestReporter(BaseReporter): - def on_set_current_module(self, module: str, filepath: Optional[str]) -> None: - self.messages = [] - - def _display(self, layout: "Section") -> None: - pass - - -class CompareToZeroUsedTC(unittest.TestCase): - _linter = PyLinter() - - @classmethod - def setUpClass(cls) -> None: - cls._linter.set_reporter(CompareToZeroTestReporter()) - checkers.initialize(cls._linter) - cls._linter.register_checker(CompareToZeroChecker(cls._linter)) - cls._linter.disable("I") - - def test_comparetozero_message(self) -> None: - elif_test = os.path.join( - os.path.dirname(os.path.abspath(__file__)), "data", "compare_to_zero.py" - ) - self._linter.check([elif_test]) - msgs = self._linter.reporter.messages - self.assertEqual(len(msgs), 4) - for msg in msgs: - self.assertEqual(msg.symbol, "compare-to-zero") - self.assertEqual(msg.msg, "Avoid comparisons to zero") - self.assertEqual(msgs[0].line, 6) - self.assertEqual(msgs[1].line, 9) - self.assertEqual(msgs[2].line, 12) - self.assertEqual(msgs[3].line, 15) diff --git a/tests/extensions/test_docstyle.py b/tests/extensions/test_docstyle.py deleted file mode 100644 index 7c1d019e7..000000000 --- a/tests/extensions/test_docstyle.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2016-2018, 2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com> -# Copyright (c) 2016 Luis Escobar <lescobar@vauxoo.com> -# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_docstring -""" - -from os.path import abspath, dirname, join - -import pytest - -from pylint.extensions.docstyle import DocStringStyleChecker -from pylint.lint.pylinter import PyLinter - -EXPECTED_MSGS = [ - "First line empty in function docstring", - "First line empty in class docstring", - "First line empty in method docstring", - "Bad docstring quotes in method, expected \"\"\", given '''", - 'Bad docstring quotes in method, expected """, given "', - 'Bad docstring quotes in method, expected """, given \'', - 'Bad docstring quotes in method, expected """, given \'', -] - -EXPECTED_SYMBOLS = [ - "docstring-first-line-empty", - "docstring-first-line-empty", - "docstring-first-line-empty", - "bad-docstring-quotes", - "bad-docstring-quotes", - "bad-docstring-quotes", - "bad-docstring-quotes", -] - - -@pytest.fixture(scope="module") -def checker(): - return DocStringStyleChecker - - -def test_docstring_message(linter: PyLinter) -> None: - docstring_test = join(dirname(abspath(__file__)), "data", "docstring.py") - linter.check([docstring_test]) - msgs = linter.reporter.messages - assert len(msgs) == 7 - for msg, expected_symbol, expected_msg in zip( - msgs, EXPECTED_SYMBOLS, EXPECTED_MSGS - ): - assert msg.symbol == expected_symbol - assert msg.msg == expected_msg diff --git a/tests/extensions/test_elseif_used.py b/tests/extensions/test_elseif_used.py deleted file mode 100644 index 994a5efcf..000000000 --- a/tests/extensions/test_elseif_used.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2015-2018, 2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2015 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr> -# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com> -# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2020 Damien Baty <damien.baty@polyconseil.fr> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_elif -""" -from os import path as osp - -import pytest - -from pylint.extensions.check_elif import ElseifUsedChecker -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return ElseifUsedChecker - - -def test_elseif_message(linter: PyLinter) -> None: - elif_test = osp.join(osp.dirname(osp.abspath(__file__)), "data", "elif.py") - linter.check([elif_test]) - msgs = linter.reporter.messages - assert len(msgs) == 2 - for msg in msgs: - assert msg.symbol == "else-if-used" - assert msg.msg == 'Consider using "elif" instead of "else if"' - assert msgs[0].line == 9 - assert msgs[1].line == 21 diff --git a/tests/extensions/test_empty_comment.py b/tests/extensions/test_empty_comment.py deleted file mode 100644 index 42d1b51f2..000000000 --- a/tests/extensions/test_empty_comment.py +++ /dev/null @@ -1,35 +0,0 @@ -from pathlib import Path - -import pytest - -from pylint.extensions import empty_comment -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return empty_comment.CommentChecker - - -@pytest.fixture(scope="module") -def enable(): - return ["empty-comment"] - - -@pytest.fixture(scope="module") -def disable(): - return ["all"] - - -def test_comment_base_case(linter: PyLinter) -> None: - comment_test = str(Path(__file__).parent.joinpath("data", "empty_comment.py")) - linter.check([comment_test]) - msgs = linter.reporter.messages - assert len(msgs) == 4 - for msg in msgs: - assert msg.symbol == "empty-comment" - assert msg.msg == "Line with empty comment" - assert msgs[0].line == 2 - assert msgs[1].line == 3 - assert msgs[2].line == 5 - assert msgs[3].line == 7 diff --git a/tests/extensions/test_emptystring.py b/tests/extensions/test_emptystring.py deleted file mode 100644 index f89f9202f..000000000 --- a/tests/extensions/test_emptystring.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2016 Łukasz Rogalski <rogalski.91@gmail.com> -# Copyright (c) 2016 Alexander Todorov <atodorov@otb.bg> -# Copyright (c) 2017-2018, 2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2017 Derek Gustafson <degustaf@gmail.com> -# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2020 Damien Baty <damien.baty@polyconseil.fr> -# Copyright (c) 2020 Anthony Sottile <asottile@umich.edu> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.emptystring -""" -from os import path as osp - -import pytest - -from pylint.extensions.emptystring import CompareToEmptyStringChecker -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return CompareToEmptyStringChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_emptystring_message(linter: PyLinter) -> None: - elif_test = osp.join( - osp.dirname(osp.abspath(__file__)), "data", "empty_string_comparison.py" - ) - linter.check([elif_test]) - msgs = linter.reporter.messages - expected_lineno = [6, 9, 12, 15] - assert len(msgs) == len(expected_lineno) - for msg, lineno in zip(msgs, expected_lineno): - assert msg.symbol == "compare-to-empty-string" - assert msg.msg == "Avoid comparisons to empty string" - assert msg.line == lineno diff --git a/tests/extensions/test_overlapping_exceptions.py b/tests/extensions/test_overlapping_exceptions.py deleted file mode 100644 index 005e0bcf9..000000000 --- a/tests/extensions/test_overlapping_exceptions.py +++ /dev/null @@ -1,88 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.overlapping_exceptions -""" - -from os.path import dirname, join - -import pytest - -from pylint.extensions.overlapping_exceptions import OverlappingExceptionsChecker -from pylint.lint.pylinter import PyLinter - - -@pytest.fixture(scope="module") -def checker(): - return OverlappingExceptionsChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_overlapping_exceptions(linter: PyLinter) -> None: - test = join(dirname(__file__), "data", "overlapping_exceptions.py") - linter.check([test]) - msgs = linter.reporter.messages - - expected = [ - (13, "Overlapping exceptions (SomeException and SomeException are the same)"), - ( - 18, - "Overlapping exceptions (SomeException is an ancestor class of SubclassException)", - ), - (23, "Overlapping exceptions (SomeException and AliasException are the same)"), - ( - 28, - "Overlapping exceptions (AliasException is an ancestor class of SubclassException)", - ), - (34, "Overlapping exceptions (SomeException and AliasException are the same)"), - ( - 34, - "Overlapping exceptions (SomeException is an ancestor class of SubclassException)", - ), - ( - 34, - "Overlapping exceptions (AliasException is an ancestor class of SubclassException)", - ), - ( - 39, - "Overlapping exceptions (ArithmeticError is an ancestor class of FloatingPointError)", - ), - ( - 44, - "Overlapping exceptions (ValueError is an ancestor class of UnicodeDecodeError)", - ), - ] - - assert len(msgs) == len(expected) - for msg, exp in zip(msgs, expected): - assert msg.msg_id == "W0714" - assert msg.symbol == "overlapping-except" - assert msg.category == "warning" - assert (msg.line, msg.msg) == exp - - -def test_overlapping_exceptions_py33(linter: PyLinter) -> None: - """From Python 3.3 both IOError and socket.error are aliases for OSError.""" - test = join(dirname(__file__), "data", "overlapping_exceptions_py33.py") - linter.check([test]) - msgs = linter.reporter.messages - - expected = [ - (7, "Overlapping exceptions (IOError and OSError are the same)"), - (12, "Overlapping exceptions (socket.error and OSError are the same)"), - ( - 17, - "Overlapping exceptions (socket.error is an ancestor class of ConnectionError)", - ), - ] - - assert len(msgs) == len(expected) - for msg, exp in zip(msgs, expected): - assert msg.msg_id == "W0714" - assert msg.symbol == "overlapping-except" - assert msg.category == "warning" - assert (msg.line, msg.msg) == exp diff --git a/tests/extensions/test_redefined.py b/tests/extensions/test_redefined.py deleted file mode 100644 index 1f945bf79..000000000 --- a/tests/extensions/test_redefined.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2016-2020 Claudiu Popa <pcmanticore@gmail.com> -# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com> -# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com> -# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk> -# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com> -# Copyright (c) 2020 Damien Baty <damien.baty@polyconseil.fr> -# Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> -# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com> - -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE - -"""Tests for the pylint checker in :mod:`pylint.extensions.check_elif""" -from os import path as osp - -import pytest - -from pylint.extensions.redefined_variable_type import MultipleTypesChecker -from pylint.lint import fix_import_path -from pylint.lint.pylinter import PyLinter - -EXPECTED = [ - "Redefinition of self.var1 type from int to float", - "Redefinition of a_str type from bool to float", - "Redefinition of var type from int to str", - "Redefinition of myint type from int to bool", - "Redefinition of _OK type from bool to str", - "Redefinition of instance type from redefined.MyClass to bool", - "Redefinition of SOME_FLOAT type from float to int", - "Redefinition of var3 type from str to int", - "Redefinition of var type from bool to int", - "Redefinition of var4 type from float to str", -] - - -@pytest.fixture(scope="module") -def checker(): - return MultipleTypesChecker - - -@pytest.fixture(scope="module") -def disable(): - return ["I"] - - -def test_types_redefined(linter: PyLinter) -> None: - elif_test = osp.join(osp.dirname(osp.abspath(__file__)), "data", "redefined.py") - with fix_import_path([elif_test]): - linter.check([elif_test]) - msgs = sorted(linter.reporter.messages, key=lambda item: item.line) - assert len(msgs) == 10 - for msg, expected in zip(msgs, EXPECTED): - assert msg.symbol == "redefined-variable-type" - assert msg.msg == expected |