DocstringMetadataTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
B test_from_docstring() 0 30 1
A check_from_docstring_dataset() 0 15 1
A test_str() 0 17 1
1
import unittest
2
3
from coalib.settings.DocstringMetadata import DocstringMetadata
4
5
6
class DocstringMetadataTest(unittest.TestCase):
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
27
        a multiline desc for p1
28
29
        :param p2: p2 description
30
31
        @return: retval description
32
        :return: retval description
33
        override
34
        """, desc="Main description", param_dict={
35
            "p1": "this is\na multiline desc for p1\n",
36
            "p2": "p2 description\n"
37
        }, retval_desc="retval description override")
38
39
    def test_str(self):
40
        uut = DocstringMetadata.from_docstring(
41
            '''
42
            Description of something. No params.
43
            ''')
44
45
        self.assertEqual(str(uut), "Description of something. No params.")
46
47
        uut = DocstringMetadata.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 {}
63
64
        self.assertIsInstance(docstring,
65
                              str,
66
                              "docstring needs to be a string for this test.")
67
        doc_comment = DocstringMetadata.from_docstring(docstring)
68
        self.assertEqual(doc_comment.desc, desc)
69
        self.assertEqual(doc_comment.param_dict, param_dict)
70
71
        self.assertEqual(doc_comment.retval_desc, retval_desc)
72