1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from unittest import TestCase
24
25
26 from lib.text.sectioning import section, subsection, subsubsection, subsubtitle, subtitle, title
27 from relax_io import DummyFileObject
28
29
31 """Unit tests for the lib.text.sectioning relax module."""
32
34 """Test of the lib.text.sectioning.section() function."""
35
36
37 file = DummyFileObject()
38 section(file=file, text='Test section')
39
40
41 lines = file.readlines()
42 print("Formatted section lines: %s" % lines)
43
44
45 real_lines = [
46 '\n',
47 '\n',
48 'Test section\n',
49 '============\n',
50 '\n',
51 ]
52 self.assertEqual(len(lines), len(real_lines))
53 for i in range(len(lines)):
54 self.assertEqual(lines[i], real_lines[i])
55
56
58 """Test of the lib.text.sectioning.subsection() function."""
59
60
61 file = DummyFileObject()
62 subsection(file=file, text='Test subsection')
63
64
65 lines = file.readlines()
66 print("Formatted subsection lines: %s" % lines)
67
68
69 real_lines = [
70 '\n',
71 'Test subsection\n',
72 '---------------\n',
73 '\n',
74 ]
75 self.assertEqual(len(lines), len(real_lines))
76 for i in range(len(lines)):
77 self.assertEqual(lines[i], real_lines[i])
78
79
81 """Test of the lib.text.sectioning.subsubsection() function."""
82
83
84 file = DummyFileObject()
85 subsubsection(file=file, text='Test subsubsection')
86
87
88 lines = file.readlines()
89 print("Formatted subsubsection lines: %s" % lines)
90
91
92 real_lines = [
93 '\n',
94 'Test subsubsection\n',
95 '~~~~~~~~~~~~~~~~~~\n',
96 '\n',
97 ]
98 self.assertEqual(len(lines), len(real_lines))
99 for i in range(len(lines)):
100 self.assertEqual(lines[i], real_lines[i])
101
102
104 """Test of the lib.text.sectioning.subsubtitle() function."""
105
106
107 file = DummyFileObject()
108 subsubtitle(file=file, text='Test subsubtitle')
109
110
111 lines = file.readlines()
112 print("Formatted subsubtitle lines: %s" % lines)
113
114
115 real_lines = [
116 '\n',
117 '~~~~~~~~~~~~~~~~~~~~\n',
118 '~ Test subsubtitle ~\n',
119 '~~~~~~~~~~~~~~~~~~~~\n',
120 '\n',
121 ]
122 self.assertEqual(len(lines), len(real_lines))
123 for i in range(len(lines)):
124 self.assertEqual(lines[i], real_lines[i])
125
126
128 """Test of the lib.text.sectioning.subtitle() function."""
129
130
131 file = DummyFileObject()
132 subtitle(file=file, text='Test subtitle')
133
134
135 lines = file.readlines()
136 print("Formatted subtitle lines: %s" % lines)
137
138
139 real_lines = [
140 '\n',
141 '-----------------\n',
142 '- Test subtitle -\n',
143 '-----------------\n',
144 '\n',
145 ]
146 self.assertEqual(len(lines), len(real_lines))
147 for i in range(len(lines)):
148 self.assertEqual(lines[i], real_lines[i])
149
150
152 """Test of the lib.text.sectioning.title() function."""
153
154
155 file = DummyFileObject()
156 title(file=file, text='Test title')
157
158
159 lines = file.readlines()
160 print("Formatted title lines: %s" % lines)
161
162
163 real_lines = [
164 '\n',
165 '\n',
166 '==============\n',
167 '= Test title =\n',
168 '==============\n',
169 '\n',
170 ]
171 self.assertEqual(len(lines), len(real_lines))
172 for i in range(len(lines)):
173 self.assertEqual(lines[i], real_lines[i])
174