2016-07-22 21:22:28 +00:00
|
|
|
# Copyright (c) 2013-2014 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2014-2017 Claudiu Popa <pcmanticore@gmail.com>
|
2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2014 Calin Don <calin.don@gmail.com>
|
|
|
|
# Copyright (c) 2014 Google, Inc.
|
|
|
|
# Copyright (c) 2014 Arun Persaud <arun@nubati.net>
|
|
|
|
# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
|
|
|
|
# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2018 Sushobhit <31987769+sushobhit27@users.noreply.github.com>
|
2016-07-22 21:22:28 +00:00
|
|
|
|
2016-06-01 15:11:29 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
|
|
|
|
|
2015-01-03 08:25:03 +00:00
|
|
|
import warnings
|
2013-07-30 16:02:48 +00:00
|
|
|
|
2018-05-27 05:12:14 +00:00
|
|
|
from io import StringIO
|
2015-05-07 20:30:02 +00:00
|
|
|
|
2013-09-25 06:13:10 +00:00
|
|
|
from pylint.lint import PyLinter
|
2013-07-30 16:02:48 +00:00
|
|
|
from pylint import checkers
|
2014-10-16 11:26:20 +00:00
|
|
|
from pylint.reporters.text import TextReporter, ParseableTextReporter
|
2016-12-02 17:09:18 +00:00
|
|
|
import pytest
|
2015-09-05 12:24:35 +00:00
|
|
|
|
2013-07-30 16:02:48 +00:00
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2017-01-03 07:05:38 +00:00
|
|
|
def reporter(reporter):
|
|
|
|
return TextReporter
|
|
|
|
|
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2017-01-03 07:05:38 +00:00
|
|
|
def disable(disable):
|
2018-09-16 15:33:50 +00:00
|
|
|
return ["I"]
|
2016-12-08 04:15:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_template_option(linter):
|
2018-05-27 05:12:14 +00:00
|
|
|
output = StringIO()
|
2016-12-08 04:15:21 +00:00
|
|
|
linter.reporter.set_output(output)
|
2018-09-16 15:33:50 +00:00
|
|
|
linter.set_option("msg-template", "{msg_id}:{line:03d}")
|
2016-12-08 04:15:21 +00:00
|
|
|
linter.open()
|
2018-09-16 15:33:50 +00:00
|
|
|
linter.set_current_module("0123")
|
|
|
|
linter.add_message("C0301", line=1, args=(1, 2))
|
|
|
|
linter.add_message("line-too-long", line=2, args=(3, 4))
|
|
|
|
assert (
|
|
|
|
output.getvalue() == "************* Module 0123\n" "C0301:001\n" "C0301:002\n"
|
|
|
|
)
|
2016-12-08 04:15:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parseable_output_deprecated():
|
|
|
|
with warnings.catch_warnings(record=True) as cm:
|
|
|
|
warnings.simplefilter("always")
|
|
|
|
ParseableTextReporter()
|
|
|
|
|
|
|
|
assert len(cm) == 1
|
|
|
|
assert isinstance(cm[0].message, DeprecationWarning)
|
|
|
|
|
|
|
|
|
|
|
|
def test_parseable_output_regression():
|
2018-05-27 05:12:14 +00:00
|
|
|
output = StringIO()
|
2016-12-08 04:15:21 +00:00
|
|
|
with warnings.catch_warnings(record=True):
|
|
|
|
linter = PyLinter(reporter=ParseableTextReporter())
|
|
|
|
|
|
|
|
checkers.initialize(linter)
|
|
|
|
linter.config.persistent = 0
|
|
|
|
linter.reporter.set_output(output)
|
2018-09-16 15:33:50 +00:00
|
|
|
linter.set_option("output-format", "parseable")
|
2016-12-08 04:15:21 +00:00
|
|
|
linter.open()
|
2018-09-16 15:33:50 +00:00
|
|
|
linter.set_current_module("0123")
|
|
|
|
linter.add_message("line-too-long", line=1, args=(1, 2))
|
|
|
|
assert (
|
|
|
|
output.getvalue() == "************* Module 0123\n"
|
|
|
|
"0123:1: [C0301(line-too-long), ] "
|
|
|
|
"Line too long (1/2)\n"
|
|
|
|
)
|
2016-12-08 04:15:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_display_results_is_renamed():
|
|
|
|
class CustomReporter(TextReporter):
|
|
|
|
def _display(self, layout):
|
|
|
|
return None
|
|
|
|
|
|
|
|
reporter = CustomReporter()
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
reporter.display_results
|