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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9770
          http://sourceforge.net/p/docutils/code/9770
Author:   milde
Date:     2024-06-18 07:44:50 +0000 (Tue, 18 Jun 2024)
Log Message:
-----------
Unify arguments for component name and instance in core.py.

Allow a string value (component name or alias) in the
"reader", "parser", and "writer" arguments of `Publisher.__init__()`
and the `publish_*()` convenience functions.

Warn about the pending removal of the "reader_name",
"parser_name", and "writer_name" function arguments.

Modified Paths:
--------------
    trunk/docutils/HISTORY.txt
    trunk/docutils/RELEASE-NOTES.txt
    trunk/docutils/docutils/core.py
    trunk/docutils/test/test_publisher.py

Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt	2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/HISTORY.txt	2024-06-18 07:44:50 UTC (rev 9770)
@@ -30,6 +30,9 @@
 * docutils/core.py
 
   - Removed `Publisher.setup_option_parser()` (internal, obsolete).
+  - Allow a string value (component name or alias) in the
+    "reader", "parser", and "writer" arguments of `Publisher.__init__()`
+    and the `publish_*()` convenience functions.
 
 * docutils/frontend.py
 

Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt	2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/RELEASE-NOTES.txt	2024-06-18 07:44:50 UTC (rev 9770)
@@ -152,6 +152,11 @@
   (obsoleted by the `"writer" setting`_ since Docutils 0.18)
   in Docutils 2.0.
 
+* Remove the "reader_name", "parser_name", and "writer_name" arguments of
+  `core.Publisher.__init__()` and the `core.publish_*()` convenience
+  functions in Docutils 2.0.  Since Docutils 0.22, you may use "reader",
+  "parser", and "writer" arguments for component names as well as instances.
+
 * Revise the `String I/O`__ interface used by the `publish_string()`
   and `publish_from_doctree()` publisher convenience functions.
   (In Python 3, name and behaviour no longer match.)

Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py	2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/docutils/core.py	2024-06-18 07:44:50 UTC (rev 9770)
@@ -22,7 +22,7 @@
 import warnings
 
 from docutils import (__version__, __version_details__, SettingsSpec,
-                      io, utils, readers, writers)
+                      io, utils, readers, parsers, writers)
 from docutils.frontend import OptionParser
 from docutils.readers import doctree
 
@@ -38,11 +38,23 @@
                  destination=None, destination_class=io.FileOutput,
                  settings=None):
         """
-        Initial setup.  If any of `reader`, `parser`, or `writer` are not
-        specified, ``set_components()`` or the corresponding ``set_...()``
-        method should be called with component names
-        (`set_reader` sets the parser as well).
+        Initial setup.
+
+        The components `reader`, `parser`, or `writer` should all be
+        specified, either as instances or via their names.
         """
+        # get component instances from their names:
+        if isinstance(reader, str):
+            reader = readers.get_reader_class(reader)(parser)
+        if isinstance(parser, str):
+            if isinstance(reader, readers.Reader):
+                if reader.parser is None:
+                    reader.set_parser(parser)
+                parser = reader.parser
+            else:
+                parser = parsers.get_parser_class(parser)()
+        if isinstance(writer, str):
+            writer = writers.get_writer_class(writer)()
 
         self.document = None
         """The document tree (`docutils.nodes` objects)."""
@@ -56,13 +68,6 @@
         self.writer = writer
         """A `docutils.writers.Writer` instance."""
 
-        for component in 'reader', 'parser', 'writer':
-            assert not isinstance(getattr(self, component), str), (
-                'passed string "%s" as "%s" parameter; pass an instance, '
-                'or use the "%s_name" parameter instead (in '
-                'docutils.core.publish_* convenience functions).'
-                % (getattr(self, component), component, component))
-
         self.source = source
         """The source of input data, a `docutils.io.Input` instance."""
 
@@ -82,11 +87,18 @@
 
         self._stderr = io.ErrorOutput()
 
-    def set_reader(self, reader_name, parser, parser_name):
-        """Set `self.reader` by name."""
-        reader_class = readers.get_reader_class(reader_name)
+    def set_reader(self, reader, parser=None, parser_name=None):
+        """Set `self.reader` by name.
+
+        The "paser_name" argument is deprecated,
+        use "parser" with parser name or instance.
+        """
+        reader_class = readers.get_reader_class(reader)
         self.reader = reader_class(parser, parser_name)
-        self.parser = self.reader.parser
+        if self.reader.parser is not None:
+            self.parser = self.reader.parser
+        elif self.parser is not None:
+            self.reader.parser = self.parser
 
     def set_writer(self, writer_name):
         """Set `self.writer` by name."""
@@ -94,6 +106,10 @@
         self.writer = writer_class()
 
     def set_components(self, reader_name, parser_name, writer_name):
+        warnings.warn('`Publisher.set_components()` will be removed in '
+                      'Docutils 2.0.  Specify component names '
+                      'at instantiation.',
+                      PendingDeprecationWarning, stacklevel=2)
         if self.reader is None:
             self.set_reader(reader_name, self.parser, parser_name)
         if self.parser is None:
@@ -371,9 +387,9 @@
 # Chain several args as input and use --output or redirection for output:
 #   argparser.add_argument('source', nargs='+')
 #
-def publish_cmdline(reader=None, reader_name='standalone',
-                    parser=None, parser_name='restructuredtext',
-                    writer=None, writer_name='pseudoxml',
+def publish_cmdline(reader=None, reader_name=None,
+                    parser=None, parser_name=None,
+                    writer=None, writer_name=None,
                     settings=None, settings_spec=None,
                     settings_overrides=None, config_section=None,
                     enable_exit_status=True, argv=None,
@@ -392,8 +408,13 @@
     - `description`: Program description, output for the "--help" option
       (along with command-line option descriptions).
     """
+    # The "*_name" arguments are deprecated.
+    _name_arg_warning(reader_name, parser_name, writer_name)
+    # The default is only used if both arguments are empty
+    reader = reader or reader_name or 'standalone'
+    parser = parser or parser_name or 'restructuredtext'
+    writer = writer or writer_name or 'pseudoxml'
     publisher = Publisher(reader, parser, writer, settings=settings)
-    publisher.set_components(reader_name, parser_name, writer_name)
     output = publisher.publish(
         argv, usage, description, settings_spec, settings_overrides,
         config_section=config_section, enable_exit_status=enable_exit_status)
@@ -402,9 +423,9 @@
 
 def publish_file(source=None, source_path=None,
                  destination=None, destination_path=None,
-                 reader=None, reader_name='standalone',
-                 parser=None, parser_name='restructuredtext',
-                 writer=None, writer_name='pseudoxml',
+                 reader=None, reader_name=None,
+                 parser=None, parser_name=None,
+                 writer=None, writer_name=None,
                  settings=None, settings_spec=None, settings_overrides=None,
                  config_section=None, enable_exit_status=False):
     """
@@ -414,6 +435,9 @@
 
     Parameters: see `publish_programmatically()`.
     """
+    # The "*_name" arguments are deprecated.
+    _name_arg_warning(reader_name, parser_name, writer_name)
+    # The default is set in publish_programmatically().
     output, publisher = publish_programmatically(
         source_class=io.FileInput, source=source, source_path=source_path,
         destination_class=io.FileOutput,
@@ -429,9 +453,9 @@
 
 
 def publish_string(source, source_path=None, destination_path=None,
-                   reader=None, reader_name='standalone',
-                   parser=None, parser_name='restructuredtext',
-                   writer=None, writer_name='pseudoxml',
+                   reader=None, reader_name=None,
+                   parser=None, parser_name=None,
+                   writer=None, writer_name=None,
                    settings=None, settings_spec=None,
                    settings_overrides=None, config_section=None,
                    enable_exit_status=False):
@@ -444,7 +468,8 @@
     the return value is a `bytes` instance (unless `output_encoding`_ is
     "unicode", cf. `docutils.io.StringOutput.write()`).
 
-    Parameters: see `publish_programmatically()`.
+    Parameters: see `publish_programmatically()` or
+    https://docutils.sourceforge.io/docs/api/publisher.html#publish-string
 
     This function is provisional because in Python 3 name and behaviour
     no longer match.
@@ -452,6 +477,9 @@
     .. _output_encoding:
         https://docutils.sourceforge.io/docs/user/config.html#output-encoding
     """
+    # The "*_name" arguments are deprecated.
+    _name_arg_warning(reader_name, parser_name, writer_name)
+    # The default is set in publish_programmatically().
     output, publisher = publish_programmatically(
         source_class=io.StringInput, source=source, source_path=source_path,
         destination_class=io.StringOutput,
@@ -468,9 +496,9 @@
 
 def publish_parts(source, source_path=None, source_class=io.StringInput,
                   destination_path=None,
-                  reader=None, reader_name='standalone',
-                  parser=None, parser_name='restructuredtext',
-                  writer=None, writer_name='pseudoxml',
+                  reader=None, reader_name=None,
+                  parser=None, parser_name=None,
+                  writer=None, writer_name=None,
                   settings=None, settings_spec=None,
                   settings_overrides=None, config_section=None,
                   enable_exit_status=False):
@@ -490,6 +518,9 @@
 
     __ https://docutils.sourceforge.io/docs/api/publisher.html#publish-parts
     """
+    # The "*_name" arguments are deprecated.
+    _name_arg_warning(reader_name, parser_name, writer_name)
+    # The default is set in publish_programmatically().
     output, publisher = publish_programmatically(
         source=source, source_path=source_path, source_class=source_class,
         destination_class=io.StringOutput,
@@ -506,8 +537,8 @@
 
 def publish_doctree(source, source_path=None,
                     source_class=io.StringInput,
-                    reader=None, reader_name='standalone',
-                    parser=None, parser_name='restructuredtext',
+                    reader=None, reader_name=None,
+                    parser=None, parser_name=None,
                     settings=None, settings_spec=None,
                     settings_overrides=None, config_section=None,
                     enable_exit_status=False):
@@ -516,6 +547,9 @@
 
     Parameters: see `publish_programmatically()`.
     """
+    # The "*_name" arguments are deprecated.
+    _name_arg_warning(reader_name, parser_name, None)
+    # The default is set in publish_programmatically().
     _output, publisher = publish_programmatically(
         source=source, source_path=source_path,
         source_class=source_class,
@@ -523,7 +557,7 @@
         destination_class=io.NullOutput,
         reader=reader, reader_name=reader_name,
         parser=parser, parser_name=parser_name,
-        writer=None, writer_name='null',
+        writer='null', writer_name=None,
         settings=settings, settings_spec=settings_spec,
         settings_overrides=settings_overrides, config_section=config_section,
         enable_exit_status=enable_exit_status)
@@ -531,7 +565,7 @@
 
 
 def publish_from_doctree(document, destination_path=None,
-                         writer=None, writer_name='pseudoxml',
+                         writer=None, writer_name=None,
                          settings=None, settings_spec=None,
                          settings_overrides=None, config_section=None,
                          enable_exit_status=False):
@@ -554,13 +588,13 @@
     This function is provisional because in Python 3 name and behaviour
     of the `io.StringOutput` class no longer match.
     """
-    reader = doctree.Reader(parser_name='null')
-    publisher = Publisher(reader, None, writer,
+    # The "writer_name" argument is deprecated.
+    _name_arg_warning(None, None, writer_name)
+    publisher = Publisher(reader=doctree.Reader(),
+                          writer=writer or writer_name or 'pseudoxml',
                           source=io.DocTreeInput(document),
                           destination_class=io.StringOutput,
                           settings=settings)
-    if not writer and writer_name:
-        publisher.set_writer(writer_name)
     publisher.process_programmatic_settings(
         settings_spec, settings_overrides, config_section)
     publisher.set_destination(None, destination_path)
@@ -611,6 +645,15 @@
     return output
 
 
+def _name_arg_warning(*name_args):
+    for component, name_arg in zip(('reader', 'parser', 'writer'), name_args):
+        if name_arg is not None:
+            warnings.warn(f'Argument "{component}_name" will be removed in '
+                          f'Docutils 2.0.  Specify {component} name '
+                          f'in the "{component}" argument.',
+                          PendingDeprecationWarning, stacklevel=3)
+
+
 def publish_programmatically(source_class, source, source_path,
                              destination_class, destination, destination_path,
                              reader, reader_name,
@@ -625,7 +668,8 @@
     Return the output (as `str` or `bytes`, depending on `destination_class`,
     writer, and the "output_encoding" setting) and the Publisher object.
 
-    Applications should not need to call this function directly.  If it does
+    Internal:
+    Applications should not call this function directly.  If it does
     seem to be necessary to call this function directly, please write to the
     Docutils-develop mailing list
     <https://docutils.sourceforge.io/docs/user/mailing-lists.html#docutils-develop>.
@@ -675,20 +719,20 @@
         output; optional.  Used for determining relative paths (stylesheets,
         source links, etc.).
 
-    * `reader`: A `docutils.readers.Reader` object.
+    * `reader`: A `docutils.readers.Reader` instance, name, or alias.
+      Default: "standalone".
 
-    * `reader_name`: Name or alias of the Reader class to be instantiated if
-      no `reader` supplied.
+    * `reader_name`: Deprecated. Use `reader`.
 
-    * `parser`: A `docutils.parsers.Parser` object.
+    * `parser`: A `docutils.parsers.Parser` instance, name, or alias.
+      Default: "restructuredtext".
 
-    * `parser_name`: Name or alias of the Parser class to be instantiated if
-      no `parser` supplied.
+    * `parser_name`: Deprecated. Use `parser`.
 
-    * `writer`: A `docutils.writers.Writer` object.
+    * `writer`: A `docutils.writers.Writer` instance, name, or alias.
+      Default: "pseudoxml".
 
-    * `writer_name`: Name or alias of the Writer class to be instantiated if
-      no `writer` supplied.
+    * `writer_name`: Deprecated. Use `writer`.
 
     * `settings`: A runtime settings (`docutils.frontend.Values`) object, for
       dotted-attribute access to runtime settings.  It's the end result of the
@@ -712,10 +756,13 @@
 
     * `enable_exit_status`: Boolean; enable exit status at end of processing?
     """
+    reader = reader or reader_name or 'standalone'
+    parser = parser or parser_name or 'restructuredtext'
+    writer = writer or writer_name or 'pseudoxml'
+
     publisher = Publisher(reader, parser, writer, settings=settings,
                           source_class=source_class,
                           destination_class=destination_class)
-    publisher.set_components(reader_name, parser_name, writer_name)
     publisher.process_programmatic_settings(
         settings_spec, settings_overrides, config_section)
     publisher.set_source(source, source_path)
@@ -728,7 +775,7 @@
 # cf. https://packaging.python.org/en/latest/specifications/entry-points/
 
 def rst2something(writer, documenttype, doc_path=''):
-    # Helper function for the common parts of rst2...
+    # Helper function for the common parts of `rst2*()`
     #   writer:       writer name
     #   documenttype: output document type
     #   doc_path:     documentation path (relative to the documentation root)
@@ -738,7 +785,7 @@
         f'<https://docutils.sourceforge.io/docs/{doc_path}>.  '
         + default_description)
     locale.setlocale(locale.LC_ALL, '')
-    publish_cmdline(writer_name=writer, description=description)
+    publish_cmdline(writer=writer, description=description)
 
 
 def rst2html():

Modified: trunk/docutils/test/test_publisher.py
===================================================================
--- trunk/docutils/test/test_publisher.py	2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/test/test_publisher.py	2024-06-18 07:44:50 UTC (rev 9770)
@@ -7,7 +7,6 @@
 """
 Test the `Publisher` facade and the ``publish_*`` convenience functions.
 """
-import os.path
 import pickle
 from pathlib import Path
 import sys
@@ -19,11 +18,13 @@
     sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
 
 import docutils
-from docutils import core, nodes
+from docutils import core, nodes, parsers, readers, writers
+import docutils.parsers.null
 
 # DATA_ROOT is ./test/data/ from the docutils root
-DATA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
+DATA_ROOT = Path(__file__).parent / 'data'
 
+
 test_document = """\
 Test Document
 =============
@@ -64,14 +65,106 @@
 
 class PublisherTests(unittest.TestCase):
 
+    def test__init__(self):
+        reader = readers.standalone.Reader()
+        parser = parsers.null.Parser()
+        writer = writers.null.Writer()
+        # arguments may be component instances ...
+        publisher = core.Publisher(reader, parser, writer)
+        self.assertEqual(publisher.reader, reader)
+        self.assertEqual(publisher.parser, parser)
+        self.assertEqual(publisher.writer, writer)
+        # ... or names
+        publisher = core.Publisher('standalone', parser, writer)
+        self.assertTrue(isinstance(publisher.reader,
+                                   readers.standalone.Reader))
+        self.assertEqual(publisher.parser, parser)
+        self.assertEqual(publisher.writer, writer)
+
+        publisher = core.Publisher(reader, 'rst', writer)
+        self.assertEqual(publisher.reader, reader)
+        self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+        self.assertEqual(publisher.writer, writer)
+
+        publisher = core.Publisher(reader, parser, 'latex')
+        self.assertEqual(publisher.reader, reader)
+        self.assertEqual(publisher.parser, parser)
+        self.assertTrue(isinstance(publisher.writer, writers.latex2e.Writer))
+
+    def test_set_reader(self):
+        publisher = core.Publisher(parser='null')
+        parser = parsers.null.Parser()
+        # "parser" argument can be an instance or name
+        publisher.set_reader('standalone', parser='rst')
+        self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+        # synchronize parser attributes of publisher and reader:
+        self.assertEqual(publisher.reader.parser, publisher.parser)
+        # the "parser_name" argument is deprecated;
+        with self.assertWarnsRegex(DeprecationWarning,
+                                   'Argument "parser_name" will be removed'):
+            publisher.set_reader('standalone', parser=None, parser_name='rst')
+        self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+        self.assertEqual(publisher.reader.parser, publisher.parser)
+        # "parser" takes precedence
+        with self.assertWarns(DeprecationWarning):
+            publisher.set_reader('standalone', parser, parser_name='rst')
+        self.assertEqual(publisher.parser, parser)
+        self.assertEqual(publisher.reader.parser, publisher.parser)
+        # if there is no other parser specified, use self.parser
+        publisher.set_reader('standalone')
+        self.assertTrue(isinstance(publisher.parser, parsers.null.Parser))
+        self.assertEqual(publisher.reader.parser, publisher.parser)
+
+    def test_set_components(self):
+        publisher = core.Publisher()
+        reader = readers.standalone.Reader()
+        parser = parsers.null.Parser()
+        writer = writers.null.Writer()
+        # set components from names
+        with self.assertWarnsRegex(PendingDeprecationWarning,
+                                   'set_components.* will be removed'):
+            publisher.set_components('pep', 'rst', 'odt')
+        self.assertTrue(isinstance(publisher.reader, readers.pep.Reader))
+        self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+        self.assertTrue(isinstance(publisher.writer, writers.odf_odt.Writer))
+        # but don't overwrite registered component instances
+        publisher = core.Publisher(reader, parser, writer)
+        with self.assertWarns(PendingDeprecationWarning):
+            publisher.set_components('standalone', 'xml', 'odt')
+        self.assertEqual(publisher.reader, reader)
+        self.assertEqual(publisher.parser, parser)
+        self.assertEqual(publisher.writer, writer)
+
+    def test_set_destination(self):
+        # Exit if `_destination` and `output` settings conflict.
+        publisher = core.Publisher()
+        publisher.get_settings(output='out_name', _destination='out_name')
+        # no conflict if both have same value:
+        publisher.set_destination()
+        # no conflict if both are overridden:
+        publisher.set_destination(destination_path='winning_dest')
+        # ... also sets _destination to 'winning_dest' -> conflict
+        with self.assertRaises(SystemExit):
+            publisher.set_destination()
+
+
+class ConvenienceFunctionTests(unittest.TestCase):
+    maxDiff = None
+
     settings = {'_disable_config': True,
                 'datestamp': False}
 
+    def test_publish_cmdline(self):
+        # the "*_name" arguments will be removed
+        with self.assertWarns(PendingDeprecationWarning):
+            core.publish_cmdline(writer_name='null',
+                                 argv=[(DATA_ROOT/'include.txt').as_posix()],
+                                 settings_overrides={'traceback': True})
+
     def test_input_error_handling(self):
         # core.publish_cmdline(argv=['nonexisting/path'])
         # exits with a short message, if `traceback` is False,
-
-        # pass IOErrors to calling application if `traceback` is True
+        # pass IOErrors to calling application if `traceback` is True:
         with self.assertRaises(IOError):
             core.publish_cmdline(argv=['nonexisting/path'],
                                  settings_overrides={'traceback': True})
@@ -79,22 +172,10 @@
     def test_output_error_handling(self):
         # pass IOErrors to calling application if `traceback` is True
         with self.assertRaises(docutils.io.OutputError):
-            core.publish_cmdline(argv=[os.path.join(DATA_ROOT, 'include.txt'),
+            core.publish_cmdline(argv=[(DATA_ROOT/'include.txt').as_posix(),
                                        'nonexisting/path'],
                                  settings_overrides={'traceback': True})
 
-    def test_set_destination(self):
-        # Exit if `_destination` and `output` settings conflict.
-        publisher = core.Publisher()
-        publisher.get_settings(output='out_name', _destination='out_name')
-        # no conflict if both have same value:
-        publisher.set_destination()
-        # no conflict if both are overridden:
-        publisher.set_destination(destination_path='winning_dest')
-        # ... also sets _destination to 'winning_dest' -> conflict
-        with self.assertRaises(SystemExit):
-            publisher.set_destination()
-
     def test_destination_output_conflict(self):
         # Exit if positional argument and --output option conflict.
         settings = {'output': 'out_name'}
@@ -126,8 +207,7 @@
         self.assertTrue(output.endswith('Grüße\n'))
 
     def test_publish_string_output_encoding(self):
-        settings = dict(self.settings)
-        settings['output_encoding'] = 'latin1'
+        settings = self.settings | {'output_encoding': 'latin1'}
         settings['output_encoding_error_handler'] = 'replace'
         source = 'Grüß → dich'
         expected = ('<document source="<string>">\n'
@@ -147,26 +227,37 @@
                                     'warning_stream': ''}
         with self.assertRaisesRegex(docutils.utils.SystemMessage,
                                     'The ODT writer returns `bytes` '):
-            core.publish_string('test', writer_name='odt',
+            core.publish_string('test', writer='odt',
                                 settings_overrides=settings)
 
+    def test_publish_string_deprecation_warning(self):
+        """The "*_name" arguments are deprecated."""
+        source = 'test → me'
+        with self.assertWarns(PendingDeprecationWarning):
+            output = core.publish_string(source, writer_name='xml')
+        # ... but should still set the corresponding component:
+        self.assertTrue(output.decode('utf-8').startswith(
+            '<?xml version="1.0" encoding="utf-8"?>'))
 
+
 class PublishDoctreeTestCase(unittest.TestCase, docutils.SettingsSpec):
 
     settings_default_overrides = {
         '_disable_config': True,
-        'warning_stream': docutils.io.NullOutput()}
+        'warning_stream': docutils.io.NullOutput(),
+        'output_encoding': 'unicode'}
 
     def test_publish_doctree(self):
         # Test `publish_doctree` and `publish_from_doctree`.
 
         # Produce the document tree.
-        doctree = core.publish_doctree(
-            source=test_document, reader_name='standalone',
-            parser_name='restructuredtext', settings_spec=self,
-            settings_overrides={'expose_internals':
-                                ['refnames', 'do_not_expose'],
-                                'report_level': 5})
+        with self.assertWarns(PendingDeprecationWarning):
+            doctree = core.publish_doctree(
+                source=test_document, reader='standalone',
+                parser_name='restructuredtext', settings_spec=self,
+                settings_overrides={'expose_internals':
+                                    ['refnames', 'do_not_expose'],
+                                    'report_level': 5})
         self.assertTrue(isinstance(doctree, nodes.document))
 
         # Confirm that transforms have been applied (in this case, the
@@ -182,7 +273,8 @@
         doctree.do_not_expose = 'test'
         # Write out the document:
         output = core.publish_from_doctree(
-            doctree, writer_name='pseudoxml',
+            doctree,
+            writer='pseudoxml',
             settings_spec=self,
             settings_overrides={'expose_internals':
                                 ['refnames', 'do_not_expose'],
@@ -192,8 +284,8 @@
 
         # Test publishing parts using document as the source.
         parts = core.publish_parts(
-            reader_name='doctree', source_class=docutils.io.DocTreeInput,
-            source=doctree, source_path='test', writer_name='html',
+            reader='doctree', source_class=docutils.io.DocTreeInput,
+            source=doctree, source_path='test', writer='html',
             settings_spec=self)
         self.assertTrue(isinstance(parts, dict))
 
@@ -203,8 +295,8 @@
         # Produce the document tree.
         doctree = core.publish_doctree(
             source=test_document,
-            reader_name='standalone',
-            parser_name='restructuredtext',
+            reader='standalone',
+            parser='restructuredtext',
             settings_spec=self)
         self.assertTrue(isinstance(doctree, nodes.document))
 
@@ -229,10 +321,12 @@
         self.assertTrue(isinstance(doctree_zombie, nodes.document))
 
         # Write out the document:
-        output = core.publish_from_doctree(doctree_zombie,
-                                           writer_name='pseudoxml',
-                                           settings_spec=self)
-        self.assertEqual(pseudoxml_output, output.decode())
+        with self.assertWarnsRegex(PendingDeprecationWarning,
+                                   'Argument "writer_name" will be removed '):
+            output = core.publish_from_doctree(doctree_zombie,
+                                               writer_name='pseudoxml',
+                                               settings_spec=self)
+        self.assertEqual(pseudoxml_output, output)
 
 
 if __name__ == '__main__':

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins
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.