Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_redefined.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) 2016-2017 Claudiu Popa <pcmanticore@gmail.com>
  2. # Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com>
  3. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  4. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  5. """Tests for the pylint checker in :mod:`pylint.extensions.check_elif
  6. """
  7. import os.path as osp
  8. import pytest
  9. from pylint.extensions.redefined_variable_type import MultipleTypesChecker
  10. from pylint.lint import fix_import_path
  11. EXPECTED = [
  12. 'Redefinition of self.var1 type from int to float',
  13. 'Redefinition of var type from int to str',
  14. 'Redefinition of myint type from int to bool',
  15. 'Redefinition of _OK type from bool to str',
  16. 'Redefinition of instance type from redefined.MyClass to bool',
  17. 'Redefinition of SOME_FLOAT type from float to int',
  18. 'Redefinition of var3 type from str to int',
  19. 'Redefinition of var type from bool to int',
  20. 'Redefinition of var4 type from float to str',
  21. ]
  22. @pytest.fixture(scope="module")
  23. def checker(checker):
  24. return MultipleTypesChecker
  25. @pytest.fixture(scope="module")
  26. def disable(disable):
  27. return ['I']
  28. def test_types_redefined(linter):
  29. elif_test = osp.join(osp.dirname(osp.abspath(__file__)), 'data',
  30. 'redefined.py')
  31. with fix_import_path([elif_test]):
  32. linter.check([elif_test])
  33. msgs = sorted(linter.reporter.messages, key=lambda item: item.line)
  34. assert len(msgs) == 9
  35. for msg, expected in zip(msgs, EXPECTED):
  36. assert msg.symbol == 'redefined-variable-type'
  37. assert msg.msg == expected