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

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