Skip to content

Commit 3a4adb1

Browse files
committed
Call XMLSchema().assertValid() rather than XMLSchema().validate()
which raises a more meaningful exception
1 parent 0f2ee5e commit 3a4adb1

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/icat/ingest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ def __init__(self, client, metadata, investigation):
112112
raise InvalidIngestFileError(e)
113113
with self.get_xsd(ingest_data).open("rb") as f:
114114
schema = etree.XMLSchema(etree.parse(f))
115-
if not schema.validate(ingest_data):
116-
raise InvalidIngestFileError("validation failed")
115+
try:
116+
schema.assertValid(ingest_data)
117+
except etree.DocumentInvalid as exc:
118+
raise InvalidIngestFileError("DocumentInvalid: %s" % exc)
117119
self.add_environment(client, ingest_data)
118120
with self.get_xslt(ingest_data).open("rb") as f:
119121
xslt = etree.XSLT(etree.parse(f))

tests/test_06_ingest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def test_ingest_schema(client, investigation, schemadir, case):
357357
reader = IngestReader(client, case.metadata, investigation)
358358
with get_icatdata_schema().open("rb") as f:
359359
schema = etree.XMLSchema(etree.parse(f))
360-
assert schema.validate(reader.infile)
360+
schema.assertValid(reader.infile)
361361

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

0 commit comments

Comments
 (0)