OILS / doctools / split_doc_test.py View on Github | oils.pub

108 lines, 50 significant
1#!/usr/bin/env python2
2"""split_doc_test.py: Tests for split_doc.py."""
3from __future__ import print_function
4
5import unittest
6from cStringIO import StringIO
7
8import split_doc # module under test
9
10
11class FooTest(unittest.TestCase):
12
13 def testStrict(self):
14 # type: () -> None
15 entry_f = StringIO('''\
16Title
17=====
18
19hello
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---
43foo: bar
44---
45
46Title
47=====
48
49hello
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---
68foo: bar
69---
70No Space Before Title
71=====================
72
73hello
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('''\
91No Space Before Title
92=====================
93
94hello
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
107if __name__ == '__main__':
108 unittest.main()