1
|
|
|
import unittest |
2
|
|
|
|
3
|
|
|
from coalib.bearlib.languages.documentation.DocstyleDefinition import ( |
4
|
|
|
DocstyleDefinition) |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class DocstyleDefinitionTest(unittest.TestCase): |
8
|
|
|
|
9
|
|
|
def test_fail_instantation(self): |
10
|
|
|
with self.assertRaises(ValueError): |
11
|
|
|
DocstyleDefinition("PYTHON", "doxyGEN", (("##", "#"),)) |
12
|
|
|
|
13
|
|
|
with self.assertRaises(ValueError): |
14
|
|
|
DocstyleDefinition("WEIRD-PY", |
15
|
|
|
"schloxygen", |
16
|
|
|
(("##+", "x", "y", "z"),)) |
17
|
|
|
|
18
|
|
|
with self.assertRaises(ValueError): |
19
|
|
|
DocstyleDefinition("PYTHON", |
20
|
|
|
"doxygen", |
21
|
|
|
(("##", "", "#"), ('"""', '"""'))) |
22
|
|
|
|
23
|
|
|
with self.assertRaises(TypeError): |
24
|
|
|
DocstyleDefinition(123, ["doxygen"], (('"""', '"""'))) |
25
|
|
|
|
26
|
|
|
def test_properties(self): |
27
|
|
|
uut = DocstyleDefinition("C", "doxygen", (("/**", "*", "*/"),)) |
28
|
|
|
|
29
|
|
|
self.assertEqual(uut.language, "c") |
30
|
|
|
self.assertEqual(uut.docstyle, "doxygen") |
31
|
|
|
self.assertEqual(uut.markers, (("/**", "*", "*/"),)) |
32
|
|
|
|
33
|
|
|
uut = DocstyleDefinition("PYTHON", "doxyGEN", [("##", "", "#")]) |
34
|
|
|
|
35
|
|
|
self.assertEqual(uut.language, "python") |
36
|
|
|
self.assertEqual(uut.docstyle, "doxygen") |
37
|
|
|
self.assertEqual(uut.markers, (("##", "", "#"),)) |
38
|
|
|
|
39
|
|
|
uut = DocstyleDefinition("I2C", |
40
|
|
|
"my-custom-tool", |
41
|
|
|
(["~~", "/~", "/~"], (">!", ">>", ">>"))) |
42
|
|
|
|
43
|
|
|
self.assertEqual(uut.language, "i2c") |
44
|
|
|
self.assertEqual(uut.docstyle, "my-custom-tool") |
45
|
|
|
self.assertEqual(uut.markers, (("~~", "/~", "/~"), (">!", ">>", ">>"))) |
46
|
|
|
|
47
|
|
|
uut = DocstyleDefinition("Cpp", "doxygen", ("~~", "/~", "/~")) |
48
|
|
|
|
49
|
|
|
self.assertEqual(uut.language, "cpp") |
50
|
|
|
self.assertEqual(uut.docstyle, "doxygen") |
51
|
|
|
self.assertEqual(uut.markers, (("~~", "/~", "/~"),)) |
52
|
|
|
|
53
|
|
|
def test_load(self): |
54
|
|
|
# Test unregistered docstyle. |
55
|
|
|
with self.assertRaises(FileNotFoundError): |
56
|
|
|
next(DocstyleDefinition.load("PYTHON", "INVALID")) |
57
|
|
|
|
58
|
|
|
# Test unregistered language in existing docstyle. |
59
|
|
|
with self.assertRaises(KeyError): |
60
|
|
|
next(DocstyleDefinition.load("bake-a-cake", "default")) |
61
|
|
|
|
62
|
|
|
# Test wrong argument type. |
63
|
|
|
with self.assertRaises(TypeError): |
64
|
|
|
next(DocstyleDefinition.load(123, ["list"])) |
65
|
|
|
|
66
|
|
|
# Test python 3 default configuration and if everything is parsed |
67
|
|
|
# right. |
68
|
|
|
result = DocstyleDefinition.load("PYTHON3", "default") |
69
|
|
|
|
70
|
|
|
self.assertEqual(result.language, "python3") |
71
|
|
|
self.assertEqual(result.docstyle, "default") |
72
|
|
|
self.assertEqual(result.markers, (('"""', '', '"""'),)) |
73
|
|
|
|