readthedocs / sphinx-autoapi

A new approach to API documentation in Sphinx.
https://sphinx-autoapi.readthedocs.io/
MIT License
415 stars 126 forks source link

3.1.1: `pyupgrade --py38-plush` generated changes trashes test suite #449

Closed kloczek closed 1 week ago

kloczek commented 1 month ago

I've been trying to drop python<=3.7 support by filter all code over pyupgrade --py38-plush and after that test suite started failing

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-autoapi-3.1.1-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-autoapi-3.1.1-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0
rootdir: /home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1
configfile: pyproject.toml
plugins: datadir-1.5.0, regressions-2.5.0, timeout-2.3.1, typeguard-4.2.1, flexmock-0.12.1
collected 311 items

tests/python/test_own_page_option.py .......F.....F.....F......F...........                                                                                                           [ 12%]
tests/python/test_parser.py ..........                                                                                                                                                [ 15%]
tests/python/test_pyintegration.py ..F....F...F............s..........................................                                                                                [ 36%]
tests/test_astroid_utils.py ......................................................................................................................................................... [ 86%]
........................................                                                                                                                                              [ 99%]
tests/test_integration.py ...                                                                                                                                                         [100%]

========================================================================================= FAILURES ==========================================================================================
___________________________________________________________________________________ TestClass.test_class ____________________________________________________________________________________

self = <test_own_page_option.TestClass object at 0x7f7b7a647af0>, parse = <function parse.<locals>.parser at 0x7f7b784c6830>

    def test_class(self, parse):
        class_path = "_build/html/autoapi/package/Class.html"
        class_file = parse(class_path)

        class_sig = class_file.find(id="package.Class")
        assert class_sig
        class_ = class_sig.parent
        docstring = class_.find_all("p")[1]
>       assert docstring.text == "This is a class."
E       AssertionError: assert 'Class var docstring' == 'This is a class.'
E
E         - This is a class.
E         + Class var docstring

/home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1/tests/python/test_own_page_option.py:262: AssertionError
__________________________________________________________________________________ TestFunction.test_class __________________________________________________________________________________

self = <test_own_page_option.TestFunction object at 0x7f7b7a6454e0>, parse = <function parse.<locals>.parser at 0x7f7b780556c0>

    def test_class(self, parse):
        class_path = "_build/html/autoapi/package/Class.html"
        class_file = parse(class_path)

        class_sig = class_file.find(id="package.Class")
        assert class_sig
        class_ = class_sig.parent
        docstring = class_.find_all("p")[1]
>       assert docstring.text == "This is a class."
E       AssertionError: assert 'Class var docstring' == 'This is a class.'
E
E         - This is a class.
E         + Class var docstring

/home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1/tests/python/test_own_page_option.py:476: AssertionError
___________________________________________________________________________________ TestMethod.test_class ___________________________________________________________________________________

self = <test_own_page_option.TestMethod object at 0x7f7b7a646f80>, parse = <function parse.<locals>.parser at 0x7f7b7868acb0>

    def test_class(self, parse):
        class_path = "_build/html/autoapi/package/Class.html"
        class_file = parse(class_path)

        class_sig = class_file.find(id="package.Class")
        assert class_sig
        class_ = class_sig.parent
        docstring = class_.find_all("p")[1]
>       assert docstring.text == "This is a class."
E       AssertionError: assert 'Class var docstring' == 'This is a class.'
E
E         - This is a class.
E         + Class var docstring

/home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1/tests/python/test_own_page_option.py:666: AssertionError
_________________________________________________________________________________ TestAttribute.test_class __________________________________________________________________________________

self = <test_own_page_option.TestAttribute object at 0x7f7b7a647f40>, parse = <function parse.<locals>.parser at 0x7f7b77dc35b0>

    def test_class(self, parse):
        class_path = "_build/html/autoapi/package/Class.html"
        class_file = parse(class_path)

        class_sig = class_file.find(id="package.Class")
        assert class_sig
        class_ = class_sig.parent
>       docstring = class_.find_all("p")[1]
E       IndexError: list index out of range

/home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1/tests/python/test_own_page_option.py:860: IndexError
__________________________________________________________________________ TestSimpleModule.test_show_inheritance ___________________________________________________________________________

self = <test_pyintegration.TestSimpleModule object at 0x7f7b7a192020>, parse = <function parse.<locals>.parser at 0x7f7b779d3370>

    def test_show_inheritance(self, parse):
        example_file = parse("_build/html/autoapi/example/index.html")

        foo = example_file.find(id="example.Foo")
        foo_docstring = foo.parent.find("dd").contents[0]
>       assert foo_docstring.text.startswith("Bases:")
E       AssertionError: assert False
E        +  where False = <built-in method startswith of str object at 0x7f7b789b2d40>('Bases:')
E        +    where <built-in method startswith of str object at 0x7f7b789b2d40> = 'Can we parse arguments from the class docstring?'.startswith
E        +      where 'Can we parse arguments from the class docstring?' = <p>Can we parse arguments from the class docstring?</p>.text

/home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1/tests/python/test_pyintegration.py:142: AssertionError
___________________________________________________________________________ TestMovedConfPy.test_show_inheritance ___________________________________________________________________________

self = <test_pyintegration.TestMovedConfPy object at 0x7f7b7a1905b0>, parse = <function parse.<locals>.parser at 0x7f7b777ea9e0>

    def test_show_inheritance(self, parse):
        example_file = parse("_build/html/autoapi/example/index.html")

        foo = example_file.find(id="example.Foo")
        foo_docstring = foo.parent.find("dd").contents[0]
>       assert foo_docstring.text.startswith("Bases:")
E       AssertionError: assert False
E        +  where False = <built-in method startswith of str object at 0x7f7b77a36480>('Bases:')
E        +    where <built-in method startswith of str object at 0x7f7b77a36480> = 'Can we parse arguments from the class docstring?'.startswith
E        +      where 'Can we parse arguments from the class docstring?' = <p>Can we parse arguments from the class docstring?</p>.text

/home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1/tests/python/test_pyintegration.py:142: AssertionError
_______________________________________________________________ TestSimpleModuleDifferentPrimaryDomain.test_show_inheritance ________________________________________________________________

self = <test_pyintegration.TestSimpleModuleDifferentPrimaryDomain object at 0x7f7b7a190460>, parse = <function parse.<locals>.parser at 0x7f7b77795b40>

    def test_show_inheritance(self, parse):
        example_file = parse("_build/html/autoapi/example/index.html")

        foo = example_file.find(id="example.Foo")
        foo_docstring = foo.parent.find("dd").contents[0]
>       assert foo_docstring.text.startswith("Bases:")
E       AssertionError: assert False
E        +  where False = <built-in method startswith of str object at 0x7f7b7777d370>('Bases:')
E        +    where <built-in method startswith of str object at 0x7f7b7777d370> = 'Can we parse arguments from the class docstring?'.startswith
E        +      where 'Can we parse arguments from the class docstring?' = <p>Can we parse arguments from the class docstring?</p>.text

/home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.1/tests/python/test_pyintegration.py:142: AssertionError
===================================================================================== warnings summary ======================================================================================
tests/python/test_pyintegration.py: 52 warnings
  /usr/lib/python3.10/site-packages/sphinx/ext/autodoc/__init__.py:827: RemovedInSphinx80Warning: Returning tuples of (name, object) as the second return value from get_object_members() is deprecated. Return ObjectMember(name, object) instances instead.
    for (mname, member, isattr) in self.filter_members(members, want_all):

tests/test_integration.py::TestIntegration::test_template_overrides
  /home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-autoapi-3.1.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/autoapi/extension.py:107: RemovedInSphinx80Warning: Sphinx 8 will drop support for representing paths as strings. Use "pathlib.Path" or "os.fspath" instead.
    elif app.srcdir != os.getcwd():

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
SKIPPED [1] tests/python/test_pyintegration.py:598: PEP-695 support requires Python >=3.12
FAILED tests/python/test_own_page_option.py::TestClass::test_class - AssertionError: assert 'Class var docstring' == 'This is a class.'
FAILED tests/python/test_own_page_option.py::TestFunction::test_class - AssertionError: assert 'Class var docstring' == 'This is a class.'
FAILED tests/python/test_own_page_option.py::TestMethod::test_class - AssertionError: assert 'Class var docstring' == 'This is a class.'
FAILED tests/python/test_own_page_option.py::TestAttribute::test_class - IndexError: list index out of range
FAILED tests/python/test_pyintegration.py::TestSimpleModule::test_show_inheritance - AssertionError: assert False
FAILED tests/python/test_pyintegration.py::TestMovedConfPy::test_show_inheritance - AssertionError: assert False
FAILED tests/python/test_pyintegration.py::TestSimpleModuleDifferentPrimaryDomain::test_show_inheritance - AssertionError: assert False
================================================================== 7 failed, 303 passed, 1 skipped, 53 warnings in 27.37s ===================================================================

It would be good to prepare sphinx-autoapi code to make it upgradeable using pyupgrade.

kloczek commented 1 week ago

I've tested 3.1.1+ all commits from master ans pytest fails for me in two units

Here is pytest output: ```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-autoapi-3.1.2-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-autoapi-3.1.2-2.fc37.x86_64/usr/lib/python3.10/site-packages + /usr/bin/pytest -ra -m 'not network' ============================= test session starts ============================== platform linux -- Python 3.10.14, pytest-8.2.2, pluggy-1.5.0 rootdir: /home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.2 configfile: pyproject.toml collected 312 items tests/python/test_own_page_option.py ................................... [ 11%] ... [ 12%] tests/python/test_parser.py .......... [ 15%] tests/python/test_pyintegration.py .................F...F..s............ [ 27%] ............................... [ 37%] tests/test_astroid_utils.py ............................................ [ 51%] ........................................................................ [ 74%] ........................................................................ [ 97%] ..... [ 99%] tests/test_integration.py ... [100%] =================================== FAILURES =================================== ________________________ TestPy3Module.test_annotations ________________________ self = parse = .parser at 0x7f83d23f71c0> def test_annotations(self, parse): example_file = parse("_build/html/autoapi/example/index.html") software = example_file.find(id="example.software") assert software software_value = software.find(class_="property").contents[-1] assert software_value.text.endswith('''"sphin'x"''') more_software = example_file.find(id="example.more_software") assert more_software more_software_value = more_software.find(class_="property").contents[-1] assert more_software_value.text.endswith("""'sphinx"autoapi'""") interesting = example_file.find(id="example.interesting_string") assert interesting interesting_value = interesting.find(class_="property").contents[-1] assert interesting_value.text.endswith("'interesting\"fun\\'\\\\\\'string'") code_snippet = example_file.find(id="example.code_snippet") assert code_snippet code_snippet_value = code_snippet.find(class_="property").contents[-1] assert code_snippet_value.text == "Multiline-String" max_rating = example_file.find(id="example.max_rating") assert max_rating max_rating_value = max_rating.find_all(class_="property") assert max_rating_value[0].text == ": int" assert max_rating_value[1].text == " = 10" # TODO: This should either not have a value # or should display the value as part of the type declaration. # This prevents setting warningiserror. assert example_file.find(id="example.is_valid") ratings = example_file.find(id="example.ratings") assert ratings ratings_value = ratings.find_all(class_="property") > assert "List[int]" in ratings_value[0].text E assert 'List[int]' in ': list[int]' E + where ': list[int]' = : list[int].text /home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.2/tests/python/test_pyintegration.py:312: AssertionError ________________ TestAnnotationCommentsModule.test_integration _________________ self = parse = .parser at 0x7f83d20c5ab0> def test_integration(self, parse): example_file = parse("_build/html/autoapi/example/index.html") max_rating = example_file.find(id="example.max_rating") assert max_rating max_rating_value = max_rating.find_all(class_="property") assert max_rating_value[0].text == ": int" assert max_rating_value[1].text == " = 10" ratings = example_file.find(id="example.ratings") assert ratings ratings_value = ratings.find_all(class_="property") assert "List[int]" in ratings_value[0].text rating_names = example_file.find(id="example.rating_names") assert rating_names rating_names_value = rating_names.find_all(class_="property") assert "Dict[int, str]" in rating_names_value[0].text f = example_file.find(id="example.f") assert f assert f.find(class_="sig-param").text == "start: int" > assert f.find(class_="sig-return-typehint").text == "Iterable[int]" E AssertionError: assert 'collections....Iterable[int]' == 'Iterable[int]' E E - Iterable[int] E + collections.abc.Iterable[int] /home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.2/tests/python/test_pyintegration.py:472: AssertionError ---------------------------- Captured stdout setup ----------------------------- Running Sphinx v7.3.7 making output directory... done [AutoAPI] Reading files... [100%] /home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.2/tests/python/pyannotationcommentsexample/example/example.py [AutoAPI] Mapping Data... [100%] /home/tkloczko/rpmbuild/BUILD/sphinx-autoapi-3.1.2/tests/python/pyannotationcommentsexample/example/example.py [AutoAPI] Rendering Data... [100%] example [autosummary] generating autosummary for: index.rst building [mo]: targets for 0 po files that are out of date writing output... building [html]: targets for 1 source files that are out of date updating environment: [new config] 3 added, 0 changed, 0 removed reading sources... [ 33%] autoapi/example/index reading sources... [ 67%] autoapi/index reading sources... [100%] index looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done copying assets... copying static files... done copying extra files... done done writing output... [ 33%] autoapi/example/index writing output... [ 67%] autoapi/index writing output... [100%] index generating indices... genindex py-modindex done writing additional pages... search done dumping search index in English (code: en)... done dumping object inventory... done build succeeded. The HTML pages are in _build/html. =========================== short test summary info ============================ SKIPPED [1] tests/python/test_pyintegration.py:603: PEP-695 support requires Python >=3.12 FAILED tests/python/test_pyintegration.py::TestPy3Module::test_annotations - ... FAILED tests/python/test_pyintegration.py::TestAnnotationCommentsModule::test_integration ================== 2 failed, 309 passed, 1 skipped in 28.32s =================== ```