Skip to content

Commit

Permalink
Call XMLSchema().assertValid() rather than XMLSchema().validate()
Browse files Browse the repository at this point in the history
which raises a more meaningful exception
  • Loading branch information
RKrahl committed Mar 20, 2024
1 parent 0f2ee5e commit 3a4adb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/icat/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ def __init__(self, client, metadata, investigation):
raise InvalidIngestFileError(e)
with self.get_xsd(ingest_data).open("rb") as f:
schema = etree.XMLSchema(etree.parse(f))
if not schema.validate(ingest_data):
raise InvalidIngestFileError("validation failed")
try:
schema.assertValid(ingest_data)
except etree.DocumentInvalid as exc:
raise InvalidIngestFileError("DocumentInvalid: %s" % exc)
self.add_environment(client, ingest_data)
with self.get_xslt(ingest_data).open("rb") as f:
xslt = etree.XSLT(etree.parse(f))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_06_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_ingest_schema(client, investigation, schemadir, case):
reader = IngestReader(client, case.metadata, investigation)
with get_icatdata_schema().open("rb") as f:
schema = etree.XMLSchema(etree.parse(f))
assert schema.validate(reader.infile)
schema.assertValid(reader.infile)

@pytest.mark.parametrize("case", [
pytest.param(c, id=c.metadata.name, marks=c.marks) for c in cases
Expand Down Expand Up @@ -735,7 +735,7 @@ def test_ingest_env(monkeypatch, client, investigation, schemadir, case):
reader = IngestReader(client, case.metadata, investigation)
with get_icatdata_schema().open("rb") as f:
schema = etree.XMLSchema(etree.parse(f))
assert schema.validate(reader.infile)
schema.assertValid(reader.infile)
version_elem = reader.infile.xpath("/icatdata/head/apiversion")
assert version_elem
assert version_elem[0].text == str(client.apiversion)

0 comments on commit 3a4adb1

Please sign in to comment.