| 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 |         entry_f = StringIO('''\
 | 
| 15 | Title
 | 
| 16 | =====
 | 
| 17 | 
 | 
| 18 | hello
 | 
| 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 | ---
 | 
| 41 | foo: bar
 | 
| 42 | ---
 | 
| 43 | 
 | 
| 44 | Title
 | 
| 45 | =====
 | 
| 46 | 
 | 
| 47 | hello
 | 
| 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 | ---
 | 
| 65 | foo: bar
 | 
| 66 | ---
 | 
| 67 | No Space Before Title
 | 
| 68 | =====================
 | 
| 69 | 
 | 
| 70 | hello
 | 
| 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('''\
 | 
| 87 | No Space Before Title
 | 
| 88 | =====================
 | 
| 89 | 
 | 
| 90 | hello
 | 
| 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 | 
 | 
| 103 | if __name__ == '__main__':
 | 
| 104 |     unittest.main()
 |