Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failures #34

Closed
fabaff opened this issue Feb 28, 2024 · 1 comment
Closed

Test failures #34

fabaff opened this issue Feb 28, 2024 · 1 comment
Assignees
Labels
bug Something isn't working testsuite Issues concerning test suite

Comments

@fabaff
Copy link

fabaff commented Feb 28, 2024

On Python 3.11 I get some failures during the tests.

============================= test session starts ==============================
platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0
rootdir: /build/source
plugins: typeguard-4.1.5
collected 34 items                                                             

test-rt/test_elem_class_lookup.py ..                                     [  5%]
test-rt/test_html_link_funcs.py ..FFF..........FFFF                      [ 61%]
test-rt/test_iterparse.py ..........                                     [ 91%]
test-rt/test_xinclude.py ...                                             [100%]

=================================== FAILURES ===================================
______________________ TestInputType.test_find_rel_links _______________________

self = <test_html_link_funcs.TestInputType object at 0x7ffff5dbaed0>
h1_filepath = PosixPath('/build/source/test-rt/data/sample.html')
h1_str = '<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="h...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_bytes = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
html_tree = <lxml.etree._ElementTree object at 0x7ffff5d79540>

    def test_find_rel_links(
        self,
        h1_filepath: Path,
        h1_str: str,
        h1_bytes: bytes,
        html_tree: _ElementTree[HtmlElement],
    ) -> None:
        links = find_rel_links(str(h1_filepath), "nofollow noopener noreferrer")
        reveal_type(links)
        del links
        links = find_rel_links(html_tree.getroot(), "nofollow noopener noreferrer")
        reveal_type(links)
        del links
        links = find_rel_links(h1_str, "nofollow noopener noreferrer")
        reveal_type(links)
        del links
>       links = find_rel_links(h1_bytes, "nofollow noopener noreferrer")

test-rt/test_html_link_funcs.py:82: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lxml.html._MethodFunc object at 0x7ffff5e9d390>
doc = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
args = ('nofollow noopener noreferrer',), kw = {}, result_type = <class 'bytes'>
make_a_copy = False

    def __call__(self, doc, *args, **kw):
        result_type = type(doc)
        if isinstance(doc, str):
            if 'copy' in kw:
                raise TypeError(
                    "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
            doc = fromstring(doc, **kw)
        else:
            if 'copy' in kw:
                make_a_copy = kw.pop('copy')
            else:
                make_a_copy = self.copy
            if make_a_copy:
                doc = copy.deepcopy(doc)
>       meth = getattr(doc, self.name)
E       AttributeError: 'bytes' object has no attribute 'find_rel_links'

/nix/store/a5dj6i40j88clhb53mfb2bkzif7m1iya-python3.11-lxml-5.1.0/lib/python3.11/site-packages/lxml/html/__init__.py:647: AttributeError
________________________ TestInputType.test_find_class _________________________

self = <test_html_link_funcs.TestInputType object at 0x7ffff5dba110>
h1_filepath = PosixPath('/build/source/test-rt/data/sample.html')
h1_str = '<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="h...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_bytes = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
html_tree = <lxml.etree._ElementTree object at 0x7ffff5d492c0>

    def test_find_class(
        self,
        h1_filepath: Path,
        h1_str: str,
        h1_bytes: bytes,
        html_tree: _ElementTree[HtmlElement],
    ) -> None:
        elems = find_class(str(h1_filepath), "single")
        reveal_type(elems)
        del elems
        elems = find_class(h1_str, "single")
        reveal_type(elems)
        del elems
>       elems = find_class(h1_bytes, "single")

test-rt/test_html_link_funcs.py:100: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lxml.html._MethodFunc object at 0x7ffff5e9d450>
doc = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
args = ('single',), kw = {}, result_type = <class 'bytes'>, make_a_copy = False

    def __call__(self, doc, *args, **kw):
        result_type = type(doc)
        if isinstance(doc, str):
            if 'copy' in kw:
                raise TypeError(
                    "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
            doc = fromstring(doc, **kw)
        else:
            if 'copy' in kw:
                make_a_copy = kw.pop('copy')
            else:
                make_a_copy = self.copy
            if make_a_copy:
                doc = copy.deepcopy(doc)
>       meth = getattr(doc, self.name)
E       AttributeError: 'bytes' object has no attribute 'find_class'

/nix/store/a5dj6i40j88clhb53mfb2bkzif7m1iya-python3.11-lxml-5.1.0/lib/python3.11/site-packages/lxml/html/__init__.py:647: AttributeError
_________________________ TestInputType.test_iterlinks _________________________

self = <test_html_link_funcs.TestInputType object at 0x7ffff5dbae10>
h1_filepath = PosixPath('/build/source/test-rt/data/sample.html')
h1_str = '<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="h...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_bytes = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
html_tree = <lxml.etree._ElementTree object at 0x7ffff5dafdc0>

    def test_iterlinks(
        self,
        h1_filepath: Path,
        h1_str: str,
        h1_bytes: bytes,
        html_tree: _ElementTree[HtmlElement],
    ) -> None:
        results = iterlinks(str(h1_filepath))
        reveal_type(results)
        del results
        results = iterlinks(h1_str)
        reveal_type(results)
        del results
>       results = iterlinks(h1_bytes)

test-rt/test_html_link_funcs.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lxml.html._MethodFunc object at 0x7ffff5e9d290>
doc = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
args = (), kw = {}, result_type = <class 'bytes'>, make_a_copy = False

    def __call__(self, doc, *args, **kw):
        result_type = type(doc)
        if isinstance(doc, str):
            if 'copy' in kw:
                raise TypeError(
                    "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
            doc = fromstring(doc, **kw)
        else:
            if 'copy' in kw:
                make_a_copy = kw.pop('copy')
            else:
                make_a_copy = self.copy
            if make_a_copy:
                doc = copy.deepcopy(doc)
>       meth = getattr(doc, self.name)
E       AttributeError: 'bytes' object has no attribute 'iterlinks'

/nix/store/a5dj6i40j88clhb53mfb2bkzif7m1iya-python3.11-lxml-5.1.0/lib/python3.11/site-packages/lxml/html/__init__.py:647: AttributeError
_______________________ TestBadArgs.test_bad_methodfunc ________________________

self = <test_html_link_funcs.TestBadArgs object at 0x7ffff5d91790>
h1_str = '<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="h...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_bytes = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_filepath = PosixPath('/build/source/test-rt/data/sample.html')
html_tree = <lxml.etree._ElementTree object at 0x7ffff57fee00>

    def test_bad_methodfunc(
        self,
        h1_str: str,
        h1_bytes: bytes,
        h1_filepath: Path,
        html_tree: _ElementTree[HtmlElement],
    ) -> None:
        for input in (h1_str, h1_bytes, str(h1_filepath)):
            with pytest.raises(
                TypeError, match="got an unexpected keyword argument 'handle_failures'"
            ):
>               _ = make_links_absolute(
                    doc=cast(Any, input), base_url=None, handle_failures=None
                )

test-rt/test_html_link_funcs.py:248: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lxml.html._MethodFunc object at 0x7ffff5e9d590>
doc = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
args = (), kw = {'base_url': None, 'handle_failures': None}
result_type = <class 'bytes'>, make_a_copy = True

    def __call__(self, doc, *args, **kw):
        result_type = type(doc)
        if isinstance(doc, str):
            if 'copy' in kw:
                raise TypeError(
                    "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
            doc = fromstring(doc, **kw)
        else:
            if 'copy' in kw:
                make_a_copy = kw.pop('copy')
            else:
                make_a_copy = self.copy
            if make_a_copy:
                doc = copy.deepcopy(doc)
>       meth = getattr(doc, self.name)
E       AttributeError: 'bytes' object has no attribute 'make_links_absolute'

/nix/store/a5dj6i40j88clhb53mfb2bkzif7m1iya-python3.11-lxml-5.1.0/lib/python3.11/site-packages/lxml/html/__init__.py:647: AttributeError
___________________ TestOutputType.test_make_links_absolute ____________________

self = <test_html_link_funcs.TestOutputType object at 0x7ffff5d91b10>
h1_str = '<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="h...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_bytes = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
html_tree = <lxml.etree._ElementTree object at 0x7ffff584e9c0>

    def test_make_links_absolute(
        self,
        h1_str: str,
        h1_bytes: bytes,
        html_tree: _ElementTree[HtmlElement],
    ) -> None:
        with pytest.raises(
            TypeError, match="No base_url given, and the document has no base_url"
        ):
>           _ = make_links_absolute(h1_bytes)

test-rt/test_html_link_funcs.py:272: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lxml.html._MethodFunc object at 0x7ffff5e9d590>
doc = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
args = (), kw = {}, result_type = <class 'bytes'>, make_a_copy = True

    def __call__(self, doc, *args, **kw):
        result_type = type(doc)
        if isinstance(doc, str):
            if 'copy' in kw:
                raise TypeError(
                    "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
            doc = fromstring(doc, **kw)
        else:
            if 'copy' in kw:
                make_a_copy = kw.pop('copy')
            else:
                make_a_copy = self.copy
            if make_a_copy:
                doc = copy.deepcopy(doc)
>       meth = getattr(doc, self.name)
E       AttributeError: 'bytes' object has no attribute 'make_links_absolute'

/nix/store/a5dj6i40j88clhb53mfb2bkzif7m1iya-python3.11-lxml-5.1.0/lib/python3.11/site-packages/lxml/html/__init__.py:647: AttributeError
____________________ TestOutputType.test_resolve_base_href _____________________

self = <test_html_link_funcs.TestOutputType object at 0x7ffff5d92710>
h1_str = '<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="h...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_bytes = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
html_tree = <lxml.etree._ElementTree object at 0x7ffff5d16640>

    def test_resolve_base_href(
        self,
        h1_str: str,
        h1_bytes: bytes,
        html_tree: _ElementTree[HtmlElement],
    ) -> None:
>       result = resolve_base_href(h1_bytes)

test-rt/test_html_link_funcs.py:291: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lxml.html._MethodFunc object at 0x7ffff5e9d490>
doc = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
args = (), kw = {}, result_type = <class 'bytes'>, make_a_copy = True

    def __call__(self, doc, *args, **kw):
        result_type = type(doc)
        if isinstance(doc, str):
            if 'copy' in kw:
                raise TypeError(
                    "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
            doc = fromstring(doc, **kw)
        else:
            if 'copy' in kw:
                make_a_copy = kw.pop('copy')
            else:
                make_a_copy = self.copy
            if make_a_copy:
                doc = copy.deepcopy(doc)
>       meth = getattr(doc, self.name)
E       AttributeError: 'bytes' object has no attribute 'resolve_base_href'

/nix/store/a5dj6i40j88clhb53mfb2bkzif7m1iya-python3.11-lxml-5.1.0/lib/python3.11/site-packages/lxml/html/__init__.py:647: AttributeError
______________________ TestOutputType.test_rewrite_links _______________________

self = <test_html_link_funcs.TestOutputType object at 0x7ffff5d92bd0>
h1_str = '<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="h...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
h1_bytes = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
html_tree = <lxml.etree._ElementTree object at 0x7ffff5ddaec0>

    def test_rewrite_links(
        self,
        h1_str: str,
        h1_bytes: bytes,
        html_tree: _ElementTree[HtmlElement],
    ) -> None:
>       result = rewrite_links(h1_bytes, lambda _: _BASE_HREF)

test-rt/test_html_link_funcs.py:307: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lxml.html._MethodFunc object at 0x7ffff5e9d750>
doc = b'<!DOCTYPE html>\n<html xmlns="http://www.w3.org/1999/xhtml" lang="en" data-placeholder-focus="false"><head profile="...verflow:hidden;position:absolute;bottom:1px;" alt="" /></noscript>\n<!-- google_ad_section_end -->\n</body>\n</html>\n'
args = (<function TestOutputType.test_rewrite_links.<locals>.<lambda> at 0x7ffff5d73ce0>,)
kw = {}, result_type = <class 'bytes'>, make_a_copy = True

    def __call__(self, doc, *args, **kw):
        result_type = type(doc)
        if isinstance(doc, str):
            if 'copy' in kw:
                raise TypeError(
                    "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
            doc = fromstring(doc, **kw)
        else:
            if 'copy' in kw:
                make_a_copy = kw.pop('copy')
            else:
                make_a_copy = self.copy
            if make_a_copy:
                doc = copy.deepcopy(doc)
>       meth = getattr(doc, self.name)
E       AttributeError: 'bytes' object has no attribute 'rewrite_links'

/nix/store/a5dj6i40j88clhb53mfb2bkzif7m1iya-python3.11-lxml-5.1.0/lib/python3.11/site-packages/lxml/html/__init__.py:647: AttributeError
=========================== short test summary info ============================
FAILED test-rt/test_html_link_funcs.py::TestInputType::test_find_rel_links - AttributeError: 'bytes' object has no attribute 'find_rel_links'
FAILED test-rt/test_html_link_funcs.py::TestInputType::test_find_class - AttributeError: 'bytes' object has no attribute 'find_class'
FAILED test-rt/test_html_link_funcs.py::TestInputType::test_iterlinks - AttributeError: 'bytes' object has no attribute 'iterlinks'
FAILED test-rt/test_html_link_funcs.py::TestBadArgs::test_bad_methodfunc - AttributeError: 'bytes' object has no attribute 'make_links_absolute'
FAILED test-rt/test_html_link_funcs.py::TestOutputType::test_make_links_absolute - AttributeError: 'bytes' object has no attribute 'make_links_absolute'
FAILED test-rt/test_html_link_funcs.py::TestOutputType::test_resolve_base_href - AttributeError: 'bytes' object has no attribute 'resolve_base_href'
FAILED test-rt/test_html_link_funcs.py::TestOutputType::test_rewrite_links - AttributeError: 'bytes' object has no attribute 'rewrite_links'
========================= 7 failed, 27 passed in 2.03s =========================
@abelcheung abelcheung added the bug Something isn't working label Feb 29, 2024
@abelcheung abelcheung self-assigned this Feb 29, 2024
@abelcheung
Copy link
Owner

@fabaff This is caused by a regression in lxml 5.1.0, which is already fixed but still pending a new release. Until then, you can temporarily pin lxml to 5.0.1.

I guess I'll add some code to avoid checking for bytes for that version.

@abelcheung abelcheung added the testsuite Issues concerning test suite label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working testsuite Issues concerning test suite
Projects
None yet
Development

No branches or pull requests

2 participants