[Libosinfo] [PATCH osinfo-db 14/15] tests: Use lxml
Cole Robinson
crobinso at redhat.com
Mon Mar 25 14:32:18 UTC 2019
lxml is a popular XML parsing library that uses libxml2 behind
the scenes and exports an ElementTree API, among other things.
lxml is more python ecosystem friendly as its able to be installed
from pip, unlike python-libxml2, which can help with CI in some cases.
This lets us drop the explicit libxml2 dep, and also makes it easier
to get nicer error messages when XML schema validation fails
Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
tests/osinfo.py | 3 ++-
tests/test_schema.py | 10 +++++-----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/tests/osinfo.py b/tests/osinfo.py
index ad0eea2..3585f44 100644
--- a/tests/osinfo.py
+++ b/tests/osinfo.py
@@ -2,7 +2,8 @@
# See the COPYING file in the top-level directory.
import re
-import xml.etree.ElementTree as ET
+
+import lxml.etree as ET
def _cache_property(fn):
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 98f58ef..d8d6052 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -1,18 +1,18 @@
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
-import libxml2
+import lxml.etree as ET
import pytest
from . import util
SCHEMA = util.DataFiles.schema
-PARSER = libxml2.relaxNGNewParserCtxt(SCHEMA)
-VALID = PARSER.relaxNGParse().relaxNGNewValidCtxt()
+RELAXNG = ET.RelaxNG(ET.parse(SCHEMA))
@pytest.mark.parametrize("path", util.DataFiles.xmls())
def test_schema(path):
- doc = libxml2.parseFile(path)
- assert VALID.relaxNGValidateDoc(doc) == 0
+ if not RELAXNG.validate(ET.parse(path)):
+ # pylint: disable=no-member
+ raise AssertionError(str(RELAXNG.error_log.last_error))
--
2.21.0
More information about the Libosinfo
mailing list