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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9729
          http://sourceforge.net/p/docutils/code/9729
Author:   milde
Date:     2024-06-05 12:05:56 +0000 (Wed, 05 Jun 2024)
Log Message:
-----------
Doctree validation: Test and fix recursive validation.

Fixes [r9724].

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 10:29:22 UTC (rev 9728)
+++ trunk/docutils/docutils/nodes.py	2024-06-05 12:05:56 UTC (rev 9729)
@@ -398,7 +398,7 @@
     def lstrip(self, chars=None):
         return self.__class__(str.lstrip(self, chars))
 
-    def validate(self):
+    def validate(self, recursive=True):
         pass  # Text nodes have no attributes and no children.
 
 
@@ -1161,7 +1161,7 @@
 
         if recursive:
             for child in self:
-                child.validate()
+                child.validate(recursive=recursive)
 
 
 # ====================

Modified: trunk/docutils/test/test_nodes.py
===================================================================
--- trunk/docutils/test/test_nodes.py	2024-06-05 10:29:22 UTC (rev 9728)
+++ trunk/docutils/test/test_nodes.py	2024-06-05 12:05:56 UTC (rev 9729)
@@ -478,6 +478,16 @@
         node.append(nodes.emphasis('', 'emphasised text', ids='emphtext'))
         node.validate()
 
+    def test_validate_invalid_descendent(self):
+        paragraph = nodes.paragraph('', 'plain text')
+        tip = nodes.tip('', paragraph)
+        paragraph.append(nodes.strong('doll', id='missing-es'))
+        tip.validate(recursive=False)
+        with self.assertRaisesRegex(nodes.ValidationError,
+                                    'Element <strong id=.*> invalid:\n'
+                                    '  Attribute "id" not one of "ids", '):
+            tip.validate()
+
     def test_validate_attributes(self):
         # Convert to expected data-type, normalize values,
         # cf. AttributeTypeTests below for attribute validating function tests.

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.