Author: ivan
Date: Tue Jun 23 16:05:56 2026
New Revision: 1935590
Log:
On 'xml-schema-validation-improvements' branch:
Use builtin XML parser to perform basic XML validation in tests when XML
schema validation is disabled.
XML parsing produces less verbose, but still useful error messages:
[[[
XML: mismatched tag: line 3, column 2
XML: mismatched tag: line 37, column 2
XML: not well-formed (invalid token): line 10, column 11
]]]
With the full XML schema validation error messages are as follows:
[[[
XML: Opening and ending tag mismatch: log line 2 and logentry, line 3, column
12 (<string>, line 3)
XML: Opening and ending tag mismatch: log line 2 and logentry, line 37, column
12 (<string>, line 37)
XML: PCDATA invalid Char value 8, line 10, column 12 (<string>, line 10)
]]]
* subversion/tests/cmdline/log_tests.py
* subversion/tests/cmdline/prop_tests.py
(log_with_merge_history_and_search, log_xml_with_merge_history,
xml_unsafe_author2): Update XFail condition.
* subversion/tests/cmdline/svntest/verify.py
(): Import xml.etree.ElementTree.
(validate_xml_schema): Parse XML with xml.etree.ElementTree if XML schema
validation is disabled.
Modified:
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/log_tests.py
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/prop_tests.py
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/svntest/verify.py
Modified:
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/log_tests.py
==============================================================================
---
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/log_tests.py
Tue Jun 23 15:42:18 2026 (r1935589)
+++
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/log_tests.py
Tue Jun 23 16:05:56 2026 (r1935590)
@@ -2778,7 +2778,7 @@ def log_on_deleted_deep(sbox):
'',
'-q', '-c', '1-2')
-@XFail(svntest.main.is_xml_schema_validation_enabled)
+@XFail()
@Issue(4711)
def log_with_merge_history_and_search(sbox):
"log --use-merge-history --search"
@@ -2805,8 +2805,7 @@ def log_with_merge_history_and_search(sb
svntest.verify.validate_xml_schema('log', output)
-@XFail(lambda: (svntest.main.is_xml_schema_validation_enabled()
- and svntest.main.is_ra_type_file()))
+@XFail(lambda: (svntest.main.is_ra_type_file()))
@Issue(4856)
def log_xml_with_merge_history(sbox):
"log --use-merge-history --xml"
Modified:
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/prop_tests.py
==============================================================================
---
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/prop_tests.py
Tue Jun 23 15:42:18 2026 (r1935589)
+++
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/prop_tests.py
Tue Jun 23 16:05:56 2026 (r1935590)
@@ -2641,8 +2641,7 @@ def xml_unsafe_author(sbox):
@Issue(4415)
@Issue(4919)
-@XFail(lambda: (svntest.main.is_xml_schema_validation_enabled()
- and not svntest.main.is_ra_type_dav()))
+@XFail(lambda: (not svntest.main.is_ra_type_dav()))
def xml_unsafe_author2(sbox):
"svn:author with XML unsafe chars 2"
Modified:
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/svntest/verify.py
==============================================================================
---
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/svntest/verify.py
Tue Jun 23 15:42:18 2026 (r1935589)
+++
subversion/branches/xml-schema-validation-improvements/subversion/tests/cmdline/svntest/verify.py
Tue Jun 23 16:05:56 2026 (r1935590)
@@ -32,6 +32,8 @@ import itertools
from io import BytesIO
from typing import Iterable
+import xml.etree.ElementTree
+
import svntest
logger = logging.getLogger()
@@ -1053,23 +1055,30 @@ __schema_dir = os.path.join(
os.path.abspath(__file__))))),
"svn", "schema")
def validate_xml_schema(name: str, lines: Iterable[str]) -> None:
- if not svntest.main.is_xml_schema_validation_enabled():
- logger.debug("XML schema validation is disabled.")
- return
-
- schema_name = name + ".rnc"
- try:
- from lxml import etree #type:ignore
- schema_file = os.path.join(__schema_dir, schema_name)
- schema = etree.RelaxNG(file=schema_file)
- source = ''.join(lines)
- document = etree.parse(BytesIO(source.encode("utf-8")))
- if not schema.validate(document):
- raise SVNXMLSchemaValidationError(schema.error_log)
- except ImportError:
- logger.error("XML: Module lxml.etree not found")
- raise svntest.Failure
- except Exception as ex:
- logger.error("XML: " + str(ex))
- logger.warning("XML:\n" + "\n".join(repr(line) for line in lines))
- raise
+ source = ''.join(lines)
+
+ if svntest.main.is_xml_schema_validation_enabled():
+ # Use full XML schema validation (requires lxml and rnc2rng packages)
+ schema_name = name + ".rnc"
+ try:
+ from lxml import etree #type:ignore
+ schema_file = os.path.join(__schema_dir, schema_name)
+ schema = etree.RelaxNG(file=schema_file)
+ document = etree.parse(BytesIO(source.encode("utf-8")))
+ if not schema.validate(document):
+ raise SVNXMLSchemaValidationError(schema.error_log)
+ except ImportError:
+ logger.error("XML: Module lxml.etree not found")
+ raise svntest.Failure
+ except Exception as ex:
+ logger.error("XML: " + str(ex))
+ logger.warning("XML:\n" + "\n".join(repr(line) for line in lines))
+ raise
+ else:
+ # Use simple XML validation: just check that it parses.
+ try:
+ xml.etree.ElementTree.fromstring(source)
+ except Exception as ex:
+ logger.error("XML: " + str(ex))
+ logger.warning("XML:\n" + "\n".join(repr(line) for line in lines))
+ raise