Comment 1 for bug 2016939

Revision history for this message
Miro HronĨok (churchyard) wrote :

I've tried to change the tests like this:

    def test_html_prefix_nsmap(self):
        etree = self.etree
        html = etree.HTML('<hha:page-description>aa</hha:page-description>')
        el = html.find('.//page-description')
        if etree.LIBXML_VERSION < (2, 10, 4):
            if etree.LIBXML_VERSION < (2, 9, 11):
                self.assertEqual({'hha': None}, el.nsmap)
            else:
                self.assertEqual({}, el.nsmap)
        else:
            self.assertIsNone(el)
            el = html.find('.//hha:page-description') # <-- breaks
            self.assertEqual({}, el.nsmap)

But the marked line does not work as I expected:

======================================================================
ERROR: test_html_prefix_nsmap (lxml.tests.test_etree.ETreeOnlyTestCase.test_html_prefix_nsmap)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "src/lxml/_elementpath.py", line 85, in lxml._elementpath.xpath_tokenizer
    raise KeyError
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/lib64/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/usr/lib64/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "/builddir/build/BUILD/lxml-4.9.2/src/lxml/tests/test_etree.py", line 3080, in test_html_prefix_nsmap
    el = html.find('.//hha:page-description')
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src/lxml/etree.pyx", line 1550, in lxml.etree._Element.find
    return _elementpath.find(self, path, namespaces)
  File "src/lxml/_elementpath.py", line 323, in lxml._elementpath.find
    it = iterfind(elem, path, namespaces)
  File "src/lxml/_elementpath.py", line 312, in lxml._elementpath.iterfind
    selector = _build_path_iterator(path, namespaces)
  File "src/lxml/_elementpath.py", line 295, in lxml._elementpath._build_path_iterator
    selector.append(ops[token[0]](_next, token))
  File "src/lxml/_elementpath.py", line 120, in lxml._elementpath.prepare_descendant
    token = next()
  File "src/lxml/_elementpath.py", line 88, in xpath_tokenizer
    raise SyntaxError("prefix %r not found in prefix map" % prefix)
SyntaxError: prefix 'hha' not found in prefix map

----------------------------------------------------------------------
Ran 1979 tests in 5.332s