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_overlapping_exceptions.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  3. """Tests for the pylint checker in :mod:`pylint.extensions.overlapping_exceptions
  4. """
  5. from sys import version_info
  6. from os.path import join, dirname
  7. from pylint.extensions.overlapping_exceptions import OverlappingExceptionsChecker
  8. import pytest
  9. @pytest.fixture(scope='module')
  10. def checker(checker):
  11. return OverlappingExceptionsChecker
  12. @pytest.fixture(scope='module')
  13. def disable(disable):
  14. return ['I']
  15. def test_overlapping_exceptions(linter):
  16. test = join(dirname(__file__), 'data', 'overlapping_exceptions.py')
  17. linter.check([test])
  18. msgs = linter.reporter.messages
  19. expected = [
  20. (13, 'Overlapping exceptions (SomeException and SomeException are the same)'),
  21. (18, 'Overlapping exceptions (SomeException is an ancestor class of SubclassException)'),
  22. (23, 'Overlapping exceptions (SomeException and AliasException are the same)'),
  23. (28, 'Overlapping exceptions (AliasException is an ancestor class of SubclassException)'),
  24. (34, 'Overlapping exceptions (SomeException and AliasException are the same)'),
  25. (34, 'Overlapping exceptions (SomeException is an ancestor class of SubclassException)'),
  26. (34, 'Overlapping exceptions (AliasException is an ancestor class of SubclassException)'),
  27. (39, 'Overlapping exceptions (ArithmeticError is an ancestor class of FloatingPointError)'),
  28. (44, 'Overlapping exceptions (ValueError is an ancestor class of UnicodeDecodeError)')
  29. ]
  30. assert len(msgs) == len(expected)
  31. for msg, exp in zip(msgs, expected):
  32. assert msg.msg_id == 'W0714'
  33. assert msg.symbol == 'overlapping-except'
  34. assert msg.category == 'warning'
  35. assert (msg.line, msg.msg) == exp
  36. @pytest.mark.skipif(version_info < (3, 3),
  37. reason="not relevant to Python version")
  38. def test_overlapping_exceptions_py33(linter):
  39. """From Python 3.3 both IOError and socket.error are aliases for OSError."""
  40. test = join(dirname(__file__), 'data', 'overlapping_exceptions_py33.py')
  41. linter.check([test])
  42. msgs = linter.reporter.messages
  43. expected = [
  44. (7, 'Overlapping exceptions (IOError and OSError are the same)'),
  45. (12, 'Overlapping exceptions (socket.error and OSError are the same)'),
  46. (17, 'Overlapping exceptions (socket.error is an ancestor class of ConnectionError)'),
  47. ]
  48. assert len(msgs) == len(expected)
  49. for msg, exp in zip(msgs, expected):
  50. assert msg.msg_id == 'W0714'
  51. assert msg.symbol == 'overlapping-except'
  52. assert msg.category == 'warning'
  53. assert (msg.line, msg.msg) == exp