Skip to content

Commit deca38f

Browse files
authored
Merge pull request #236 from khaeru/ci/2025-w29
Adjust ECB data expectations in 2 tests
2 parents f042e75 + 3aeb913 commit deca38f

File tree

7 files changed

+21
-6
lines changed

7 files changed

+21
-6
lines changed

doc/api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ SDMX-ML
7171

7272
.. automodule:: sdmx.format.xml
7373
:members:
74+
:exclude-members: validate_xml
75+
76+
.. automodule:: sdmx.format.xml.common
77+
:members:
78+
:exclude-members: install_schemas, validate_xml
7479

7580
``message``: SDMX messages
7681
==========================

doc/whatsnew.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ What's new?
66
Next release
77
============
88

9+
- :func:`.install_schemas` and :func:`.construct_schema` fetch, store, and use a local copy of :file:`xhtml1-strict.dsd` (:pull:`236`, :issue:`235`).
10+
This enables use of :func:`.validate_xml`
11+
with lxml version 6.0.0 (`released 2025-06-26 <https://lxml.de/6.0/changes-6.0.0.html>`__)
12+
for SDMX-ML messages containing XHTML values.
913
- Correct a broken link to :ref:`im` in the README (:pull:`233`; thanks :gh-user:`econometricsfanboy` for :issue:`232`).
1014

1115
.. _2.22.0:

sdmx/format/xml/common.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ def construct_schema(
189189
if schema_etree is None:
190190
raise FileNotFoundError(f"Could not find XSD files in {schema_dir}")
191191

192-
# Modify the schema by inserting an <xs:import > reference to the XHTML schema URL
192+
# Modify the schema by inserting an <xs:import > reference to the XHTML schema file
193193
elem = etree.Element(
194194
"{http://www.w3.org/2001/XMLSchema}import",
195195
namespace="http://www.w3.org/1999/xhtml",
196-
schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd",
196+
schemaLocation="xhtml1-strict.xsd",
197197
)
198198
schema_etree.getroot().insert(0, elem)
199199

@@ -269,6 +269,10 @@ def _extracted_zipball(version: Version, force: bool = False) -> Path:
269269
# Unpack the entire archive
270270
zf.extractall(target.parent)
271271

272+
# Fetch a copy of the XHTML1 XSD, which is missing from the SDMX bundle
273+
resp = requests.get(url="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd")
274+
result.joinpath("schemas", "xhtml1-strict.xsd").write_bytes(resp.content)
275+
272276
return result
273277

274278

sdmx/testing/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def mock_gh_api():
263263
mock = responses.RequestsMock(assert_all_requests_are_fired=False)
264264
mock.add_passthru(re.compile(rf"{base}/zipball/\w+"))
265265
mock.add_passthru(re.compile(r"https://codeload.github.com/\w+"))
266+
mock.add_passthru(re.compile(r"http://www.w3.org/\w+"))
266267

267268
for v in "2.1", "3.0", "3.0.0":
268269
mock.get(

sdmx/tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_preview_data(self) -> None:
204204

205205
# A filter can be provided, resulting in fewer keys
206206
keys = ECB.preview_data("EXR", {"CURRENCY": "CAD+CHF+CNY"})
207-
N = 30
207+
N = 33
208208
assert N >= len(keys)
209209

210210
# Result can be converted to pandas object

sdmx/tests/test_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_doc_usage_data():
233233

234234
series_keys = list(data.series)
235235

236-
assert len(series_keys) == 16
236+
assert len(series_keys) == 22
237237

238238
series_keys[5]
239239

sdmx/tests/writer/test_writer_xml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def test_ErrorMessage(errormessage):
314314
sdmx.to_xml(errormessage)
315315

316316

317-
@pytest.mark.usefixtures("tmp_path", "specimen")
317+
@pytest.mark.usefixtures("tmp_path", "installed_schemas", "specimen")
318318
class RoundTripTests(ABC):
319319
"""Abstract base class for tests that read-write-read SDMX-ML."""
320320

@@ -332,6 +332,7 @@ def rw_test(
332332
# Unpack fixture using the request_fixture
333333
tmp_path = request.getfixturevalue("tmp_path")
334334
specimen = request.getfixturevalue("specimen")
335+
schemas_dir = request.getfixturevalue("installed_schemas")
335336

336337
if structure_id:
337338
# Read {D,Metad}ataStructure from file
@@ -350,7 +351,7 @@ def rw_test(
350351
data = io.BytesIO(sdmx.to_xml(msg0, pretty_print=True))
351352

352353
# Validate using XSD
353-
assert not validate or validate_xml(data), "Invalid SDMX-ML"
354+
assert not validate or validate_xml(data, schemas_dir), "Invalid SDMX-ML"
354355

355356
# Contents can be read again
356357
try:

0 commit comments

Comments
 (0)