SF.net SVN: docutils:[9754] trunk/docutils

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9754
          http://sourceforge.net/p/docutils/code/9754
Author:   milde
Date:     2024-06-14 11:05:04 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
More precise error message for ODT writer with wrong encoding.

The ODT writer returns a document in binary format.
Therefore, it cannot be used with `output_encoding` set to
the special value "unicode".

Modified Paths:
--------------
    trunk/docutils/docutils/writers/odf_odt/__init__.py
    trunk/docutils/test/test_publisher.py

Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/odf_odt/__init__.py	2024-06-14 11:04:53 UTC (rev 9753)
+++ trunk/docutils/docutils/writers/odf_odt/__init__.py	2024-06-14 11:05:04 UTC (rev 9754)
@@ -837,6 +837,10 @@
         # nodes.SparseNodeVisitor.__init__(self, document)
         nodes.GenericNodeVisitor.__init__(self, document)
         self.settings = document.settings
+        if self.settings.output_encoding == 'unicode':
+            self.document.reporter.severe('The ODT writer returns `bytes` '
+                                          'that cannot be decoded to `str`')
+            # TODO: return document as "flat" XML?
         self.language_code = self.settings.language_code
         self.language = languages.get_language(
             self.language_code,

Modified: trunk/docutils/test/test_publisher.py
===================================================================
--- trunk/docutils/test/test_publisher.py	2024-06-14 11:04:53 UTC (rev 9753)
+++ trunk/docutils/test/test_publisher.py	2024-06-14 11:05:04 UTC (rev 9754)
@@ -143,12 +143,12 @@
 
         TODO: return `str` with document as "flat XML" (.fodt).
         """
-        settings = dict(self.settings)
-        settings['output_encoding'] = 'unicode'
-        with self.assertRaises(AssertionError) as cm:
+        settings = self.settings | {'output_encoding': 'unicode',
+                                    'warning_stream': ''}
+        with self.assertRaisesRegex(docutils.utils.SystemMessage,
+                                    'The ODT writer returns `bytes` '):
             core.publish_string('test', writer_name='odt',
                                 settings_overrides=settings)
-        self.assertIn('`data` is no `str` instance', str(cm.exception))
 
 
 class PublishDoctreeTestCase(unittest.TestCase, docutils.SettingsSpec):

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.