OILS / doctools / split_doc_test.py View on Github | oilshell.org

104 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 entry_f = StringIO('''\
15Title
16=====
17
18hello
19
20''')
21
22 meta_f = StringIO()
23 content_f = StringIO()
24
25 self.assertRaises(RuntimeError,
26 split_doc.SplitDocument, {},
27 entry_f,
28 meta_f,
29 content_f,
30 strict=True)
31
32 print(meta_f.getvalue())
33 print(content_f.getvalue())
34
35 def testMetadataAndTitle(self):
36 print('_' * 40)
37 print()
38
39 entry_f = StringIO('''\
40---
41foo: bar
42---
43
44Title
45=====
46
47hello
48
49''')
50
51 meta_f = StringIO()
52 content_f = StringIO()
53
54 split_doc.SplitDocument({'default': 'd'}, entry_f, meta_f, content_f)
55
56 print(meta_f.getvalue())
57 print(content_f.getvalue())
58
59 def testMetadataAndTitleNoSpace(self):
60 print('_' * 40)
61 print()
62
63 entry_f = StringIO('''\
64---
65foo: bar
66---
67No Space Before Title
68=====================
69
70hello
71
72''')
73
74 meta_f = StringIO()
75 content_f = StringIO()
76
77 split_doc.SplitDocument({'default': 'd'}, entry_f, meta_f, content_f)
78
79 print(meta_f.getvalue())
80 print(content_f.getvalue())
81
82 def testTitleOnly(self):
83 print('_' * 40)
84 print()
85
86 entry_f = StringIO('''\
87No Space Before Title
88=====================
89
90hello
91
92''')
93
94 meta_f = StringIO()
95 content_f = StringIO()
96
97 split_doc.SplitDocument({'default': 'd'}, entry_f, meta_f, content_f)
98
99 print(meta_f.getvalue())
100 print(content_f.getvalue())
101
102
103if __name__ == '__main__':
104 unittest.main()