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_docs_utils.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Copyright (c) 2016-2017 Claudiu Popa <pcmanticore@gmail.com>
  2. # Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
  3. # Copyright (c) 2016 Ashley Whetter <ashley@awhetter.co.uk>
  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. """Unit tests for the pylint checkers in :mod:`pylint.extensions.check_docs`,
  7. in particular the parameter documentation checker `DocstringChecker`
  8. """
  9. from __future__ import division, print_function, absolute_import
  10. import pytest
  11. import astroid
  12. import pylint.extensions._check_docs_utils as utils
  13. @pytest.mark.parametrize("string,count", [
  14. ('abc', 0),
  15. ('', 0),
  16. (' abc', 2),
  17. ('\n abc', 0),
  18. (' \n abc', 3),
  19. ])
  20. def test_space_indentation(string, count):
  21. """Test for pylint_plugin.ParamDocChecker"""
  22. assert utils.space_indentation(string) == count
  23. @pytest.mark.parametrize("raise_node,expected", [
  24. (astroid.extract_node('''
  25. def my_func():
  26. raise NotImplementedError #@
  27. '''), set(["NotImplementedError"])),
  28. (astroid.extract_node('''
  29. def my_func():
  30. raise NotImplementedError("Not implemented!") #@
  31. '''), set(["NotImplementedError"])),
  32. (astroid.extract_node('''
  33. def my_func():
  34. try:
  35. fake_func()
  36. except RuntimeError:
  37. raise #@
  38. '''), set(["RuntimeError"])),
  39. (astroid.extract_node('''
  40. def my_func():
  41. try:
  42. fake_func()
  43. except RuntimeError:
  44. if another_func():
  45. raise #@
  46. '''), set(["RuntimeError"])),
  47. (astroid.extract_node('''
  48. def my_func():
  49. try:
  50. fake_func()
  51. except RuntimeError:
  52. try:
  53. another_func()
  54. raise #@
  55. except NameError:
  56. pass
  57. '''), set(["RuntimeError"])),
  58. (astroid.extract_node('''
  59. def my_func():
  60. try:
  61. fake_func()
  62. except RuntimeError:
  63. try:
  64. another_func()
  65. except NameError:
  66. raise #@
  67. '''), set(["NameError"])),
  68. (astroid.extract_node('''
  69. def my_func():
  70. try:
  71. fake_func()
  72. except:
  73. raise #@
  74. '''), set()),
  75. (astroid.extract_node('''
  76. def my_func():
  77. try:
  78. fake_func()
  79. except (RuntimeError, ValueError):
  80. raise #@
  81. '''), set(["RuntimeError", "ValueError"])),
  82. (astroid.extract_node('''
  83. import not_a_module
  84. def my_func():
  85. try:
  86. fake_func()
  87. except not_a_module.Error:
  88. raise #@
  89. '''), set()),
  90. ])
  91. def test_exception(raise_node, expected):
  92. found = utils.possible_exc_types(raise_node)
  93. assert found == expected