diff options
| author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-07-24 18:21:12 +0200 |
|---|---|---|
| committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-07-24 18:21:12 +0200 |
| commit | 109090dfa67f1a7a35db5002346795bb717bf7d0 (patch) | |
| tree | 9c0537f58ba447b8f3bd1004f3f17c6ceb338b71 /test | |
| parent | 640161196f431821182e4cfac5dd746a7ae464e4 (diff) | |
| download | pylint-109090dfa67f1a7a35db5002346795bb717bf7d0.tar.gz | |
extract a messages store from the MessagesHandlerMixIn class
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_func.py | 6 | ||||
| -rw-r--r-- | test/test_regr.py | 4 | ||||
| -rw-r--r-- | test/unittest_lint.py | 156 |
3 files changed, 88 insertions, 78 deletions
diff --git a/test/test_func.py b/test/test_func.py index 6a64ec2..2d573c2 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -1,4 +1,4 @@ -# Copyright (c) 2003-2008 LOGILAB S.A. (Paris, FRANCE). +# Copyright (c) 2003-2014 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under @@ -45,11 +45,11 @@ class LintTestNonExistentModuleTC(LintTestUsingModule): class TestTests(testlib.TestCase): """check that all testable messages have been checked""" PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310']) - + @testlib.tag('coverage') def test_exhaustivity(self): # skip fatal messages - not_tested = set(msg.msgid for msg in linter.messages + not_tested = set(msg.msgid for msg in linter.msgs_store.messages if msg.msgid[0] != 'F' and msg.may_be_emitted()) for msgid in test_reporter.message_ids: try: diff --git a/test/test_regr.py b/test/test_regr.py index 0349481..8bc50c2 100644 --- a/test/test_regr.py +++ b/test/test_regr.py @@ -1,4 +1,4 @@ -# Copyright (c) 2005 LOGILAB S.A. (Paris, FRANCE). +# Copyright (c) 2005-2014 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under @@ -60,7 +60,7 @@ class NonRegrTC(TestCase): got = linter.reporter.finalize().strip() checked = linter.stats['by_module'].keys() self.assertEqual(checked, ['package.__init__'], - '%s: %s' % (variation, checked)) + '%s: %s' % (variation, checked)) cwd = os.getcwd() os.chdir(join(REGR_DATA, 'package')) sys.path.insert(0, '') diff --git a/test/unittest_lint.py b/test/unittest_lint.py index a856d73..0e0ed9c 100644 --- a/test/unittest_lint.py +++ b/test/unittest_lint.py @@ -27,7 +27,8 @@ from pylint import config from pylint.lint import PyLinter, Run, UnknownMessage, preprocess_options, \ ArgumentPreprocessingError from pylint.utils import MSG_STATE_SCOPE_CONFIG, MSG_STATE_SCOPE_MODULE, \ - PyLintASTWalker, MessageDefinition, build_message_def, tokenize_module + MessagesStore, PyLintASTWalker, MessageDefinition, build_message_def, \ + tokenize_module from pylint.testutils import TestReporter from pylint.reporters import text from pylint import checkers @@ -60,51 +61,6 @@ class PyLinterTC(TestCase): checkers.initialize(self.linter) self.linter.set_reporter(TestReporter()) - def _compare_messages(self, desc, msg, checkerref=False): - # replace \r\n with \n, because - # logilab.common.textutils.normalize_text - # uses os.linesep, which will - # not properly compare with triple - # quoted multilines used in these tests - self.assertMultiLineEqual(desc, - msg.format_help(checkerref=checkerref) - .replace('\r\n', '\n')) - - def test_check_message_id(self): - self.assertIsInstance(self.linter.check_message_id('F0001'), - MessageDefinition) - self.assertRaises(UnknownMessage, - self.linter.check_message_id, 'YB12') - - def test_message_help(self): - msg = self.linter.check_message_id('F0001') - self._compare_messages( - ''':fatal (F0001): - Used when an error occurred preventing the analysis of a module (unable to - find it for instance). This message belongs to the master checker.''', - msg, checkerref=True) - self._compare_messages( - ''':fatal (F0001): - Used when an error occurred preventing the analysis of a module (unable to - find it for instance).''', - msg, checkerref=False) - - def test_message_help_minmax(self): - # build the message manually to be python version independant - msg = build_message_def(self.linter._checkers['typecheck'][0], - 'E1122', checkers.typecheck.MSGS['E1122']) - self._compare_messages( - ''':duplicate-keyword-arg (E1122): *Duplicate keyword argument %r in %s call* - Used when a function call passes the same keyword argument multiple times. - This message belongs to the typecheck checker. It can't be emitted when using - Python >= 2.6.''', - msg, checkerref=True) - self._compare_messages( - ''':duplicate-keyword-arg (E1122): *Duplicate keyword argument %r in %s call* - Used when a function call passes the same keyword argument multiple times. - This message can't be emitted when using Python >= 2.6.''', - msg, checkerref=False) - def test_enable_message(self): linter = self.linter linter.open() @@ -246,16 +202,6 @@ class PyLinterTC(TestCase): self.assertTrue(linter.is_message_enabled('W0102', 1)) self.assertTrue(linter.is_message_enabled('dangerous-default-value', 1)) - def test_list_messages(self): - sys.stdout = StringIO() - try: - self.linter.list_messages() - output = sys.stdout.getvalue() - finally: - sys.stdout = sys.__stdout__ - # cursory examination of the output: we're mostly testing it completes - self.assertIn(':empty-docstring (C0112): *Empty %s docstring*', output) - def test_lint_ext_module_with_file_output(self): self.linter.set_reporter(text.TextReporter()) if sys.version_info < (3, 0): @@ -363,23 +309,6 @@ class PyLinterTC(TestCase): ['C: 1: Line too long (1/2)', 'C: 2: Line too long (3/4)'], self.linter.reporter.messages) - def test_add_renamed_message(self): - self.linter.add_renamed_message('C9999', 'old-bad-name', 'invalid-name') - self.assertEqual('invalid-name', - self.linter.check_message_id('C9999').symbol) - self.assertEqual('invalid-name', - self.linter.check_message_id('old-bad-name').symbol) - - def test_renamed_message_register(self): - class Checker(object): - msgs = {'W1234': ('message', 'msg-symbol', 'msg-description', - {'old_names': [('W0001', 'old-symbol')]})} - self.linter.register_messages(Checker()) - self.assertEqual('msg-symbol', - self.linter.check_message_id('W0001').symbol) - self.assertEqual('msg-symbol', - self.linter.check_message_id('old-symbol').symbol) - def test_init_hooks_called_before_load_plugins(self): self.assertRaises(RuntimeError, Run, ['--load-plugins', 'unexistant', '--init-hook', 'raise RuntimeError']) @@ -541,5 +470,86 @@ class PreprocessOptionsTC(TestCase): {'bar' : (None, False)}) +class MessagesStoreTC(TestCase): + def setUp(self): + self.store = MessagesStore() + class Checker(object): + name = 'achecker' + msgs = { + 'W1234': ('message', 'msg-symbol', 'msg description.', + {'old_names': [('W0001', 'old-symbol')]}), + 'E1234': ('Duplicate keyword argument %r in %s call', + 'duplicate-keyword-arg', + 'Used when a function call passes the same keyword argument multiple times.', + {'maxversion': (2, 6)}), + } + self.store.register_messages(Checker()) + + def _compare_messages(self, desc, msg, checkerref=False): + # replace \r\n with \n, because + # logilab.common.textutils.normalize_text + # uses os.linesep, which will + # not properly compare with triple + # quoted multilines used in these tests + self.assertMultiLineEqual( + desc, + msg.format_help(checkerref=checkerref).replace('\r\n', '\n')) + + def test_check_message_id(self): + self.assertIsInstance(self.store.check_message_id('W1234'), + MessageDefinition) + self.assertRaises(UnknownMessage, + self.store.check_message_id, 'YB12') + + def test_message_help(self): + msg = self.store.check_message_id('W1234') + self._compare_messages( + ''':msg-symbol (W1234): *message* + msg description. This message belongs to the achecker checker.''', + msg, checkerref=True) + self._compare_messages( + ''':msg-symbol (W1234): *message* + msg description.''', + msg, checkerref=False) + + def test_message_help_minmax(self): + # build the message manually to be python version independant + msg = self.store.check_message_id('E1234') + self._compare_messages( + ''':duplicate-keyword-arg (E1234): *Duplicate keyword argument %r in %s call* + Used when a function call passes the same keyword argument multiple times. + This message belongs to the achecker checker. It can't be emitted when using + Python >= 2.6.''', + msg, checkerref=True) + self._compare_messages( + ''':duplicate-keyword-arg (E1234): *Duplicate keyword argument %r in %s call* + Used when a function call passes the same keyword argument multiple times. + This message can't be emitted when using Python >= 2.6.''', + msg, checkerref=False) + + def test_list_messages(self): + sys.stdout = StringIO() + try: + self.store.list_messages() + output = sys.stdout.getvalue() + finally: + sys.stdout = sys.__stdout__ + # cursory examination of the output: we're mostly testing it completes + self.assertIn(':msg-symbol (W1234): *message*', output) + + def test_add_renamed_message(self): + self.store.add_renamed_message('W1234', 'old-bad-name', 'msg-symbol') + self.assertEqual('msg-symbol', + self.store.check_message_id('W1234').symbol) + self.assertEqual('msg-symbol', + self.store.check_message_id('old-bad-name').symbol) + + def test_renamed_message_register(self): + self.assertEqual('msg-symbol', + self.store.check_message_id('W0001').symbol) + self.assertEqual('msg-symbol', + self.store.check_message_id('old-symbol').symbol) + + if __name__ == '__main__': unittest_main() |
