diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-11-25 18:13:19 +0100 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-11-25 18:13:19 +0100 |
commit | f165a6675322f60d39e6c5e2902c478311232318 (patch) | |
tree | b31141421204cce4c28f2e2f7527ae2d04e880e9 | |
parent | 55729538e7def0d3ffae08b4a3fedcae68fbc7a1 (diff) | |
parent | 8d2aa9527d094e80bb97dff57c7940e498a3e6dd (diff) | |
download | pylint-git-f165a6675322f60d39e6c5e2902c478311232318.tar.gz |
merge
-rw-r--r-- | checkers/typecheck.py | 4 | ||||
-rw-r--r-- | checkers/utils.py | 8 | ||||
-rw-r--r-- | lint.py | 15 | ||||
-rw-r--r-- | test/test_func.py | 25 | ||||
-rw-r--r-- | utils.py | 28 |
5 files changed, 64 insertions, 16 deletions
diff --git a/checkers/typecheck.py b/checkers/typecheck.py index ab0484323..49e595d7a 100644 --- a/checkers/typecheck.py +++ b/checkers/typecheck.py @@ -25,7 +25,7 @@ from logilab.astng.infutils import YES, Instance from pylint.interfaces import IASTNGChecker from pylint.checkers import BaseChecker -from pylint.checkers.utils import safe_infer, is_super, display_type +from pylint.checkers.utils import safe_infer, is_super MSGS = { 'E1101': ('%s %r has no %r member', @@ -187,7 +187,7 @@ accessed.'} else: msgid = 'E1101' self.add_message(msgid, node=node, - args=(display_type(owner), name, + args=(owner.display_type(), name, node.attrname)) diff --git a/checkers/utils.py b/checkers/utils.py index ba371a53f..508fb0604 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -182,14 +182,6 @@ def overrides_a_method(class_node, name): return True return False -def display_type(node): - """return the type of this node for screen display""" - if isinstance(node, astng.Instance): - return 'Instance of' - elif isinstance(node, astng.Module): - return 'Module' - return 'Class' - PYMETHODS = set(('__new__', '__init__', '__del__', '__hash__', '__str__', '__repr__', '__len__', '__iter__', @@ -787,6 +787,12 @@ exit. The value may be a comma separated list of message ids.'''}), {'action' : 'callback', 'metavar': '<msg-id>', 'callback' : self.cb_list_messages, 'group': 'Commands', + 'help' : "Generate pylint's messages."}), + + ('full-documentation', + {'action' : 'callback', 'metavar': '<msg-id>', + 'callback' : self.cb_full_documentation, + 'group': 'Commands', 'help' : "Generate pylint's full documentation."}), ('generate-rcfile', @@ -922,9 +928,14 @@ been issued by analysing pylint output status code self.linter.help_message(splitstrip(value)) sys.exit(0) - def cb_list_messages(self, option, opt_name, value, parser): + def cb_full_documentation(self, option, opt_name, value, parser): + """optik callback for printing full documentation""" + self.linter.print_full_documentation() + sys.exit(0) + + def cb_list_messages(self, option, opt_name, value, parser): # FIXME """optik callback for printing available messages""" - self.linter.list_messages() + self.linter.list_sorted_messages() sys.exit(0) def cb_init_hook(option, opt_name, value, parser): diff --git a/test/test_func.py b/test/test_func.py index e614d5c92..1d0494d62 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -57,10 +57,29 @@ def exception_str(ex): return 'in %s\n:: %s' % (ex.file, ', '.join(ex.args)) class LintTestUsingModule(testlib.TestCase): - package = 'input' + DEFAULT_PACKAGE = 'input' + package = DEFAULT_PACKAGE linter = linter + module = None + depends = None + + _TEST_TYPE = 'module' + + def shortDescription(self): + values = { 'mode' : self._TEST_TYPE, + 'input': self.module, + 'pkg': self.package, + 'cls': self.__class__.__name__} + + if self.package == self.DEFAULT_PACKAGE: + msg = '%(mode)s test of input file "%(input)s" (%(cls)s)' + else: + msg = '%(mode)s test of input file "%(input)s" in "%(pkg)s" (%(cls)s)' + return msg % values + def setUp(self): MANAGER.set_cache_size(200) # reset cache + def test_functionality(self): tocheck = [self.package+'.'+self.module] if self.depends: @@ -98,6 +117,8 @@ class LintTestUsingModule(testlib.TestCase): class LintTestUsingFile(LintTestUsingModule): + _TEST_TYPE = 'file' + def test_functionality(self): tocheck = [self.package+'/' + self.module + '.py'] if self.depends: @@ -168,6 +189,7 @@ def make_tests(filter_rgx): module = module_file.replace('.py', '') output = messages_file depends = dependencies or None + tags = testlib.Tags(('generated',)) tests.append(LintTestUsingModuleTC) if MODULES_ONLY: @@ -177,6 +199,7 @@ def make_tests(filter_rgx): module = module_file.replace('.py', '') output = exists(messages_file + '2') and (messages_file + '2') or messages_file depends = dependencies or None + tags = testlib.Tags(('generated',)) tests.append(LintTestUsingFileTC) ## # special test for f0003 @@ -279,7 +279,12 @@ class MessagesHandlerMixIn: print continue - def list_messages(self): + def list_checkers_messages(self, checker): + """print checker's messages in reST format""" + for msg_id in sort_msgs(checker.msgs.keys()): + print self.get_message_help(msg_id, False) + + def print_full_documentation(self): """output a full documentation in ReST format""" for checker in sort_checkers(self._checkers.values()): if checker.name == 'master': @@ -313,8 +318,7 @@ class MessagesHandlerMixIn: title = ('%smessages' % prefix).capitalize() print title print '~' * len(title) - for msg_id in sort_msgs(checker.msgs.keys()): - print self.get_message_help(msg_id, False) + self.list_checkers_messages( checker) print if getattr(checker, 'reports', None): title = ('%sreports' % prefix).capitalize() @@ -325,6 +329,24 @@ class MessagesHandlerMixIn: print print + def list_messages(self): + """output full messages list documentation in ReST format""" + for checker in sort_checkers(self._checkers.values()): + if checker.msgs: + self.list_checkers_messages( checker) + print + + def list_sorted_messages(self): + """output full sorted messages list in ReST format""" + msg_ids = [] + for checker in self._checkers.values(): + for msg_id in checker.msgs.keys(): + msg_ids.append(msg_id) + msg_ids.sort() + for msg_id in msg_ids: + print self.get_message_help(msg_id, False) + print + class ReportsHandlerMixIn: """a mix-in class containing all the reports and stats manipulation |