summaryrefslogtreecommitdiff
path: root/tests/extensions/test_check_docs_utils.py
diff options
context:
space:
mode:
authorAshley Whetter <ashley@awhetter.co.uk>2019-06-14 22:28:42 -0700
committerClaudiu Popa <pcmanticore@gmail.com>2019-06-20 10:02:14 +0200
commit33b8185a455c1686d038258697bb93005f2441c2 (patch)
tree4a50ccac775c009436e45803129e428ed694065f /tests/extensions/test_check_docs_utils.py
parent7081d91f30728653000bdfc59ea85a3395f96418 (diff)
downloadpylint-git-33b8185a455c1686d038258697bb93005f2441c2.tar.gz
Stopped installing tests with package
Diffstat (limited to 'tests/extensions/test_check_docs_utils.py')
-rw-r--r--tests/extensions/test_check_docs_utils.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/extensions/test_check_docs_utils.py b/tests/extensions/test_check_docs_utils.py
new file mode 100644
index 000000000..26af9db9d
--- /dev/null
+++ b/tests/extensions/test_check_docs_utils.py
@@ -0,0 +1,111 @@
+# Copyright (c) 2016-2017 Claudiu Popa <pcmanticore@gmail.com>
+# Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
+# Copyright (c) 2016 Ashley Whetter <ashley@awhetter.co.uk>
+# Copyright (c) 2018 Anthony Sottile <asottile@umich.edu>
+
+# 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
+
+"""Unit tests for the pylint checkers in :mod:`pylint.extensions.check_docs`,
+in particular the parameter documentation checker `DocstringChecker`
+"""
+from __future__ import absolute_import, division, print_function
+
+import astroid
+import pytest
+
+import pylint.extensions._check_docs_utils as utils
+
+
+@pytest.mark.parametrize("string,count", [
+ ('abc', 0),
+ ('', 0),
+ (' abc', 2),
+ ('\n abc', 0),
+ (' \n abc', 3),
+])
+def test_space_indentation(string, count):
+ """Test for pylint_plugin.ParamDocChecker"""
+ assert utils.space_indentation(string) == count
+
+
+@pytest.mark.parametrize("raise_node,expected", [
+ (astroid.extract_node('''
+ def my_func():
+ raise NotImplementedError #@
+ '''), {"NotImplementedError"}),
+
+ (astroid.extract_node('''
+ def my_func():
+ raise NotImplementedError("Not implemented!") #@
+ '''), {"NotImplementedError"}),
+
+ (astroid.extract_node('''
+ def my_func():
+ try:
+ fake_func()
+ except RuntimeError:
+ raise #@
+ '''), {"RuntimeError"}),
+
+ (astroid.extract_node('''
+ def my_func():
+ try:
+ fake_func()
+ except RuntimeError:
+ if another_func():
+ raise #@
+ '''), {"RuntimeError"}),
+
+ (astroid.extract_node('''
+ def my_func():
+ try:
+ fake_func()
+ except RuntimeError:
+ try:
+ another_func()
+ raise #@
+ except NameError:
+ pass
+ '''), {"RuntimeError"}),
+
+ (astroid.extract_node('''
+ def my_func():
+ try:
+ fake_func()
+ except RuntimeError:
+ try:
+ another_func()
+ except NameError:
+ raise #@
+ '''), {"NameError"}),
+
+ (astroid.extract_node('''
+ def my_func():
+ try:
+ fake_func()
+ except:
+ raise #@
+ '''), set()),
+
+ (astroid.extract_node('''
+ def my_func():
+ try:
+ fake_func()
+ except (RuntimeError, ValueError):
+ raise #@
+ '''), {"RuntimeError", "ValueError"}),
+
+ (astroid.extract_node('''
+ import not_a_module
+ def my_func():
+ try:
+ fake_func()
+ except not_a_module.Error:
+ raise #@
+ '''), set()),
+
+])
+def test_exception(raise_node, expected):
+ found = utils.possible_exc_types(raise_node)
+ assert found == expected