diff options
author | Fergal Hainey <fergal.hainey@skyscanner.net> | 2018-03-04 20:52:13 +0000 |
---|---|---|
committer | Ashley Whetter <ashley@awhetter.co.uk> | 2019-02-09 13:27:33 -0800 |
commit | 362ee549ef4e473fcfe8d225523ea216cf0df859 (patch) | |
tree | 1596baf6cf1846759e90f3e2b340c097a049fca1 | |
parent | 451f9307e573f669beb5f04c52d9b917789f76af (diff) | |
download | pylint-git-362ee549ef4e473fcfe8d225523ea216cf0df859.tar.gz |
Add InvalidCheckerError
-rw-r--r-- | pylint/exceptions.py | 4 | ||||
-rw-r--r-- | pylint/lint.py | 6 | ||||
-rw-r--r-- | pylint/test/unittest_lint.py | 17 |
3 files changed, 23 insertions, 4 deletions
diff --git a/pylint/exceptions.py b/pylint/exceptions.py index 30640093f..6b217e0e2 100644 --- a/pylint/exceptions.py +++ b/pylint/exceptions.py @@ -25,5 +25,9 @@ class InvalidReporterError(Exception): """raised when selected reporter is invalid (e.g. not found)""" +class InvalidCheckerError(Exception): + """raised when registering an invalid checker (e.g. invalid priority)""" + + class ConfigurationError(Exception): """Raised when the configuration is invalid.""" diff --git a/pylint/lint.py b/pylint/lint.py index 7e5770375..c9a69e804 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -928,12 +928,12 @@ class PluginRegistry(utils.ReportsHandlerMixIn): :param checker: The checker to register. :type checker: BaseChecker - :raises ValueError: If the priority of the checker is invalid. + :raises InvalidCheckerError: If the priority of the checker is + invalid. """ if checker.priority > 0: - # TODO: Use a custom exception msg = "{}.priority must be <= 0".format(checker.__class__) - raise ValueError(msg) + raise exceptions.InvalidCheckerError(msg) self._checkers[checker.name].append(checker) diff --git a/pylint/test/unittest_lint.py b/pylint/test/unittest_lint.py index 072df1744..ab73d04bc 100644 --- a/pylint/test/unittest_lint.py +++ b/pylint/test/unittest_lint.py @@ -48,7 +48,11 @@ from pylint.utils import ( FileState, tokenize_module, ) -from pylint.exceptions import InvalidMessageError, UnknownMessageError +from pylint.exceptions import ( + InvalidCheckerError, + InvalidMessageError, + UnknownMessageError, +) import pylint.testutils as testutils from pylint.reporters import text from pylint import checkers @@ -252,6 +256,17 @@ def init_linter(linter): return linter +def test_register_checker_invalid_priority(): + class CustomChecker(checkers.BaseChecker): + priority = 10 + + linter = PyLinter() + plugin_registry = PluginRegistry(linter) + + with pytest.raises(exceptions.InvalidCheckerError): + plugin_registry.register_checker(CustomChecker(linter)) + + def test_pylint_visit_method_taken_in_account(linter): class CustomChecker(checkers.BaseChecker): __implements__ = interfaces.IAstroidChecker |