def make_reports(self, stats, old_stats): """render registered reports""" sect = Section('Report', '%s statements analysed.' % (self.stats['statement'])) for checker in self.report_order(): for reportid, r_title, r_cb in self._reports[checker]: if not self.report_is_enabled(reportid): continue report_sect = Section(r_title) try: r_cb(report_sect, stats, old_stats) except EmptyReport: continue report_sect.report_id = reportid sect.append(report_sect) return sect
def set_output(self, output=None): """set output stream messages buffered for old output is processed first""" if self.out and self.msgs: self._display(Section()) BaseReporter.set_output(self, output)
def test_html_reporter_msg_template(self): expected = ''' <html> <body> <div> <div> <h2>Messages</h2> <table> <tr class="header"> <th>category</th> <th>msg_id</th> </tr> <tr class="even"> <td>warning</td> <td>W0332</td> </tr> </table> </div> </div> </body> </html>'''.strip().splitlines() output = six.StringIO() linter = PyLinter(reporter=HTMLReporter()) checkers.initialize(linter) linter.config.persistent = 0 linter.reporter.set_output(output) linter.set_option('msg-template', '{category}{msg_id}') linter.open() linter.set_current_module('0123') linter.add_message('lowercase-l-suffix', line=1) linter.reporter.display_results(Section()) self.assertEqual(output.getvalue().splitlines(), expected)
def display_messages(self, layout): if self.msgs: # add stored messages to the layout msgs = self.header cols = len(self.header) msgs += self.msgs sect = Section('Messages') layout.append(sect) sect.append(Table(cols=cols, children=msgs, rheaders=1)) self.msgs = [] self._display(layout)
def make_reports( # type: ignore[misc] # ReportsHandlerMixIn is always mixed with PyLinter self: "PyLinter", stats: LinterStats, old_stats: Optional[LinterStats], ) -> Section: """render registered reports""" sect = Section("Report", f"{self.stats.statement} statements analysed.") for checker in self.report_order(): for reportid, r_title, r_cb in self._reports[checker]: if not self.report_is_enabled(reportid): continue report_sect = Section(r_title) try: r_cb(report_sect, stats, old_stats) except EmptyReportError: continue report_sect.report_id = reportid sect.append(report_sect) return sect
def test_display_results_is_renamed(self): class CustomReporter(TextReporter): def _display(self, layout): return None reporter = CustomReporter() if __pkginfo__.numversion >= (2, 0): with self.assertRaises(AttributeError): reporter.display_results else: with testutils.catch_warnings() as cm: reporter.display_results(Section()) self.assertEqual(len(cm), 1) self.assertIsInstance(cm[0].message, DeprecationWarning)
def test_html_reporter_type(self): # Integration test for issue #263 # https://bitbucket.org/logilab/pylint/issue/263/html-report-type-problems expected = '''<html> <body> <div> <div> <h2>Messages</h2> <table> <tr class="header"> <th>type</th> <th>module</th> <th>object</th> <th>line</th> <th>col_offset</th> <th>message</th> </tr> <tr class="even"> <td>convention</td> <td>0123</td> <td> </td> <td>1</td> <td>0</td> <td>Exactly one space required before comparison a< 5: print "zero"</td> </tr> </table> </div> </div> </body> </html> ''' output = six.StringIO() with testutils.catch_warnings(): linter = PyLinter(reporter=HTMLReporter()) checkers.initialize(linter) linter.config.persistent = 0 linter.reporter.set_output(output) linter.open() linter.set_current_module('0123') linter.add_message('bad-whitespace', line=1, args=('Exactly one', 'required', 'before', 'comparison', 'a< 5: print "zero"')) linter.reporter.display_reports(Section()) self.assertMultiLineEqual(output.getvalue(), expected)
def _display(self, layout): """launch layouts display overridden from BaseReporter to add insert the messages section (in add_message, message is not displayed, just collected so it can be displayed in an html table) """ if self.msgs: # add stored messages to the layout msgs = self.header cols = len(self.header) msgs += self.msgs sect = Section('Messages') layout.append(sect) sect.append(Table(cols=cols, children=msgs, rheaders=1)) self.msgs = [] HTMLWriter().format(layout, self.out)