Failed Conditions
Pull Request — master (#2076)
by Abdeali
02:04
created

test_from_docstring()   B

Complexity

Conditions 1

Size

Total Lines 30

Duplication

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