diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-10-27 11:08:13 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-10-27 11:56:34 +0200 |
commit | 5f0e8c305fd98be0d48078dc85c8e4a904aa8b78 (patch) | |
tree | 2e7eeb24a2ff9c5da1e71112a6156487f51670bc /tests/checkers | |
parent | ee85728805ca3bc9ab888b9224416aeb4861e0c3 (diff) | |
download | pylint-git-5f0e8c305fd98be0d48078dc85c8e4a904aa8b78.tar.gz |
Create a new file for BaseChecker unit tests
Diffstat (limited to 'tests/checkers')
-rw-r--r-- | tests/checkers/unittest_base.py | 62 | ||||
-rw-r--r-- | tests/checkers/unittest_base_checker.py | 68 |
2 files changed, 69 insertions, 61 deletions
diff --git a/tests/checkers/unittest_base.py b/tests/checkers/unittest_base.py index 616a0a8e7..9f0d5fd4f 100644 --- a/tests/checkers/unittest_base.py +++ b/tests/checkers/unittest_base.py @@ -34,7 +34,7 @@ from typing import Dict, Type import astroid -from pylint.checkers import BaseChecker, base +from pylint.checkers import base from pylint.testutils import CheckerTestCase, MessageTest, set_config @@ -683,66 +683,6 @@ class TestNamePresets(unittest.TestCase): self._test_should_always_pass(naming_style) -class TestBaseChecker(unittest.TestCase): - def test_doc(self) -> None: - class OtherBasicChecker(BaseChecker): - name = "basic" - msgs = { - "W0001": ( - "Basic checker has an example.", - "basic-checker-example", - "Used nowhere and serves no purpose.", - ) - } - - class LessBasicChecker(OtherBasicChecker): - options = ( - ( - "example-args", - { - "default": 42, - "type": "int", - "metavar": "<int>", - "help": "Example of integer argument for the checker.", - }, - ), - ) - - basic = OtherBasicChecker() - expected_beginning = """\ -Basic checker -~~~~~~~~~~~~~ - -Verbatim name of the checker is ``basic``. - -""" - expected_middle = """\ -Basic checker Options -^^^^^^^^^^^^^^^^^^^^^ -:example-args: - Example of integer argument for the checker. - - Default: ``42`` - -""" - expected_end = """\ -Basic checker Messages -^^^^^^^^^^^^^^^^^^^^^^ -:basic-checker-example (W0001): *Basic checker has an example.* - Used nowhere and serves no purpose. - - -""" - self.assertEqual(str(basic), expected_beginning + expected_end) - self.assertEqual(repr(basic), "Checker 'basic' (responsible for 'W0001')") - less_basic = LessBasicChecker() - - self.assertEqual( - str(less_basic), expected_beginning + expected_middle + expected_end - ) - self.assertEqual(repr(less_basic), repr(basic)) - - class TestNoSix(unittest.TestCase): @unittest.skip("too many dependencies need six :(") def test_no_six(self): diff --git a/tests/checkers/unittest_base_checker.py b/tests/checkers/unittest_base_checker.py new file mode 100644 index 000000000..b684d6f59 --- /dev/null +++ b/tests/checkers/unittest_base_checker.py @@ -0,0 +1,68 @@ +# 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 + +"""Unittest for the BaseChecker class.""" + +import unittest + +from pylint.checkers import BaseChecker + + +class TestBaseChecker(unittest.TestCase): + def test_doc(self) -> None: + class OtherBasicChecker(BaseChecker): + name = "basic" + msgs = { + "W0001": ( + "Basic checker has an example.", + "basic-checker-example", + "Used nowhere and serves no purpose.", + ) + } + + class LessBasicChecker(OtherBasicChecker): + options = ( + ( + "example-args", + { + "default": 42, + "type": "int", + "metavar": "<int>", + "help": "Example of integer argument for the checker.", + }, + ), + ) + + basic = OtherBasicChecker() + expected_beginning = """\ +Basic checker +~~~~~~~~~~~~~ + +Verbatim name of the checker is ``basic``. + +""" + expected_middle = """\ +Basic checker Options +^^^^^^^^^^^^^^^^^^^^^ +:example-args: + Example of integer argument for the checker. + + Default: ``42`` + +""" + expected_end = """\ +Basic checker Messages +^^^^^^^^^^^^^^^^^^^^^^ +:basic-checker-example (W0001): *Basic checker has an example.* + Used nowhere and serves no purpose. + + +""" + self.assertEqual(str(basic), expected_beginning + expected_end) + self.assertEqual(repr(basic), "Checker 'basic' (responsible for 'W0001')") + less_basic = LessBasicChecker() + + self.assertEqual( + str(less_basic), expected_beginning + expected_middle + expected_end + ) + self.assertEqual(repr(less_basic), repr(basic)) |