From 5f0e8c305fd98be0d48078dc85c8e4a904aa8b78 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 27 Oct 2021 11:08:13 +0200 Subject: Create a new file for BaseChecker unit tests --- tests/checkers/unittest_base.py | 62 +----------------------------- tests/checkers/unittest_base_checker.py | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 61 deletions(-) create mode 100644 tests/checkers/unittest_base_checker.py (limited to 'tests/checkers') 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": "", - "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": "", + "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)) -- cgit v1.2.1