14
0

- Add the upstream etree_import_in_tests.patch to fix

gh#sissaschool/xmlschema#210.

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-xmlschema?expand=0&rev=22
This commit is contained in:
2020-11-10 07:14:36 +00:00
committed by Git OBS Bridge
parent 89a32e9a2c
commit 80adc55baf
3 changed files with 661 additions and 10 deletions

648
etree_import_in_tests.patch Normal file
View File

@@ -0,0 +1,648 @@
diff --git a/tests/test_documents.py b/tests/test_documents.py
index 6c616fe..bd5d8c5 100644
--- a/tests/test_documents.py
+++ b/tests/test_documents.py
@@ -16,7 +16,6 @@ import io
import pathlib
import tempfile
from decimal import Decimal
-from xml.etree import ElementTree
try:
import lxml.etree as lxml_etree
@@ -27,7 +26,7 @@ from xmlschema import XMLSchema10, XMLSchema11, XmlDocument, \
XMLResourceError, XMLSchemaValidationError, XMLSchemaDecodeError, \
to_json, from_json
-from xmlschema.etree import is_etree_element, is_etree_document
+from xmlschema.etree import ElementTree, is_etree_element, is_etree_document
from xmlschema.namespaces import XSD_NAMESPACE, XSI_NAMESPACE
from xmlschema.resources import XMLResource
from xmlschema.documents import get_context
diff --git a/tests/test_etree.py b/tests/test_etree.py
index d16c793..96aba4b 100644
--- a/tests/test_etree.py
+++ b/tests/test_etree.py
@@ -11,10 +11,11 @@
import unittest
import os
import platform
-from xml.etree import ElementTree
import lxml.etree
-from xmlschema import etree
+from xmlschema.etree import ElementTree, PyElementTree, ParseError, \
+ SafeXMLParser, etree_tostring, etree_getpath, etree_iter_location_hints, \
+ etree_iterpath, etree_elements_assert_equal, prune_etree
TEST_CASES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_cases/')
@@ -25,176 +26,173 @@ def casepath(relative_path):
class TestElementTree(unittest.TestCase):
- def test_imported_element_tree(self):
- self.assertIs(ElementTree, etree.ElementTree)
-
def test_element_string_serialization(self):
- self.assertRaises(TypeError, etree.etree_tostring, '<element/>')
+ self.assertRaises(TypeError, etree_tostring, '<element/>')
elem = ElementTree.Element('element')
- self.assertEqual(etree.etree_tostring(elem), '<element />')
- self.assertEqual(etree.etree_tostring(elem, xml_declaration=True), '<element />')
+ self.assertEqual(etree_tostring(elem), '<element />')
+ self.assertEqual(etree_tostring(elem, xml_declaration=True), '<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='us-ascii'), b'<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='us-ascii', indent=' '),
+ self.assertEqual(etree_tostring(elem, encoding='us-ascii'), b'<element />')
+ self.assertEqual(etree_tostring(elem, encoding='us-ascii', indent=' '),
b' <element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='us-ascii', xml_declaration=True),
+ self.assertEqual(etree_tostring(elem, encoding='us-ascii', xml_declaration=True),
b'<?xml version="1.0" encoding="us-ascii"?>\n<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='ascii'),
+ self.assertEqual(etree_tostring(elem, encoding='ascii'),
b"<?xml version='1.0' encoding='ascii'?>\n<element />")
- self.assertEqual(etree.etree_tostring(elem, encoding='ascii', xml_declaration=False),
+ self.assertEqual(etree_tostring(elem, encoding='ascii', xml_declaration=False),
b'<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='utf-8'), b'<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='utf-8', xml_declaration=True),
+ self.assertEqual(etree_tostring(elem, encoding='utf-8'), b'<element />')
+ self.assertEqual(etree_tostring(elem, encoding='utf-8', xml_declaration=True),
b'<?xml version="1.0" encoding="utf-8"?>\n<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='iso-8859-1'),
+ self.assertEqual(etree_tostring(elem, encoding='iso-8859-1'),
b"<?xml version='1.0' encoding='iso-8859-1'?>\n<element />")
- self.assertEqual(etree.etree_tostring(elem, encoding='iso-8859-1', xml_declaration=False),
+ self.assertEqual(etree_tostring(elem, encoding='iso-8859-1', xml_declaration=False),
b"<element />")
- self.assertEqual(etree.etree_tostring(elem, method='html'), '<element></element>')
- self.assertEqual(etree.etree_tostring(elem, method='text'), '')
+ self.assertEqual(etree_tostring(elem, method='html'), '<element></element>')
+ self.assertEqual(etree_tostring(elem, method='text'), '')
- root = etree.ElementTree.XML('<root>\n'
- ' text1\n'
- ' <elem>text2</elem>\n'
- '</root>')
- self.assertEqual(etree.etree_tostring(root, method='text'), '\n text1\n text2')
+ root = ElementTree.XML('<root>\n'
+ ' text1\n'
+ ' <elem>text2</elem>\n'
+ '</root>')
+ self.assertEqual(etree_tostring(root, method='text'), '\n text1\n text2')
def test_py_element_string_serialization(self):
- elem = etree.PyElementTree.Element('element')
- self.assertEqual(etree.etree_tostring(elem), '<element />')
- self.assertEqual(etree.etree_tostring(elem, xml_declaration=True), '<element />')
+ elem = PyElementTree.Element('element')
+ self.assertEqual(etree_tostring(elem), '<element />')
+ self.assertEqual(etree_tostring(elem, xml_declaration=True), '<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='us-ascii'), b'<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='us-ascii', xml_declaration=True),
+ self.assertEqual(etree_tostring(elem, encoding='us-ascii'), b'<element />')
+ self.assertEqual(etree_tostring(elem, encoding='us-ascii', xml_declaration=True),
b'<?xml version="1.0" encoding="us-ascii"?>\n<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='ascii'),
+ self.assertEqual(etree_tostring(elem, encoding='ascii'),
b"<?xml version='1.0' encoding='ascii'?>\n<element />")
- self.assertEqual(etree.etree_tostring(elem, encoding='ascii', xml_declaration=False),
+ self.assertEqual(etree_tostring(elem, encoding='ascii', xml_declaration=False),
b'<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='utf-8'), b'<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='utf-8', xml_declaration=True),
+ self.assertEqual(etree_tostring(elem, encoding='utf-8'), b'<element />')
+ self.assertEqual(etree_tostring(elem, encoding='utf-8', xml_declaration=True),
b'<?xml version="1.0" encoding="utf-8"?>\n<element />')
- self.assertEqual(etree.etree_tostring(elem, encoding='iso-8859-1'),
+ self.assertEqual(etree_tostring(elem, encoding='iso-8859-1'),
b"<?xml version='1.0' encoding='iso-8859-1'?>\n<element />")
- self.assertEqual(etree.etree_tostring(elem, encoding='iso-8859-1', xml_declaration=False),
+ self.assertEqual(etree_tostring(elem, encoding='iso-8859-1', xml_declaration=False),
b"<element />")
- self.assertEqual(etree.etree_tostring(elem, method='html'), '<element></element>')
- self.assertEqual(etree.etree_tostring(elem, method='text'), '')
+ self.assertEqual(etree_tostring(elem, method='html'), '<element></element>')
+ self.assertEqual(etree_tostring(elem, method='text'), '')
- root = etree.PyElementTree.XML('<root>\n'
- ' text1\n'
- ' <elem>text2</elem>\n'
- '</root>')
- self.assertEqual(etree.etree_tostring(root, method='text'), '\n text1\n text2')
+ root = PyElementTree.XML('<root>\n'
+ ' text1\n'
+ ' <elem>text2</elem>\n'
+ '</root>')
+ self.assertEqual(etree_tostring(root, method='text'), '\n text1\n text2')
def test_lxml_element_string_serialization(self):
elem = lxml.etree.Element('element')
- self.assertEqual(etree.etree_tostring(elem), '<element/>')
- self.assertEqual(etree.etree_tostring(elem, xml_declaration=True), '<element/>')
+ self.assertEqual(etree_tostring(elem), '<element/>')
+ self.assertEqual(etree_tostring(elem, xml_declaration=True), '<element/>')
- self.assertEqual(etree.etree_tostring(elem, encoding='us-ascii'), b'<element/>')
- self.assertEqual(etree.etree_tostring(elem, encoding='us-ascii', xml_declaration=True),
+ self.assertEqual(etree_tostring(elem, encoding='us-ascii'), b'<element/>')
+ self.assertEqual(etree_tostring(elem, encoding='us-ascii', xml_declaration=True),
b'<?xml version="1.0" encoding="us-ascii"?>\n<element/>')
- self.assertEqual(etree.etree_tostring(elem, encoding='ascii'), b'<element/>')
- self.assertEqual(etree.etree_tostring(elem, encoding='ascii', xml_declaration=True),
+ self.assertEqual(etree_tostring(elem, encoding='ascii'), b'<element/>')
+ self.assertEqual(etree_tostring(elem, encoding='ascii', xml_declaration=True),
b'<?xml version="1.0" encoding="ascii"?>\n<element/>')
- self.assertEqual(etree.etree_tostring(elem, encoding='utf-8'), b'<element/>')
- self.assertEqual(etree.etree_tostring(elem, encoding='utf-8', xml_declaration=True),
+ self.assertEqual(etree_tostring(elem, encoding='utf-8'), b'<element/>')
+ self.assertEqual(etree_tostring(elem, encoding='utf-8', xml_declaration=True),
b'<?xml version="1.0" encoding="utf-8"?>\n<element/>')
- self.assertEqual(etree.etree_tostring(elem, encoding='iso-8859-1'),
+ self.assertEqual(etree_tostring(elem, encoding='iso-8859-1'),
b"<?xml version='1.0' encoding='iso-8859-1'?>\n<element/>")
- self.assertEqual(etree.etree_tostring(elem, encoding='iso-8859-1', xml_declaration=False),
+ self.assertEqual(etree_tostring(elem, encoding='iso-8859-1', xml_declaration=False),
b"<element/>")
- self.assertEqual(etree.etree_tostring(elem, method='html'), '<element></element>')
- self.assertEqual(etree.etree_tostring(elem, method='text'), '')
+ self.assertEqual(etree_tostring(elem, method='html'), '<element></element>')
+ self.assertEqual(etree_tostring(elem, method='text'), '')
root = lxml.etree.XML('<root>\n'
' text1\n'
' <elem>text2</elem>\n'
'</root>')
- self.assertEqual(etree.etree_tostring(root, method='text'), '\n text1\n text2')
+ self.assertEqual(etree_tostring(root, method='text'), '\n text1\n text2')
def test_defuse_xml_entities(self):
xml_file = casepath('resources/with_entity.xml')
- elem = etree.ElementTree.parse(xml_file).getroot()
+ elem = ElementTree.parse(xml_file).getroot()
self.assertEqual(elem.text, 'abc')
- parser = etree.SafeXMLParser(target=etree.PyElementTree.TreeBuilder())
- with self.assertRaises(etree.PyElementTree.ParseError) as ctx:
- etree.ElementTree.parse(xml_file, parser=parser)
+ parser = SafeXMLParser(target=PyElementTree.TreeBuilder())
+ with self.assertRaises(PyElementTree.ParseError) as ctx:
+ ElementTree.parse(xml_file, parser=parser)
self.assertEqual("Entities are forbidden (entity_name='e')", str(ctx.exception))
def test_defuse_xml_external_entities(self):
xml_file = casepath('resources/external_entity.xml')
- with self.assertRaises(etree.ParseError) as ctx:
- etree.ElementTree.parse(xml_file)
+ with self.assertRaises(ParseError) as ctx:
+ ElementTree.parse(xml_file)
self.assertIn("undefined entity &ee", str(ctx.exception))
- parser = etree.SafeXMLParser(target=etree.PyElementTree.TreeBuilder())
- with self.assertRaises(etree.PyElementTree.ParseError) as ctx:
- etree.ElementTree.parse(xml_file, parser=parser)
+ parser = SafeXMLParser(target=PyElementTree.TreeBuilder())
+ with self.assertRaises(PyElementTree.ParseError) as ctx:
+ ElementTree.parse(xml_file, parser=parser)
self.assertEqual("Entities are forbidden (entity_name='ee')", str(ctx.exception))
def test_defuse_xml_unused_external_entities(self):
xml_file = casepath('resources/unused_external_entity.xml')
- elem = etree.ElementTree.parse(xml_file).getroot()
+ elem = ElementTree.parse(xml_file).getroot()
self.assertEqual(elem.text, 'abc')
- parser = etree.SafeXMLParser(target=etree.PyElementTree.TreeBuilder())
- with self.assertRaises(etree.PyElementTree.ParseError) as ctx:
- etree.ElementTree.parse(xml_file, parser=parser)
+ parser = SafeXMLParser(target=PyElementTree.TreeBuilder())
+ with self.assertRaises(PyElementTree.ParseError) as ctx:
+ ElementTree.parse(xml_file, parser=parser)
self.assertEqual("Entities are forbidden (entity_name='ee')", str(ctx.exception))
def test_defuse_xml_unparsed_entities(self):
xml_file = casepath('resources/unparsed_entity.xml')
- parser = etree.SafeXMLParser(target=etree.PyElementTree.TreeBuilder())
- with self.assertRaises(etree.PyElementTree.ParseError) as ctx:
- etree.ElementTree.parse(xml_file, parser=parser)
+ parser = SafeXMLParser(target=PyElementTree.TreeBuilder())
+ with self.assertRaises(PyElementTree.ParseError) as ctx:
+ ElementTree.parse(xml_file, parser=parser)
self.assertEqual("Unparsed entities are forbidden (entity_name='logo_file')",
str(ctx.exception))
def test_defuse_xml_unused_unparsed_entities(self):
xml_file = casepath('resources/unused_unparsed_entity.xml')
- elem = etree.ElementTree.parse(xml_file).getroot()
+ elem = ElementTree.parse(xml_file).getroot()
self.assertIsNone(elem.text)
- parser = etree.SafeXMLParser(target=etree.PyElementTree.TreeBuilder())
- with self.assertRaises(etree.PyElementTree.ParseError) as ctx:
- etree.ElementTree.parse(xml_file, parser=parser)
+ parser = SafeXMLParser(target=PyElementTree.TreeBuilder())
+ with self.assertRaises(PyElementTree.ParseError) as ctx:
+ ElementTree.parse(xml_file, parser=parser)
self.assertEqual("Unparsed entities are forbidden (entity_name='logo_file')",
str(ctx.exception))
def test_etree_iterpath(self):
root = ElementTree.XML('<a><b1><c1/><c2/></b1><b2/><b3><c3/></b3></a>')
- items = list(etree.etree_iterpath(root))
+ items = list(etree_iterpath(root))
self.assertListEqual(items, [
(root, '.'), (root[0], './b1'), (root[0][0], './b1/c1'),
(root[0][1], './b1/c2'), (root[1], './b2'), (root[2], './b3'),
(root[2][0], './b3/c3')
])
- self.assertListEqual(items, list(etree.etree_iterpath(root, tag='*')))
- self.assertListEqual(items, list(etree.etree_iterpath(root, path='')))
- self.assertListEqual(items, list(etree.etree_iterpath(root, path=None)))
+ self.assertListEqual(items, list(etree_iterpath(root, tag='*')))
+ self.assertListEqual(items, list(etree_iterpath(root, path='')))
+ self.assertListEqual(items, list(etree_iterpath(root, path=None)))
- self.assertListEqual(list(etree.etree_iterpath(root, path='/')), [
+ self.assertListEqual(list(etree_iterpath(root, path='/')), [
(root, '/'), (root[0], '/b1'), (root[0][0], '/b1/c1'),
(root[0][1], '/b1/c2'), (root[1], '/b2'), (root[2], '/b3'),
(root[2][0], '/b3/c3')
@@ -203,104 +201,104 @@ class TestElementTree(unittest.TestCase):
def test_etree_getpath(self):
root = ElementTree.XML('<a><b1><c1/><c2/></b1><b2/><b3><c3/></b3></a>')
- self.assertEqual(etree.etree_getpath(root, root), '.')
- self.assertEqual(etree.etree_getpath(root[0], root), './b1')
- self.assertEqual(etree.etree_getpath(root[2][0], root), './b3/c3')
- self.assertEqual(etree.etree_getpath(root[0], root, parent_path=True), '.')
- self.assertEqual(etree.etree_getpath(root[2][0], root, parent_path=True), './b3')
+ self.assertEqual(etree_getpath(root, root), '.')
+ self.assertEqual(etree_getpath(root[0], root), './b1')
+ self.assertEqual(etree_getpath(root[2][0], root), './b3/c3')
+ self.assertEqual(etree_getpath(root[0], root, parent_path=True), '.')
+ self.assertEqual(etree_getpath(root[2][0], root, parent_path=True), './b3')
- self.assertIsNone(etree.etree_getpath(root, root[0]))
- self.assertIsNone(etree.etree_getpath(root[0], root[1]))
- self.assertIsNone(etree.etree_getpath(root, root, parent_path=True))
+ self.assertIsNone(etree_getpath(root, root[0]))
+ self.assertIsNone(etree_getpath(root[0], root[1]))
+ self.assertIsNone(etree_getpath(root, root, parent_path=True))
def test_etree_elements_assert_equal(self):
e1 = ElementTree.XML('<a><b1>text<c1 a="1"/></b1>\n<b2/><b3/></a>\n')
e2 = ElementTree.XML('<a><b1>text<c1 a="1"/></b1>\n<b2/><b3/></a>\n')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e1))
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2))
+ self.assertIsNone(etree_elements_assert_equal(e1, e1))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2))
e2 = lxml.etree.XML('<a><b1>text<c1 a="1"/></b1>\n<b2/><b3/></a>\n')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2))
e2 = ElementTree.XML('<a><b1>text<c1 a="1"/></b1>\n<b2/><b3/><b4/></a>\n')
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2)
+ etree_elements_assert_equal(e1, e2)
self.assertIn("has lesser children than <Element 'a'", str(ctx.exception))
e2 = ElementTree.XML('<a><b1>text <c1 a="1"/></b1>\n<b2/><b3/></a>\n')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2, strict=False))
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2)
+ etree_elements_assert_equal(e1, e2)
self.assertIn("texts differ: 'text' != 'text '", str(ctx.exception))
e2 = ElementTree.XML('<a><b1>text<c1 a="1"/></b1>\n<b2>text</b2><b3/></a>\n')
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2, strict=False)
+ etree_elements_assert_equal(e1, e2, strict=False)
self.assertIn("texts differ: None != 'text'", str(ctx.exception))
e2 = ElementTree.XML('<a><b1>text<c1 a="1"/></b1>\n<b2/><b3/></a>')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2))
e2 = ElementTree.XML('<a><b1>text<c1 a="1"/></b1><b2/><b3/></a>\n')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2, strict=False))
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2)
+ etree_elements_assert_equal(e1, e2)
self.assertIn(r"tails differ: '\n' != None", str(ctx.exception))
e2 = ElementTree.XML('<a><b1>text<c1 a="1 "/></b1>\n<b2/><b3/></a>\n')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2, strict=False))
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2)
+ etree_elements_assert_equal(e1, e2)
self.assertIn("attributes differ: {'a': '1'} != {'a': '1 '}", str(ctx.exception))
e2 = ElementTree.XML('<a><b1>text<c1 a="2 "/></b1>\n<b2/><b3/></a>\n')
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2, strict=False)
+ etree_elements_assert_equal(e1, e2, strict=False)
self.assertIn("attribute 'a' values differ: '1' != '2'", str(ctx.exception))
e2 = ElementTree.XML('<a><!--comment--><b1>text<c1 a="1"/></b1>\n<b2/><b3/></a>\n')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2))
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2, skip_comments=False))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2, skip_comments=False))
e2 = lxml.etree.XML('<a><!--comment--><b1>text<c1 a="1"/></b1>\n<b2/><b3/></a>\n')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2))
e1 = ElementTree.XML('<a><b1>+1</b1></a>')
e2 = ElementTree.XML('<a><b1>+ 1 </b1></a>')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2, strict=False))
e1 = ElementTree.XML('<a><b1>+1</b1></a>')
e2 = ElementTree.XML('<a><b1>+1.1 </b1></a>')
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2, strict=False)
+ etree_elements_assert_equal(e1, e2, strict=False)
self.assertIn("texts differ: '+1' != '+1.1 '", str(ctx.exception))
e1 = ElementTree.XML('<a><b1>1</b1></a>')
e2 = ElementTree.XML('<a><b1>true </b1></a>')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2, strict=False))
- self.assertIsNone(etree.etree_elements_assert_equal(e2, e1, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e2, e1, strict=False))
e2 = ElementTree.XML('<a><b1>false </b1></a>')
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2, strict=False)
+ etree_elements_assert_equal(e1, e2, strict=False)
self.assertIn("texts differ: '1' != 'false '", str(ctx.exception))
e1 = ElementTree.XML('<a><b1> 0</b1></a>')
- self.assertIsNone(etree.etree_elements_assert_equal(e1, e2, strict=False))
- self.assertIsNone(etree.etree_elements_assert_equal(e2, e1, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e1, e2, strict=False))
+ self.assertIsNone(etree_elements_assert_equal(e2, e1, strict=False))
e2 = ElementTree.XML('<a><b1>true </b1></a>')
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2, strict=False)
+ etree_elements_assert_equal(e1, e2, strict=False)
self.assertIn("texts differ: ' 0' != 'true '", str(ctx.exception))
e1 = ElementTree.XML('<a><b1>text<c1 a="1"/></b1>\n<b2/><b3/></a>\n')
e2 = ElementTree.XML('<a><b1>text<c1 a="1"/>tail</b1>\n<b2/><b3/></a>\n')
with self.assertRaises(AssertionError) as ctx:
- etree.etree_elements_assert_equal(e1, e2, strict=False)
+ etree_elements_assert_equal(e1, e2, strict=False)
self.assertIn("tails differ: None != 'tail'", str(ctx.exception))
def test_iter_location_hints(self):
@@ -309,7 +307,7 @@ class TestElementTree(unittest.TestCase):
xsi:schemaLocation="http://example.com/xmlschema/ns-A import-case4a.xsd"/>"""
)
self.assertListEqual(
- list(etree.etree_iter_location_hints(elem)),
+ list(etree_iter_location_hints(elem)),
[('http://example.com/xmlschema/ns-A', 'import-case4a.xsd')]
)
elem = ElementTree.XML(
@@ -317,16 +315,16 @@ class TestElementTree(unittest.TestCase):
xsi:noNamespaceSchemaLocation="schema.xsd"/>"""
)
self.assertListEqual(
- list(etree.etree_iter_location_hints(elem)), [('', 'schema.xsd')]
+ list(etree_iter_location_hints(elem)), [('', 'schema.xsd')]
)
def test_prune_etree(self):
root = ElementTree.XML('<a><b1><c1/><c2/></b1><b2/><b3><c3/></b3></a>')
- etree.prune_etree(root, selector=lambda x: x.tag == 'b1')
+ prune_etree(root, selector=lambda x: x.tag == 'b1')
self.assertListEqual([e.tag for e in root.iter()], ['a', 'b2', 'b3', 'c3'])
root = ElementTree.XML('<a><b1><c1/><c2/></b1><b2/><b3><c3/></b3></a>')
- etree.prune_etree(root, selector=lambda x: x.tag.startswith('c'))
+ prune_etree(root, selector=lambda x: x.tag.startswith('c'))
self.assertListEqual([e.tag for e in root.iter()], ['a', 'b1', 'b2', 'b3'])
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index a7148ca..29b93ff 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -12,11 +12,10 @@
import unittest
import sys
import decimal
-import xml.etree.ElementTree as ElementTree
from collections import OrderedDict
from xmlschema import XMLSchema, XMLSchemaParseError
-from xmlschema.etree import etree_element, prune_etree
+from xmlschema.etree import ElementTree, etree_element, prune_etree
from xmlschema.qnames import XSD_SCHEMA, XSD_ELEMENT, XSD_SIMPLE_TYPE, XSD_ANNOTATION
from xmlschema.helpers import get_xsd_annotation, get_xsd_derivation_attribute, \
get_xsd_form_attribute, raw_xml_encode, count_digits, strictly_equal, \
diff --git a/tests/test_resources.py b/tests/test_resources.py
index 8fd2073..546bbdb 100644
--- a/tests/test_resources.py
+++ b/tests/test_resources.py
@@ -19,7 +19,6 @@ from urllib.error import URLError
from urllib.request import urlopen
from urllib.parse import urlsplit, uses_relative
from pathlib import Path, PureWindowsPath, PurePath
-from xml.etree import ElementTree
try:
import lxml.etree as lxml_etree
@@ -28,7 +27,7 @@ except ImportError:
from xmlschema import fetch_namespaces, fetch_resource, normalize_url, \
fetch_schema, fetch_schema_locations, XMLResource, XMLResourceError, XMLSchema
-from xmlschema.etree import etree_element, py_etree_element, is_etree_element
+from xmlschema.etree import ElementTree, etree_element, py_etree_element, is_etree_element
from xmlschema.namespaces import XSD_NAMESPACE
from xmlschema.resources import is_url, is_local_url, is_remote_url, \
url_path_is_file, normalize_locations, LazySelector
diff --git a/tests/test_w3c_suite.py b/tests/test_w3c_suite.py
index 6df61d2..964ce08 100644
--- a/tests/test_w3c_suite.py
+++ b/tests/test_w3c_suite.py
@@ -14,7 +14,6 @@ This script runs tests concerning the W3C XML Schema 1.1 test suite.
import unittest
import argparse
import os.path
-import xml.etree.ElementTree as ElementTree
import warnings
try:
@@ -23,6 +22,7 @@ except ImportError:
lxml_etree = None
from xmlschema import validate, XMLSchema10, XMLSchema11, XMLSchemaException
+from xmlschema.etree import ElementTree
TEST_SUITE_NAMESPACE = "http://www.w3.org/XML/2004/xml-schema-test-suite/"
XLINK_NAMESPACE = "http://www.w3.org/1999/xlink"
diff --git a/tests/test_wsdl.py b/tests/test_wsdl.py
index c480156..65a5209 100644
--- a/tests/test_wsdl.py
+++ b/tests/test_wsdl.py
@@ -14,13 +14,11 @@ import unittest
import os
from xmlschema import XMLSchemaValidationError, XMLSchema10, XMLSchema11
-from xmlschema.etree import ParseError
+from xmlschema.etree import ElementTree, ParseError
from xmlschema.wsdl import WsdlParseError, WsdlComponent, WsdlMessage, \
WsdlPortType, WsdlOperation, WsdlBinding, WsdlService, Wsdl11Document, \
WsdlInput, SoapHeader
-from xml.etree import ElementTree
-
TEST_CASES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_cases/')
diff --git a/tests/test_xpath.py b/tests/test_xpath.py
index e72b221..eb5acad 100644
--- a/tests/test_xpath.py
+++ b/tests/test_xpath.py
@@ -12,12 +12,12 @@
import unittest
import os
-import xml.etree.ElementTree as ElementTree
from elementpath import XPath1Parser, XPath2Parser, Selector, \
AttributeNode, TypedElement, ElementPathSyntaxError
from xmlschema import XMLSchema10, XMLSchema11, XsdElement, XsdAttribute
from xmlschema.namespaces import XSD_NAMESPACE
+from xmlschema.etree import ElementTree
from xmlschema.xpath import XMLSchemaProxy, iter_schema_nodes
from xmlschema.validators import XsdAtomic, XsdAtomicRestriction
diff --git a/tests/validation/test_decoding.py b/tests/validation/test_decoding.py
index 908e6bd..ae7742a 100644
--- a/tests/validation/test_decoding.py
+++ b/tests/validation/test_decoding.py
@@ -12,7 +12,6 @@ import unittest
import os
from decimal import Decimal
import base64
-from xml.etree import ElementTree
try:
import lxml.etree as lxml_etree
@@ -24,6 +23,7 @@ import xmlschema
from xmlschema import XMLSchemaValidationError, ParkerConverter, BadgerFishConverter, \
AbderaConverter, JsonMLConverter, ColumnarConverter
+from xmlschema.etree import ElementTree
from xmlschema.converters import UnorderedConverter
from xmlschema.validators import XMLSchema11
from xmlschema.testing import XsdValidatorTestCase
diff --git a/tests/validation/test_validation.py b/tests/validation/test_validation.py
index be8ce36..b104973 100644
--- a/tests/validation/test_validation.py
+++ b/tests/validation/test_validation.py
@@ -11,7 +11,6 @@
import unittest
import os
import sys
-from xml.etree import ElementTree
try:
import lxml.etree as lxml_etree
@@ -21,6 +20,7 @@ except ImportError:
import xmlschema
from xmlschema import XMLSchemaValidationError
+from xmlschema.etree import ElementTree
from xmlschema.validators import XMLSchema11
from xmlschema.testing import XsdValidatorTestCase
diff --git a/tests/validators/test_exceptions.py b/tests/validators/test_exceptions.py
index c23f1d6..86c5635 100644
--- a/tests/validators/test_exceptions.py
+++ b/tests/validators/test_exceptions.py
@@ -11,10 +11,10 @@
import unittest
import os
import io
-import xml.etree.ElementTree as ElementTree
import lxml.etree
from xmlschema import XMLSchema, XMLResource
+from xmlschema.etree import ElementTree
from xmlschema.validators.exceptions import XMLSchemaValidatorError, \
XMLSchemaNotBuiltError, XMLSchemaModelDepthError, XMLSchemaValidationError, \
XMLSchemaChildrenValidationError
diff --git a/tests/validators/test_notations.py b/tests/validators/test_notations.py
index 0b48c01..a14baa8 100644
--- a/tests/validators/test_notations.py
+++ b/tests/validators/test_notations.py
@@ -9,9 +9,9 @@
# @author Davide Brunato <brunato@sissa.it>
#
import unittest
-import xml.etree.ElementTree as ElementTree
from xmlschema import XMLSchemaParseError
+from xmlschema.etree import ElementTree
from xmlschema.qnames import XSD_NOTATION
from xmlschema.validators import XMLSchema10, XMLSchema11, XsdNotation
diff --git a/tests/validators/test_xsdbase.py b/tests/validators/test_xsdbase.py
index f5791b4..6182a83 100644
--- a/tests/validators/test_xsdbase.py
+++ b/tests/validators/test_xsdbase.py
@@ -12,10 +12,10 @@ import unittest
import os
import platform
import re
-import xml.etree.ElementTree as ElementTree
from xmlschema.validators import XsdValidator, XsdComponent, XMLSchema10, \
XMLSchema11, XMLSchemaParseError, XMLSchemaValidationError, XsdGroup, XsdSimpleType
+from xmlschema.etree import ElementTree
from xmlschema.qnames import XSD_ELEMENT, XSD_ANNOTATION, XSD_ANY_TYPE
from xmlschema.namespaces import XSD_NAMESPACE
@@ -766,7 +766,6 @@ class TestParticleMixin(unittest.TestCase):
if __name__ == '__main__':
- import platform
header_template = "Test xmlschema's XSD base classes with Python {} on {}"
header = header_template.format(platform.python_version(), platform.platform())
print('{0}\n{1}\n{0}'.format("*" * len(header), header))

View File

@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Nov 10 07:13:53 UTC 2020 - Matej Cepl <mcepl@suse.com>
- Add the upstream etree_import_in_tests.patch to fix
gh#sissaschool/xmlschema#210.
-------------------------------------------------------------------
Mon Nov 9 15:32:59 UTC 2020 - Matej Cepl <mcepl@suse.com>

View File

@@ -25,15 +25,18 @@ Summary: An XML Schema validator and decoder
License: MIT
URL: https://github.com/sissaschool/xmlschema
Source: https://files.pythonhosted.org/packages/source/x/xmlschema/xmlschema-%{version}.tar.gz
# PATCH-FIX-UPSTREAM etree_import_in_tests.patch gh#sissaschool/xmlschema#210 mcepl@suse.com
# use the same etree all the time
Patch0: etree_import_in_tests.patch
# PATCH-FIX-UPSTREAM factory_tests.patch gh#sissaschool/xmlschema#210 mcepl@suse.com
# rename tests_factory to factory_tests so it is not discovered by pytest.
Patch0: factory_tests.patch
Patch1: factory_tests.patch
# PATCH-FIX-UPSTREAM remove_shebang.patch gh#sissaschool/xmlschema#210 mcepl@suse.com
# Remove superfluous shebang
Patch1: remove_shebang.patch
Patch2: remove_shebang.patch
# PATCH-FIX-UPSTREAM location_testing_script.patch gh#sissaschool/xmlschema#210 mcepl@suse.com
# this patch makes things totally awesome
Patch2: location_testing_script.patch
Patch3: location_testing_script.patch
BuildRequires: %{python_module elementpath >= 1.4.0}
BuildRequires: %{python_module lxml}
BuildRequires: %{python_module pip}
@@ -76,13 +79,7 @@ done
%check
export LANG="en_US.UTF8"
# test_element_tree_import_script is (easily workaroundable) gh#sissaschool/xmlschema#167
# tests_factory setup is broken
# SKIP_TESTS="test_element_tree_import_script"
# gh#sissaschool/xmlschema#210
SKIP_TESTS="test_imported_element_tree or test_xml_resource_defuse"
SKIP_TESTS="$SKIP_TESTS or test_xml_resource_from_string"
%pytest -s -k "not ($SKIP_TESTS)" tests
%pytest tests/
%post
%python_install_alternative xmlschema-json2xml