From fc8c4d81fd81b66c424480ce5aaa91bcf49809bb Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 10 Dec 2012 20:04:22 -0600 Subject: testsuite: test for exceptions raised without messages --- testsuite/ext/exception_messages.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 testsuite/ext/exception_messages.py (limited to 'testsuite/ext/exception_messages.py') diff --git a/testsuite/ext/exception_messages.py b/testsuite/ext/exception_messages.py new file mode 100644 index 000000000..877ba42a1 --- /dev/null +++ b/testsuite/ext/exception_messages.py @@ -0,0 +1,35 @@ +from logilab import astng +from pylint.interfaces import IASTNGChecker +from pylint.checkers import BaseChecker +from pylint.checkers.utils import safe_infer + + +class ExceptionMessageChecker(BaseChecker): + __implements__ = IASTNGChecker + + name = 'Exception Messages' + msgs = \ + {'R9901': ('Exception raised without arguments', + 'Used when an exception is raised without any arguments')} + options = ( + ('exceptions-without-args', + dict(default=('NotImplementedError',), + type='csv', + metavar='', + help='List of exception names that may be raised without arguments')),) + # this is important so that your checker is executed before others + priority = -1 + + def visit_raise(self, node): + if node.exc is None: + return + if isinstance(node.exc, astng.Name): + raised = safe_infer(node.exc) + if (isinstance(raised, astng.Class) and + raised.name not in self.config.exceptions_without_args): + self.add_message('R9901', node=node.exc) + + +def register(linter): + """required method to auto register this checker""" + linter.register_checker(ExceptionMessageChecker(linter)) -- cgit v1.2.3-1-g7c22