Completed
Pull Request — master (#1173)
by Lasse
04:14 queued 01:52
created

coalib.tests.settings.skip_test()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 8
rs 9.4286
1
import sys
2
import unittest
3
4
sys.path.insert(0, ".")
5
6
from coalib.settings.DocumentationComment import DocumentationComment
7
8
9
class DocumentationCommentParserTest(unittest.TestCase):
10
    def test_from_docstring(self):
11
        self.check_from_docstring_dataset("")
12
        self.check_from_docstring_dataset(" description only ",
13
                                          desc="description only")
14
        self.check_from_docstring_dataset(" :param test:  test description ",
15
                                          param_dict={
16
            "test": "test description"})
17
        self.check_from_docstring_dataset(" @param test:  test description ",
18
                                          param_dict={
19
            "test": "test description"})
20
        self.check_from_docstring_dataset(" :return: something ",
21
                                          retval_desc="something")
22
        self.check_from_docstring_dataset(" @return: something ",
23
                                          retval_desc="something")
24
        self.check_from_docstring_dataset("""
25
        Main description
26
27
        @param p1: this is
28
        a multiline desc for p1
29
30
        main description continues.
31
        :param p2: p2 description
32
33
        @return: retval description
34
        :return: retval description
35
        override
36
        """, desc="Main description main description continues.", param_dict={
37
            "p1": "this is a multiline desc for p1",
38
            "p2": "p2 description"
39
        }, retval_desc="retval description override")
40
41
    def test_str(self):
42
        uut = DocumentationComment.from_docstring(
43
            '''
44
            Description of something. No params.
45
            ''')
46
47
        self.assertEqual(str(uut), "Description of something. No params.")
48
49
        uut = DocumentationComment.from_docstring(
50
            '''
51
            Description of something with params.
52
53
            :param x: Imagine something.
54
            :param y: x^2
55
            ''')
56
57
        self.assertEqual(str(uut), "Description of something with params.")
58
59
    def check_from_docstring_dataset(self,
60
                                     docstring,
61
                                     desc="",
62
                                     param_dict=None,
63
                                     retval_desc=""):
64
        param_dict = param_dict or {}
65
66
        self.assertIsInstance(docstring,
67
                              str,
68
                              "docstring needs to be a string for this test.")
69
        doc_comment = DocumentationComment.from_docstring(docstring)
70
        self.assertEqual(doc_comment.desc, desc)
71
        self.assertEqual(doc_comment.param_dict, param_dict)
72
        self.assertEqual(doc_comment.retval_desc, retval_desc)
73
74
75
if __name__ == '__main__':
76
    unittest.main(verbosity=2)
77