Failed Conditions
Pull Request — master (#1173)
by Lasse
01:47
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
import subprocess
0 ignored issues
show
Unused Code introduced by
The import subprocess seems to be unused.
Loading history...
4
5
sys.path.insert(0, ".")
6
7
from coalib.settings.DocumentationComment import DocumentationComment
8
9
10
class DocumentationCommentParserTest(unittest.TestCase):
11
    def test_from_docstring(self):
12
        self.check_from_docstring_dataset("")
13
        self.check_from_docstring_dataset(" description only ",
14
                                          desc="description only")
15
        self.check_from_docstring_dataset(" :param test:  test description ",
16
                                          param_dict={
17
            "test": "test description"})
18
        self.check_from_docstring_dataset(" @param test:  test description ",
19
                                          param_dict={
20
            "test": "test description"})
21
        self.check_from_docstring_dataset(" :return: something ",
22
                                          retval_desc="something")
23
        self.check_from_docstring_dataset(" @return: something ",
24
                                          retval_desc="something")
25
        self.check_from_docstring_dataset("""
26
        Main description
27
28
        @param p1: this is
29
        a multiline desc for p1
30
31
        main description continues.
32
        :param p2: p2 description
33
34
        @return: retval description
35
        :return: retval description
36
        override
37
        """, desc="Main description main description continues.", param_dict={
38
            "p1": "this is a multiline desc for p1",
39
            "p2": "p2 description"
40
        }, retval_desc="retval description override")
41
42
    def test_str(self):
43
        uut = DocumentationComment.from_docstring(
44
            '''
45
            Description of something. No params.
46
            ''')
47
48
        self.assertEqual(str(uut), "Description of something. No params.")
49
50
        uut = DocumentationComment.from_docstring(
51
            '''
52
            Description of something with params.
53
54
            :param x: Imagine something.
55
            :param y: x^2
56
            ''')
57
58
        self.assertEqual(str(uut), "Description of something with params.")
59
60
    def check_from_docstring_dataset(self,
61
                                     docstring,
62
                                     desc="",
63
                                     param_dict=None,
64
                                     retval_desc=""):
65
        param_dict = param_dict or {}
66
67
        self.assertIsInstance(docstring,
68
                              str,
69
                              "docstring needs to be a string for this test.")
70
        doc_comment = DocumentationComment.from_docstring(docstring)
71
        self.assertEqual(doc_comment.desc, desc)
72
        self.assertEqual(doc_comment.param_dict, param_dict)
73
        self.assertEqual(doc_comment.retval_desc, retval_desc)
74
75
76
if __name__ == '__main__':
77
    unittest.main(verbosity=2)
78