diff options
Diffstat (limited to 'scripts/xml-parse-test.py')
-rwxr-xr-x | scripts/xml-parse-test.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/scripts/xml-parse-test.py b/scripts/xml-parse-test.py index d8a954d5..8e830d8d 100755 --- a/scripts/xml-parse-test.py +++ b/scripts/xml-parse-test.py @@ -2,7 +2,7 @@ import glob, rpki.up_down, rpki.left_right, xml.sax, lxml.etree, lxml.sax -def test(fileglob, schema, proto): +def test(fileglob, schema, proto, encoding): rng = lxml.etree.RelaxNG(lxml.etree.parse(schema)) files = glob.glob(fileglob) files.sort() @@ -12,10 +12,14 @@ def test(fileglob, schema, proto): et = lxml.etree.parse(f) rng.assertValid(et) lxml.sax.saxify(et, handler) - et = lxml.etree.fromstring(str(handler.result)) - print lxml.etree.tostring(et) - rng.assertValid(et) + et = handler.result.toXML() + print lxml.etree.tostring(et, pretty_print=True, encoding=encoding, xml_declaration=True) + try: + rng.assertValid(et) + except lxml.etree.DocumentInvalid: + print rng.error_log.last_error + raise -test("up-down-protocol-samples/*.xml", "up-down-medium-schema.rng", rpki.up_down) +test("up-down-protocol-samples/*.xml", "up-down-medium-schema.rng", rpki.up_down, encoding="utf-8") -test("left-right-protocol-samples/*.xml", "left-right-schema.rng", rpki.left_right) +test("left-right-protocol-samples/*.xml", "left-right-schema.rng", rpki.left_right, encoding="us-ascii") |