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_check_mccabe.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) 2016-2017 Claudiu Popa <pcmanticore@gmail.com>
  2. # Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com>
  3. # Copyright (c) 2016 Moises Lopez <moylop260@vauxoo.com>
  4. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  5. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  6. """Tests for the pylint checker in :mod:`pylint.extensions.check_mccabe
  7. """
  8. import os.path as osp
  9. import pytest
  10. from pylint.extensions import mccabe
  11. EXPECTED_MSGS = [
  12. "'f1' is too complex. The McCabe rating is 1",
  13. "'f2' is too complex. The McCabe rating is 1",
  14. "'f3' is too complex. The McCabe rating is 3",
  15. "'f4' is too complex. The McCabe rating is 2",
  16. "'f5' is too complex. The McCabe rating is 2",
  17. "'f6' is too complex. The McCabe rating is 2",
  18. "'f7' is too complex. The McCabe rating is 3",
  19. "'f8' is too complex. The McCabe rating is 4",
  20. "'f9' is too complex. The McCabe rating is 9",
  21. "'method1' is too complex. The McCabe rating is 1",
  22. "This 'for' is too complex. The McCabe rating is 4",
  23. "'method3' is too complex. The McCabe rating is 2",
  24. "'f10' is too complex. The McCabe rating is 11",
  25. "'method2' is too complex. The McCabe rating is 18",
  26. ]
  27. @pytest.fixture(scope="module")
  28. def enable(enable):
  29. return ['too-complex']
  30. @pytest.fixture(scope="module")
  31. def disable(disable):
  32. return ['all']
  33. @pytest.fixture(scope="module")
  34. def register(register):
  35. return mccabe.register
  36. @pytest.fixture
  37. def fname_mccabe_example():
  38. return osp.join(osp.dirname(osp.abspath(__file__)), 'data', 'mccabe.py')
  39. @pytest.mark.parametrize("complexity, expected", [
  40. (0, EXPECTED_MSGS),
  41. (9, EXPECTED_MSGS[-2:]),
  42. ])
  43. def test_max_mccabe_rate(linter, fname_mccabe_example, complexity, expected):
  44. linter.global_set_option('max-complexity', complexity)
  45. linter.check([fname_mccabe_example])
  46. real_msgs = [message.msg for message in linter.reporter.messages]
  47. assert sorted(expected) == sorted(real_msgs)