示例#1
0
    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()
        with testutils.catch_warnings():
            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_messages(Section())
        self.assertEqual(output.getvalue().splitlines(), expected)
示例#2
0
    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()
        with testutils.catch_warnings():
            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_messages(Section())
        self.assertEqual(output.getvalue().splitlines(), expected)
示例#3
0
    def test_html_reporter_deprecated(self):
        with testutils.catch_warnings() as caught:
            HTMLReporter()

        self.assertEqual(len(caught), 1)
        self.assertIsInstance(caught[0].message, DeprecationWarning)
        self.assertEqual(str(caught[0].message),
                         'This reporter will be removed in Pylint 2.0.')
示例#4
0
    def test_html_reporter_deprecated(self):
        with testutils.catch_warnings() as caught:
            HTMLReporter()

        self.assertEqual(len(caught), 1)
        self.assertIsInstance(caught[0].message, DeprecationWarning)
        self.assertEqual(str(caught[0].message),
                         'This reporter will be removed in Pylint 2.0.')
示例#5
0
    def test_html_reporter_missing_files(self):
        output = six.StringIO()
        with catch_warnings():
            self.linter.set_reporter(html.HTMLReporter(output))

        self.linter.set_option('output-format', 'html')
        self.linter.check('troppoptop.py')
        self.linter.generate_reports()
        value = output.getvalue()
        self.assertIn('troppoptop.py', value)
        self.assertIn('fatal', value)
示例#6
0
    def test_html_reporter_missing_files(self):
        output = six.StringIO()
        with catch_warnings():
            self.linter.set_reporter(html.HTMLReporter(output))

        self.linter.set_option('output-format', 'html')
        self.linter.check('troppoptop.py')
        self.linter.generate_reports()
        value = output.getvalue()
        self.assertIn('troppoptop.py', value)
        self.assertIn('fatal', value)
示例#7
0
    def test_all(self):
        """Make pylint check itself."""
        with testutils.catch_warnings():
            reporters = [
                TextReporter(six.StringIO()),
                HTMLReporter(six.StringIO()),
                ColorizedTextReporter(six.StringIO()),
                JSONReporter(six.StringIO())
            ]

        self._runtest(['pylint/test/functional/arguments.py'],
                      reporter=MultiReporter(reporters), code=1)
示例#8
0
    def test_all(self):
        """Make pylint check itself."""
        with testutils.catch_warnings():
            reporters = [
                TextReporter(six.StringIO()),
                HTMLReporter(six.StringIO()),
                ColorizedTextReporter(six.StringIO()),
                JSONReporter(six.StringIO())
            ]

        self._runtest(['pylint/test/functional/arguments.py'],
                      reporter=MultiReporter(reporters),
                      code=1)
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
    def test_parseable_output_regression(self):
        output = six.StringIO()
        with testutils.catch_warnings():
            linter = PyLinter(reporter=ParseableTextReporter())

        checkers.initialize(linter)
        linter.config.persistent = 0
        linter.reporter.set_output(output)
        linter.set_option('output-format', 'parseable')
        linter.open()
        linter.set_current_module('0123')
        linter.add_message('line-too-long', line=1, args=(1, 2))
        self.assertMultiLineEqual(
            output.getvalue(), '************* Module 0123\n'
            '0123:1: [C0301(line-too-long), ] '
            'Line too long (1/2)\n')
示例#12
0
    def test_parseable_output_regression(self):
        output = six.StringIO()
        with testutils.catch_warnings():
            linter = PyLinter(reporter=ParseableTextReporter())

        checkers.initialize(linter)
        linter.config.persistent = 0
        linter.reporter.set_output(output)
        linter.set_option('output-format', 'parseable')
        linter.open()
        linter.set_current_module('0123')
        linter.add_message('line-too-long', line=1, args=(1, 2))
        self.assertMultiLineEqual(output.getvalue(),
                                  '************* Module 0123\n'
                                  '0123:1: [C0301(line-too-long), ] '
                                  'Line too long (1/2)\n')
示例#13
0
    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>&#160;</td>
<td>1</td>
<td>0</td>
<td>Exactly one space required before comparison
a&lt; 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)
示例#14
0
    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>&#160;</td>
<td>1</td>
<td>0</td>
<td>Exactly one space required before comparison
a&lt; 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)
示例#15
0
 def test_html_crash_report(self):
     out = six.StringIO()
     module = join(HERE, 'regrtest_data', 'html_crash_420.py')
     with testutils.catch_warnings():
         self._runtest([module], code=16, reporter=HTMLReporter(out))
示例#16
0
    def test_parseable_output_deprecated(self):
        with testutils.catch_warnings() as cm:
            ParseableTextReporter()

        self.assertEqual(len(cm), 1)
        self.assertIsInstance(cm[0].message, DeprecationWarning)
示例#17
0
 def test_html_crash_report(self):
     out = six.StringIO()
     module = join(HERE, 'regrtest_data', 'html_crash_420.py')
     with testutils.catch_warnings():
         self._runtest([module], code=16, reporter=HTMLReporter(out))
示例#18
0
 def test_parseable_output_deprecated(self):
     with testutils.catch_warnings() as cm:
         ParseableTextReporter()
     
     self.assertEqual(len(cm), 1)
     self.assertIsInstance(cm[0].message, DeprecationWarning)