summaryrefslogtreecommitdiff
path: root/docutils/test
diff options
context:
space:
mode:
Diffstat (limited to 'docutils/test')
-rw-r--r--docutils/test/functional/expected/odt_basic.odtbin0 -> 7400 bytes
-rw-r--r--docutils/test/functional/expected/odt_tables1.odtbin0 -> 9504 bytes
-rw-r--r--docutils/test/functional/input/odt_basic.txt9
-rw-r--r--docutils/test/functional/input/odt_tables1.txt171
-rwxr-xr-xdocutils/test/test_writers/test_odt.py134
5 files changed, 314 insertions, 0 deletions
diff --git a/docutils/test/functional/expected/odt_basic.odt b/docutils/test/functional/expected/odt_basic.odt
new file mode 100644
index 000000000..0691d2a33
--- /dev/null
+++ b/docutils/test/functional/expected/odt_basic.odt
Binary files differ
diff --git a/docutils/test/functional/expected/odt_tables1.odt b/docutils/test/functional/expected/odt_tables1.odt
new file mode 100644
index 000000000..7345c97ab
--- /dev/null
+++ b/docutils/test/functional/expected/odt_tables1.odt
Binary files differ
diff --git a/docutils/test/functional/input/odt_basic.txt b/docutils/test/functional/input/odt_basic.txt
new file mode 100644
index 000000000..ee5a844dc
--- /dev/null
+++ b/docutils/test/functional/input/odt_basic.txt
@@ -0,0 +1,9 @@
+=====
+Test
+=====
+
+Basic # 1
+==========
+
+A *simple* test.
+
diff --git a/docutils/test/functional/input/odt_tables1.txt b/docutils/test/functional/input/odt_tables1.txt
new file mode 100644
index 000000000..838b75479
--- /dev/null
+++ b/docutils/test/functional/input/odt_tables1.txt
@@ -0,0 +1,171 @@
+================================================================================
+Grid test
+================================================================================
+
+Test 1
+=======
+
++------------------------+------------+----------+----------+
+| Header row, column 1 | Header 2 | Header 3 | Header 4 |
+| (header rows optional) | | | |
++========================+============+==========+==========+
+| body row 1, column 1 | column 2 | column 3 | column 4 |
++------------------------+------------+----------+----------+
+| body row 2 | Cells may span columns. |
++------------------------+------------+---------------------+
+| body row 3 | Cells may | - Table cells |
++------------------------+ span rows. + - contain +
+| body row 4 | aaa | - body elements. |
++------------------------+------------+---------------------+
+
+Test 2
+=======
+
++------------------------+------------+----------+----------+
+| Header row, column 1 | Header 2 | Header 3 | Header 4 |
+| (header rows optional) | | | |
++========================+============+==========+==========+
+| body row 1, column 1 | column 2 | column 3 | column 4 |
++ +------------+----------+----------+
+| body row 2 | column 2 | column 3 | column 4 |
++------------------------+ +----------+----------+
+| body row 3 | may span | - Table cells |
++------------------------+------------+ - contain +
+| body row 4 | column 2 | - body elements. |
++------------------------+------------+---------------------+
+
+
+Test 3
+=======
+
++------------------------+------------+----------+----------+
+| Header row, column 1 | Header 2 | Header 3 | Header 4 |
+| (header rows optional) | | | |
++========================+============+==========+==========+
+| body row 1, column 1 | column 2 | column 3 | column 4 |
++ +------------+----------+ +
+| body row 2 | column 2 | column 3 | may span |
++------------------------+------------+ +----------+
+| body row 3 | column 2 | may span | column 4 |
++------------------------+ +----------+----------+
+| body row 4 | may span | column 3 | column 4 |
++------------------------+------------+----------+----------+
+
+
+Test 4
+=======
+
++------------------------+------------+----------+----------+
+| Header row, column 1 | Header 2 | Header 3 | Header 4 |
+| (header rows optional) | | | |
++========================+============+==========+==========+
+| body row 1, column 1 | column 2 | column 3 | column 4 |
++ +------------+----------+ +
+| body row 2 | column 2 and column 3 | may span |
++------------------------+ +----------+
+| body row 3 | may span | column 4 |
++ +------------+----------+----------+
+| may span | may span | column 3 | column 4 |
++------------------------+------------+----------+----------+
+
+Test 4a
+=======
+
++------------------------+------------+----------+----------+
+| Header row, column 1 | Header 2 | Header 3 | Header 4 |
+| (header rows optional) | | | |
++========================+============+==========+==========+
+| body row 1, column 1 | column 2 | column 3 | column 4 |
++ +------------+----------+ +
+| body row 2 | column 2 and column 3 | may span |
++------------------------+ +----------+
+| body row 3 | may span | column 4 |
++ +------------+----------+----------+
+| may span | may span | column 3 | column 4 |
++------------------------+------------+----------+----------+
+| body row 4 | column 2 | column 3 | column 4 |
++------------------------+------------+----------+----------+
+
+
+
+
+
+
+
+
+Test 5
+=======
+
++------------------------+------------+----------+----------+
+| Header row, column 1 | Header 2 | Header 3 | Header 4 |
+| (header rows optional) | | | |
++========================+============+==========+==========+
+| body row 1, column 1 | column 2 | column 3 | column 4 |
++------------------------+------------+----------+----------+
+| body row 2 | Cells may span columns. |
++------------------------+------------+---------------------+
+| body row 3 | Cells may | - Table cells |
++------------------------+ span rows. | - contain |
+| body row 4 | | - body elements. |
++------------------------+------------+---------------------+
+
+
+Test 6
+=======
+
+Some care must be taken with grid tables to avoid undesired
+interactions with cell text in rare cases. For example, the
+following table contains a cell in row 2 spanning from column 2 to
+column 4:
+
++--------------+----------+-----------+-----------+
+| row 1, col 1 | column 2 | column 3 | column 4 |
++--------------+----------+-----------+-----------+
+| row 2 | |
++--------------+----------+-----------+-----------+
+| row 3 | | | |
++--------------+----------+-----------+-----------+
+
+Test 7
+=======
+
+If a vertical bar is used in the text of that cell, it could have
+unintended effects if accidentally aligned with column boundaries:
+
++--------------+----------+-----------+-----------+
+| row 1, col 1 | column 2 | column 3 | column 4 |
++--------------+----------+-----------+-----------+
+| row 2 | Use the command ``ls \| more``. |
++--------------+----------+-----------+-----------+
+| row 3 | | | |
++--------------+----------+-----------+-----------+
+
+Test 8
+=======
+
+Several solutions are possible. All that is needed is to break the
+continuity of the cell outline rectangle. One possibility is to
+shift the text by adding an extra space before:
+
+
++--------------+----------+-----------+-----------+
+| row 1, col 1 | column 2 | column 3 | column 4 |
++--------------+----------+-----------+-----------+
+| row 2 | Use the command ``ls | more``. |
++--------------+----------+-----------+-----------+
+| row 3 | | | |
++--------------+----------+-----------+-----------+
+
+Test 9
+=======
+
+Another possibility is to add an extra line to row 2:
+
++--------------+----------+-----------+-----------+
+| row 1, col 1 | column 2 | column 3 | column 4 |
++--------------+----------+-----------+-----------+
+| row 2 | Use the command ``ls | more``. |
+| | |
++--------------+----------+-----------+-----------+
+| row 3 | | | |
++--------------+----------+-----------+-----------+
diff --git a/docutils/test/test_writers/test_odt.py b/docutils/test/test_writers/test_odt.py
new file mode 100755
index 000000000..728c33415
--- /dev/null
+++ b/docutils/test/test_writers/test_odt.py
@@ -0,0 +1,134 @@
+#!/usr/bin/env python
+
+# $Id$
+# Author: Dave Kuhlman <dkuhlman@rexx.com>
+# Copyright: This module has been placed in the public domain.
+
+"""
+Tests for docutils odtwriter.
+
+Instructions for adding a new test:
+
+1. Add a new method to class DocutilsOdtTestCase (below) named
+ test_odt_xxxx, where xxxx describes your new feature. See
+ test_odt_basic for an example.
+
+2. Add a new input reST (.txt) file in test/functional/input. This
+ file should contain the smallest amount of reST that tests your
+ new feature. Name this file odt_xxxx.txt.
+
+3. Convert your input reST (.txt) file to an ODF (.odt) file using
+ rst2odt.py. Place this ODF (.odt) file in
+ test/functional/expected. Name this file odt_xxxx.odt.
+ You can also pass parameter save_output=True to method
+ process_test() in order to produce expected output.
+ See variable TEMP_FILE_NAME for destination.
+
+4. Run your test. Your new test should pass.
+
+5. If any other tests fail, that's a possible regression.
+
+"""
+
+import sys
+import StringIO
+import zipfile
+from xml.dom import minidom
+import tempfile
+
+from __init__ import DocutilsTestSupport
+
+import docutils
+import docutils.core
+
+#
+# Globals
+TEMP_FILE_NAME = '/tmp/odtwriter_expected.odt'
+INPUT_PATH = 'functional/input/'
+EXPECTED_PATH = 'functional/expected/'
+
+
+class DocutilsOdtTestCase(DocutilsTestSupport.StandardTestCase):
+
+ def process_test(self, input_filename, expected_filename, save_output=False):
+ # Test that xmlcharrefreplace is the default output encoding
+ # error handler.
+ input_file = open(INPUT_PATH + input_filename, 'r')
+ expected_file = open(EXPECTED_PATH + expected_filename, 'r')
+ input = input_file.read()
+ expected = expected_file.read()
+ input_file.close()
+ expected_file.close()
+ settings_overrides={
+ }
+ result = docutils.core.publish_string(
+ source=input,
+ reader_name='standalone',
+ writer_name='odf_odt',
+ settings_overrides=settings_overrides)
+## msg = 'file length not equal: expected length: %d actual length: %d' % (
+## len(expected), len(result), )
+## self.assertEqual(str(len(result)), str(len(expected)))
+ if save_output:
+ outfile = open(TEMP_FILE_NAME, 'w')
+ outfile.write(result)
+ outfile.close()
+ content1 = self.extract_file(result, 'content.xml')
+ content2 = self.extract_file(expected, 'content.xml')
+ msg = 'content.xml not equal: expected len: %d actual len: %d' % (
+ len(content2), len(content1), )
+ self.assertEqual(content1, content2, msg)
+
+ def extract_file(self, payload, filename):
+ payloadfile = StringIO.StringIO()
+ payloadfile.write(payload)
+ payloadfile.seek(0)
+ zfile = zipfile.ZipFile(payloadfile, 'r')
+ content1 = zfile.read(filename)
+ doc = minidom.parseString(content1)
+ #content2 = doc.toprettyxml(indent=' ')
+ content2 = doc.toxml()
+ return content2
+
+ def assertEqual(self, first, second, msg=None):
+ if msg is None:
+ msg2 = msg
+ else:
+ sep = '+' * 60
+ msg1 = '\n%s\nresult:\n%s\n%s\nexpected:\n%s\n%s' % (
+ sep, first, sep, second, sep, )
+ #msg2 = '%s\n%s' % (msg1, msg, )
+ msg2 = '%s' % (msg, )
+ DocutilsTestSupport.StandardTestCase.failUnlessEqual(self,
+ first, second, msg2)
+
+ #
+ # Unit test methods
+ #
+ # All test methods should be named "test_odt_xxxx", where
+ # xxxx is replaced with a name for the new test.
+ # See instructions above in module doc-string.
+ #
+
+ def test_odt_basic(self):
+ self.process_test('odt_basic.txt', 'odt_basic.odt')
+
+ def test_odt_tables1(self):
+ self.process_test('odt_tables1.txt', 'odt_tables1.odt')
+
+ #
+ # Template for new tests.
+ # Also add functional/input/odt_xxxx.txt and
+ # functional/expected/odt_xxxx.odt
+ # Replace all xxxx with name of your test.
+ #
+## def test_odt_xxxx(self):
+## self.process_test('odt_xxxx.txt', 'odt_xxxx.odt')
+
+
+# -----------------------------------------------------------------
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main()