diff --git a/sdmx/tests/format/test_format_xml.py b/sdmx/tests/format/test_format_xml.py
index 38ff6a6ba..9ec8d77af 100644
--- a/sdmx/tests/format/test_format_xml.py
+++ b/sdmx/tests/format/test_format_xml.py
@@ -135,18 +135,19 @@ def test_validate_xml_invalid_doc(tmp_path, installed_schemas):
msg_path.write_bytes(sdmx.to_xml(msg))
- # Expect validation to fail
- assert not sdmx.validate_xml(msg_path, schema_dir=installed_schemas.joinpath("2.1"))
+ assert sdmx.validate_xml(msg_path, schema_dir=installed_schemas.joinpath("2.1"))
def test_validate_xml_invalid_message_type(installed_schemas):
"""Ensure that an invalid document fails validation."""
# Create a mangled structure message with its outmost tag changed to be invalid
msg = StructureMessage()
- invalid_msg = re.sub(b"mes:Structure([ >])", rb"mes:FooBar\1", sdmx.to_xml(msg))
+ invalid_msg = io.BytesIO(
+ re.sub(b"mes:Structure([ >])", rb"mes:FooBar\1", sdmx.to_xml(msg))
+ )
with pytest.raises(NotImplementedError, match="Validate non-SDMX root.*FooBar>"):
- sdmx.validate_xml(io.BytesIO(invalid_msg), installed_schemas)
+ sdmx.validate_xml(invalid_msg, installed_schemas)
@pytest.mark.parametrize("version", ["1", 1, None])
@@ -157,6 +158,23 @@ def test_validate_xml_invalid_version(version):
sdmx.validate_xml("samples/common/common.xml", version=version)
+def test_validate_xml_max_errors(caplog, installed_schemas):
+ """Test :py:`validate_xml(..., max_errors=...)`."""
+ msg = StructureMessage()
+ invalid_msg = io.BytesIO(
+ re.sub(b"<(mes:Structures)/>", rb"<\1>\1>", sdmx.to_xml(msg))
+ )
+
+ # Without max_errors, 2 messages are logged
+ sdmx.validate_xml(invalid_msg, installed_schemas)
+ assert 2 == len(caplog.messages)
+ caplog.clear()
+
+ # With the argument, only 1 message is logged
+ sdmx.validate_xml(invalid_msg, installed_schemas, max_errors=1)
+ assert 1 == len(caplog.messages)
+
+
def test_validate_xml_no_schemas(tmp_path, specimen):
"""Check that supplying an invalid schema path will raise ``ValueError``."""
with specimen("IPI-2010-A21-structure.xml", opened=False) as msg_path:
diff --git a/sdmx/tests/test_source.py b/sdmx/tests/test_source.py
index db393c99f..4a724ecf4 100644
--- a/sdmx/tests/test_source.py
+++ b/sdmx/tests/test_source.py
@@ -17,7 +17,7 @@ def test_get_source(caplog):
def test_list_sources():
source_ids = list_sources()
# Correct number of sources, excluding those created for testing
- assert 29 == len(set(source_ids) - {"MOCK", "TEST"})
+ assert 34 == len(set(source_ids) - {"MOCK", "TEST"})
# Listed alphabetically
assert "ABS" == source_ids[0]