| 1 | #!/usr/bin/env python2
|
| 2 | """
|
| 3 | split_doc_test.py: Tests for split_doc.py
|
| 4 | """
|
| 5 | from __future__ import print_function
|
| 6 |
|
| 7 | import unittest
|
| 8 | from cStringIO import StringIO
|
| 9 |
|
| 10 | import split_doc # module under test
|
| 11 |
|
| 12 |
|
| 13 | class FooTest(unittest.TestCase):
|
| 14 |
|
| 15 | def testStrict(self):
|
| 16 | entry_f = StringIO('''\
|
| 17 | Title
|
| 18 | =====
|
| 19 |
|
| 20 | hello
|
| 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 | ---
|
| 39 | foo: bar
|
| 40 | ---
|
| 41 |
|
| 42 | Title
|
| 43 | =====
|
| 44 |
|
| 45 | hello
|
| 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 | ---
|
| 63 | foo: bar
|
| 64 | ---
|
| 65 | No Space Before Title
|
| 66 | =====================
|
| 67 |
|
| 68 | hello
|
| 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('''\
|
| 85 | No Space Before Title
|
| 86 | =====================
|
| 87 |
|
| 88 | hello
|
| 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 |
|
| 101 | if __name__ == '__main__':
|
| 102 | unittest.main()
|