Removed _SimpleElementPath and its flaky test. The test monkey-patches the module, which causes other failures and fails itself depending on the order tests are run.
This commit is contained in:
parent
175fada429
commit
27cbb19ae5
|
@ -2234,28 +2234,6 @@ class NoAcceleratorTest(unittest.TestCase):
|
||||||
self.assertEqual(pyET.Element.__module__, 'xml.etree.ElementTree')
|
self.assertEqual(pyET.Element.__module__, 'xml.etree.ElementTree')
|
||||||
self.assertEqual(pyET.SubElement.__module__, 'xml.etree.ElementTree')
|
self.assertEqual(pyET.SubElement.__module__, 'xml.etree.ElementTree')
|
||||||
|
|
||||||
|
|
||||||
class ElementPathFallbackTest(unittest.TestCase):
|
|
||||||
def test_fallback(self):
|
|
||||||
current_ElementPath = ET.ElementPath
|
|
||||||
ET.ElementPath = ET._SimpleElementPath()
|
|
||||||
elem = ET.XML(SAMPLE_XML)
|
|
||||||
self.assertEqual(elem.find('tag').tag, 'tag')
|
|
||||||
self.assertEqual(ET.ElementTree(elem).find('tag').tag, 'tag')
|
|
||||||
self.assertEqual(elem.findtext('tag'), 'text')
|
|
||||||
self.assertIsNone(elem.findtext('tog'))
|
|
||||||
self.assertEqual(elem.findtext('tog', 'default'), 'default')
|
|
||||||
self.assertEqual(ET.ElementTree(elem).findtext('tag'), 'text')
|
|
||||||
self.assertEqual(summarize_list(elem.findall('tag')), ['tag', 'tag'])
|
|
||||||
self.assertEqual(summarize_list(elem.findall('.//tag')),
|
|
||||||
['tag', 'tag', 'tag'])
|
|
||||||
|
|
||||||
#self.assertIsNone(elem.find('section/tag'))
|
|
||||||
#self.assertIsNone(elem.findtext('section/tag'))
|
|
||||||
self.assertEqual(summarize_list(elem.findall('section/tag')), [])
|
|
||||||
|
|
||||||
ET.ElementPath = current_ElementPath
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -2328,7 +2306,6 @@ def test_main(module=None):
|
||||||
if pyET:
|
if pyET:
|
||||||
test_classes.extend([
|
test_classes.extend([
|
||||||
NoAcceleratorTest,
|
NoAcceleratorTest,
|
||||||
ElementPathFallbackTest,
|
|
||||||
])
|
])
|
||||||
|
|
||||||
support.run_unittest(*test_classes)
|
support.run_unittest(*test_classes)
|
||||||
|
|
|
@ -101,32 +101,8 @@ import sys
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
class _SimpleElementPath:
|
from . import ElementPath
|
||||||
# emulate pre-1.2 find/findtext/findall behaviour
|
|
||||||
def find(self, element, tag, namespaces=None):
|
|
||||||
for elem in element:
|
|
||||||
if elem.tag == tag:
|
|
||||||
return elem
|
|
||||||
return None
|
|
||||||
def findtext(self, element, tag, default=None, namespaces=None):
|
|
||||||
elem = self.find(element, tag)
|
|
||||||
if elem is None:
|
|
||||||
return default
|
|
||||||
return elem.text or ""
|
|
||||||
def iterfind(self, element, tag, namespaces=None):
|
|
||||||
if tag[:3] == ".//":
|
|
||||||
for elem in element.iter(tag[3:]):
|
|
||||||
yield elem
|
|
||||||
for elem in element:
|
|
||||||
if elem.tag == tag:
|
|
||||||
yield elem
|
|
||||||
def findall(self, element, tag, namespaces=None):
|
|
||||||
return list(self.iterfind(element, tag, namespaces))
|
|
||||||
|
|
||||||
try:
|
|
||||||
from . import ElementPath
|
|
||||||
except ImportError:
|
|
||||||
ElementPath = _SimpleElementPath()
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Parser error. This is a subclass of <b>SyntaxError</b>.
|
# Parser error. This is a subclass of <b>SyntaxError</b>.
|
||||||
|
|
Loading…
Reference in New Issue