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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9731
          http://sourceforge.net/p/docutils/code/9731
Author:   milde
Date:     2024-06-05 15:54:16 +0000 (Wed, 05 Jun 2024)
Log Message:
-----------
Doctree validation: fix check of `authors` content.

The `authors` element has a complex content model that cannot be
represented with the data-structure used in `Element.content_model`:

    (author, organization?, address?, contact?)+

Use specific method in `nodes.authors` to repeatedly test a
simplified content model description until all children are handled.

Modified Paths:
--------------
    trunk/docutils/docutils/nodes.py
    trunk/docutils/test/test_nodes.py

Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py	2024-06-05 15:54:07 UTC (rev 9730)
+++ trunk/docutils/docutils/nodes.py	2024-06-05 15:54:16 UTC (rev 9731)
@@ -1901,7 +1901,17 @@
                      (address, '?'),
                      (contact, '?'))
 
+    def validate_content(self):
+        """Repeatedly test for children matching the content model.
 
+        Provisional.
+        """
+        relics = super().validate_content()
+        while relics:
+            relics = super().validate_content(elements=relics)
+        return relics
+
+
 # Body Elements
 # =============
 #

Modified: trunk/docutils/test/test_nodes.py
===================================================================
--- trunk/docutils/test/test_nodes.py	2024-06-05 15:54:07 UTC (rev 9730)
+++ trunk/docutils/test/test_nodes.py	2024-06-05 15:54:16 UTC (rev 9731)
@@ -747,7 +747,14 @@
             authors.validate_content()
         authors.extend([nodes.author(), nodes.address(), nodes.contact()])
         self.assertEqual(authors.validate_content(), [])
-        # TODO: check content model again, with next set of elements
+        authors.append(nodes.hint())
+        with self.assertRaisesRegex(nodes.ValidationError,
+                                    ' child of type <author>, not <hint>.'):
+            authors.validate_content()
+        authors.extend([nodes.author(), nodes.tip(), nodes.contact()])
+        with self.assertRaisesRegex(nodes.ValidationError,
+                                    ' child of type <author>, not <hint>.'):
+            authors.validate_content()
 
     def test_validate_content_subtitle(self):
         """<subtitle> must follow a <title>.

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.