| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | import unittest |
|---|
| 5 | from lxml import etree |
|---|
| 6 | from . import xhtml2odt |
|---|
| 7 | |
|---|
| 8 | class BlockElements(unittest.TestCase): |
|---|
| 9 | |
|---|
| 10 | def test_blockquote(self): |
|---|
| 11 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><blockquote><p>Test</p></blockquote></html>' |
|---|
| 12 | odt = xhtml2odt(html) |
|---|
| 13 | print odt |
|---|
| 14 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Quotations">Test</text:p>\n' |
|---|
| 15 | |
|---|
| 16 | def test_hr(self): |
|---|
| 17 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><hr/></html>' |
|---|
| 18 | odt = xhtml2odt(html) |
|---|
| 19 | print odt |
|---|
| 20 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Horizontal_20_Line"/>\n' |
|---|
| 21 | |
|---|
| 22 | def test_pre1(self): |
|---|
| 23 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><pre>Test</pre></html>' |
|---|
| 24 | odt = xhtml2odt(html) |
|---|
| 25 | print odt |
|---|
| 26 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text">Test</text:p>\n' |
|---|
| 27 | |
|---|
| 28 | def test_pre2(self): |
|---|
| 29 | """<pre>: insertion of line breaks""" |
|---|
| 30 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><pre>First line\nSecond line</pre></html>' |
|---|
| 31 | odt = xhtml2odt(html) |
|---|
| 32 | print odt |
|---|
| 33 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text">First line<text:line-break/>Second line</text:p>\n' |
|---|
| 34 | |
|---|
| 35 | def test_pre3(self): |
|---|
| 36 | """<pre>: space preservation""" |
|---|
| 37 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><pre> Line with spaces </pre></html>' |
|---|
| 38 | odt = xhtml2odt(html) |
|---|
| 39 | print odt |
|---|
| 40 | # note: one of the spaces below is a non-breaking space, can you spot it ? ;-) |
|---|
| 41 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"> Line with spaces </text:p>\n' |
|---|
| 42 | |
|---|
| 43 | def test_pre4(self): |
|---|
| 44 | """<pre>: removing last line-break""" |
|---|
| 45 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><pre>Line\n</pre></html>' |
|---|
| 46 | odt = xhtml2odt(html) |
|---|
| 47 | print odt |
|---|
| 48 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text">Line</text:p>\n' |
|---|
| 49 | |
|---|
| 50 | def test_pre5(self): |
|---|
| 51 | """<pre>: adjacent subelements""" |
|---|
| 52 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><pre><span>Line1</span>\n<span>Line2</span></pre></html>' |
|---|
| 53 | odt = xhtml2odt(html) |
|---|
| 54 | self.assertEquals(str(odt), '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text">Line1<text:line-break/>Line2</text:p>\n') |
|---|
| 55 | |
|---|
| 56 | def test_pre6(self): |
|---|
| 57 | """<pre>: removing last line-break of many""" |
|---|
| 58 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><pre>Line1\nLine2\n</pre></html>' |
|---|
| 59 | odt = xhtml2odt(html) |
|---|
| 60 | print odt |
|---|
| 61 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text">Line1<text:line-break/>Line2</text:p>\n' |
|---|
| 62 | |
|---|
| 63 | def test_address(self): |
|---|
| 64 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><address>Test</address></html>' |
|---|
| 65 | odt = xhtml2odt(html) |
|---|
| 66 | print odt |
|---|
| 67 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Sender">Test</text:p>\n' |
|---|
| 68 | |
|---|
| 69 | def test_center(self): |
|---|
| 70 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><center>Test</center></html>' |
|---|
| 71 | odt = xhtml2odt(html) |
|---|
| 72 | print odt |
|---|
| 73 | assert str(odt) == '<?xml version="1.0" encoding="utf-8"?>\n<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="center">Test</text:p>\n' |
|---|
| 74 | |
|---|
| 75 | def test_center_containing_ul(self): |
|---|
| 76 | """center tag containing block-type elements""" |
|---|
| 77 | html = '<html xmlns="http://www.w3.org/1999/xhtml"><center>Test1<ul><li>Test2</li></ul>Test3</center></html>' |
|---|
| 78 | odt = xhtml2odt(html) |
|---|
| 79 | print odt |
|---|
| 80 | assert str(odt) == """<?xml version="1.0" encoding="utf-8"?> |
|---|
| 81 | <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="center">Test1</text:p>""" + \ |
|---|
| 82 | """<text:list xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="List_20_1"> |
|---|
| 83 | <text:list-item> |
|---|
| 84 | <text:p text:style-name="list-item-bullet">Test2</text:p> |
|---|
| 85 | </text:list-item> |
|---|
| 86 | </text:list>""" + \ |
|---|
| 87 | """<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="center">Test3</text:p> |
|---|
| 88 | """ |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | if __name__ == '__main__': |
|---|
| 92 | unittest.main() |
|---|