1 | #!/usr/bin/env python2
|
2 | """split_doc_test.py: Tests for split_doc.py."""
|
3 | from __future__ import print_function
|
4 |
|
5 | import unittest
|
6 | from cStringIO import StringIO
|
7 |
|
8 | import split_doc # module under test
|
9 |
|
10 |
|
11 | class FooTest(unittest.TestCase):
|
12 |
|
13 | def testStrict(self):
|
14 | # type: () -> None
|
15 | entry_f = StringIO('''\
|
16 | Title
|
17 | =====
|
18 |
|
19 | hello
|
20 |
|
21 | ''')
|
22 |
|
23 | meta_f = StringIO()
|
24 | content_f = StringIO()
|
25 |
|
26 | self.assertRaises(RuntimeError,
|
27 | split_doc.SplitDocument, {},
|
28 | entry_f,
|
29 | meta_f,
|
30 | content_f,
|
31 | strict=True)
|
32 |
|
33 | print(meta_f.getvalue())
|
34 | print(content_f.getvalue())
|
35 |
|
36 | def testMetadataAndTitle(self):
|
37 | # type: () -> None
|
38 | print('_' * 40)
|
39 | print()
|
40 |
|
41 | entry_f = StringIO('''\
|
42 | ---
|
43 | foo: bar
|
44 | ---
|
45 |
|
46 | Title
|
47 | =====
|
48 |
|
49 | hello
|
50 |
|
51 | ''')
|
52 |
|
53 | meta_f = StringIO()
|
54 | content_f = StringIO()
|
55 |
|
56 | split_doc.SplitDocument({'default': 'd'}, entry_f, meta_f, content_f)
|
57 |
|
58 | print(meta_f.getvalue())
|
59 | print(content_f.getvalue())
|
60 |
|
61 | def testMetadataAndTitleNoSpace(self):
|
62 | # type: () -> None
|
63 | print('_' * 40)
|
64 | print()
|
65 |
|
66 | entry_f = StringIO('''\
|
67 | ---
|
68 | foo: bar
|
69 | ---
|
70 | No Space Before Title
|
71 | =====================
|
72 |
|
73 | hello
|
74 |
|
75 | ''')
|
76 |
|
77 | meta_f = StringIO()
|
78 | content_f = StringIO()
|
79 |
|
80 | split_doc.SplitDocument({'default': 'd'}, entry_f, meta_f, content_f)
|
81 |
|
82 | print(meta_f.getvalue())
|
83 | print(content_f.getvalue())
|
84 |
|
85 | def testTitleOnly(self):
|
86 | # type: () -> None
|
87 | print('_' * 40)
|
88 | print()
|
89 |
|
90 | entry_f = StringIO('''\
|
91 | No Space Before Title
|
92 | =====================
|
93 |
|
94 | hello
|
95 |
|
96 | ''')
|
97 |
|
98 | meta_f = StringIO()
|
99 | content_f = StringIO()
|
100 |
|
101 | split_doc.SplitDocument({'default': 'd'}, entry_f, meta_f, content_f)
|
102 |
|
103 | print(meta_f.getvalue())
|
104 | print(content_f.getvalue())
|
105 |
|
106 |
|
107 | if __name__ == '__main__':
|
108 | unittest.main()
|