|
From: <mi...@us...> - 2024-05-18 08:45:10
|
Revision: 9713
http://sourceforge.net/p/docutils/code/9713
Author: milde
Date: 2024-05-18 08:45:06 +0000 (Sat, 18 May 2024)
Log Message:
-----------
Doctree validation: small fixes.
Docstring for Element.validate().
Indent secondary message lines with 2 spaces.
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-05-18 08:44:56 UTC (rev 9712)
+++ trunk/docutils/docutils/nodes.py 2024-05-18 08:45:06 UTC (rev 9713)
@@ -1142,12 +1142,20 @@
raise ValueError('\n'.join(messages))
def validate(self):
+ """Validate element and its children.
+
+ Test conformance to the Docutils Document Model ("doctree").
+ Report violations as warning or raise ValueError if there is
+ no reporter attached to the root node.
+
+ Provisional (work in progress).
+ """
messages = []
try:
self.validate_attributes()
except ValueError as e:
messages.append(e.args[0]) # the message argument
- # TODO: check number of children
+ # test number of children
n_min, n_max = self.valid_len
if len(self.children) < n_min:
messages.append(f'Expects at least {n_min} children, '
@@ -1160,7 +1168,8 @@
messages.append(f'May not contain "{child.tagname}" elements.')
child.validate()
if messages:
- msg = f'Element <{self.tagname}> invalid:\n' + '\n'.join(messages)
+ msg = (f'Element <{self.tagname}> invalid:\n '
+ + '\n '.join(messages))
try:
self.document.reporter.warning(msg)
except AttributeError:
@@ -2053,6 +2062,8 @@
class citation(General, BackLinkable, Element, Labeled, Targetable):
valid_children = (label, Body) # (label, (%body.elements;)+)
valid_len = (2, None)
+ # TODO: DTD requires both label and content but rST allows empty citation
+ # (see test_rst/test_citations.py). Is this sensible?
# Graphical elements
Modified: trunk/docutils/test/test_nodes.py
===================================================================
--- trunk/docutils/test/test_nodes.py 2024-05-18 08:44:56 UTC (rev 9712)
+++ trunk/docutils/test/test_nodes.py 2024-05-18 08:45:06 UTC (rev 9713)
@@ -489,7 +489,7 @@
node = nodes.paragraph('', 'text', id='test-paragraph')
with self.assertRaisesRegex(ValueError,
'Element <paragraph> invalid:\n'
- 'Attribute "id" not one of "ids '):
+ ' Attribute "id" not one of "ids '):
node.validate()
def test_validate_wrong_attribute_value(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|