summaryrefslogtreecommitdiff
path: root/pylint/test
diff options
context:
space:
mode:
authorLuis Escobar <lescobar@vauxoo.com>2016-04-13 20:00:00 +0000
committerLuis Escobar <lescobar@vauxoo.com>2016-04-13 23:06:39 +0000
commit5a201d5ff23e0301603cfb5ffd64520ac011463b (patch)
treeea5d5f7382bcbd9c54702f6e62955b5a597b1274 /pylint/test
parent4b65c18495c1e8a9da99dce5c5541ebccdcc8264 (diff)
downloadpylint-git-5a201d5ff23e0301603cfb5ffd64520ac011463b.tar.gz
[IMP] Add New checks for PEP 0257 - Docstring Conventions - triple double quotes and handling-docstring-indentation
Diffstat (limited to 'pylint/test')
-rw-r--r--pylint/test/extensions/data/docstring.py43
-rw-r--r--pylint/test/extensions/test_docstring_add.py60
2 files changed, 103 insertions, 0 deletions
diff --git a/pylint/test/extensions/data/docstring.py b/pylint/test/extensions/data/docstring.py
new file mode 100644
index 000000000..563280f11
--- /dev/null
+++ b/pylint/test/extensions/data/docstring.py
@@ -0,0 +1,43 @@
+"""Checks of Dosctrings 'docstring-first-line-empty' 'bad-docstring-quotes'"""
+
+
+def check_messages(*messages):
+ """docstring"""
+ return messages
+
+
+class FFFF(object):
+ """
+ Test Docstring First Line Empty
+ """
+
+ def method1(self):
+ '''Test Triple Single Quotes docstring
+ '''
+ pass
+
+ def method2(self):
+ "bad docstring 1"
+ pass
+
+ def method3(self):
+ 'bad docstring 2'
+ pass
+
+ def method4(self):
+ ' """bad docstring 3 '
+ pass
+
+ @check_messages('bad-open-mode', 'redundant-unittest-assert',
+ 'deprecated-module')
+ def method5(self):
+ """Test OK 1 with decorators"""
+ pass
+
+ def method6(self):
+ r"""Test OK 2 with raw string"""
+ pass
+
+ def method7(self):
+ u"""Test OK 3 with unicode string"""
+ pass
diff --git a/pylint/test/extensions/test_docstring_add.py b/pylint/test/extensions/test_docstring_add.py
new file mode 100644
index 000000000..6fd844e42
--- /dev/null
+++ b/pylint/test/extensions/test_docstring_add.py
@@ -0,0 +1,60 @@
+"""Tests for the pylint checker in :mod:`pylint.extensions.check_docstring
+"""
+
+import os.path as osp
+import unittest
+
+from pylint import checkers
+from pylint.extensions.check_docstring import DocStringAddicChecker
+from pylint.lint import PyLinter
+from pylint.reporters import BaseReporter
+
+
+class TestReporter(BaseReporter):
+
+ def handle_message(self, msg):
+ self.messages.append(msg)
+
+ def on_set_current_module(self, module, filepath):
+ self.messages = []
+
+
+class CheckDocStringAddicTC(unittest.TestCase):
+
+ expected_msg = [
+ 'First line empty in class docstring',
+ 'Bad docstring quotes in method, expected """, given \'\'\'',
+ 'Bad docstring quotes in method, expected """, given "',
+ 'Bad docstring quotes in method, expected """, given \'',
+ 'Bad docstring quotes in method, expected """, given \'',
+ ]
+ expected_symbol = [
+ 'docstring-first-line-empty',
+ 'bad-docstring-quotes',
+ 'bad-docstring-quotes',
+ 'bad-docstring-quotes',
+ 'bad-docstring-quotes',
+ ]
+
+ @classmethod
+ def setUpClass(cls):
+ cls._linter = PyLinter()
+ cls._linter.set_reporter(TestReporter())
+ checkers.initialize(cls._linter)
+ cls._linter.register_checker(DocStringAddicChecker(cls._linter))
+
+ def test_docstring_message(self):
+ docstring_test = osp.join(osp.dirname(osp.abspath(__file__)), 'data',
+ 'docstring.py')
+ self._linter.check([docstring_test])
+ msgs = self._linter.reporter.messages
+ self.assertEqual(len(msgs), 5)
+ for msg, expected_symbol, expected_msg in zip(msgs,
+ self.expected_symbol,
+ self.expected_msg):
+ self.assertEqual(msg.symbol, expected_symbol)
+ self.assertEqual(msg.msg, expected_msg)
+
+
+if __name__ == '__main__':
+ unittest.main()