2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2016-2017 Claudiu Popa <pcmanticore@gmail.com>
|
2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.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
|
|
|
|
|
2016-02-16 17:48:14 +00:00
|
|
|
"""Tests for the pylint checker in :mod:`pylint.extensions.check_elif
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os.path as osp
|
|
|
|
|
2016-12-08 04:15:21 +00:00
|
|
|
import pytest
|
|
|
|
|
2016-07-07 13:51:42 +00:00
|
|
|
from pylint.extensions.redefined_variable_type import MultipleTypesChecker
|
2017-01-03 07:05:38 +00:00
|
|
|
from pylint.lint import fix_import_path
|
2016-02-16 17:48:14 +00:00
|
|
|
|
2016-12-08 04:15:21 +00:00
|
|
|
EXPECTED = [
|
2019-06-01 09:30:42 +00:00
|
|
|
"Redefinition of self.var1 type from int to float",
|
|
|
|
"Redefinition of a_str type from bool to float",
|
|
|
|
"Redefinition of var type from int to str",
|
|
|
|
"Redefinition of myint type from int to bool",
|
|
|
|
"Redefinition of _OK type from bool to str",
|
|
|
|
"Redefinition of instance type from redefined.MyClass to bool",
|
|
|
|
"Redefinition of SOME_FLOAT type from float to int",
|
|
|
|
"Redefinition of var3 type from str to int",
|
|
|
|
"Redefinition of var type from bool to int",
|
|
|
|
"Redefinition of var4 type from float to str",
|
2016-12-08 04:15:21 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2017-01-03 07:05:38 +00:00
|
|
|
def checker(checker):
|
|
|
|
return MultipleTypesChecker
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def disable(disable):
|
2019-06-01 09:30:42 +00:00
|
|
|
return ["I"]
|
2016-12-08 04:15:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_types_redefined(linter):
|
2019-06-01 09:30:42 +00:00
|
|
|
elif_test = osp.join(osp.dirname(osp.abspath(__file__)), "data", "redefined.py")
|
2016-12-08 04:15:21 +00:00
|
|
|
with fix_import_path([elif_test]):
|
|
|
|
linter.check([elif_test])
|
|
|
|
msgs = sorted(linter.reporter.messages, key=lambda item: item.line)
|
2019-06-01 09:30:42 +00:00
|
|
|
assert len(msgs) == 10
|
2016-12-08 04:15:21 +00:00
|
|
|
for msg, expected in zip(msgs, EXPECTED):
|
2019-06-01 09:30:42 +00:00
|
|
|
assert msg.symbol == "redefined-variable-type"
|
2016-12-08 04:15:21 +00:00
|
|
|
assert msg.msg == expected
|