PyCQA / docformatter

Formats docstrings to follow PEP 257
https://pypi.python.org/pypi/docformatter
MIT License
524 stars 61 forks source link

Tests fail with Python 3.12 #274

Open stefanor opened 5 months ago

stefanor commented 5 months ago

Debian has started transitioning to add support for Python 3.12, and docformatter's tests fail. See: Debian bug #1056469.

That was on 1.7.5, and I can't reproduce those failures exactly under your tox. But I do get these failures on the current git HEAD (504107bdc4618f83a3378faac610e02cd62ef5f9):

==================================== test session starts =====================================
platform linux -- Python 3.12.1, pytest-7.4.4, pluggy-1.3.0
cachedir: .tox/py312/.pytest_cache
rootdir: /tmp/docformatter
configfile: pyproject.toml
plugins: cov-4.1.0
collected 277 items / 41 deselected / 236 selected                                           

tests/test_configuration_functions.py ....................
tests/test_encoding_functions.py ............
tests/test_string_functions.py ...............................
tests/test_strip_docstring.py ........
tests/test_syntax_functions.py ......
tests/test_utility_functions.py .........................................
tests/formatter/test_do_format_code.py ..FFF.............
tests/formatter/test_do_format_docstring.py ..............
tests/formatter/test_format_black.py ...
tests/formatter/test_format_code.py ............................
tests/formatter/test_format_code_ranges.py ...
tests/formatter/test_format_epytext.py ..
tests/formatter/test_format_lists.py .....
tests/formatter/test_format_sphinx.py ..........
tests/formatter/test_format_styles.py ....
tests/formatter/test_format_urls.py .................
tests/formatter/test_format_wrap.py ..............

========================================== FAILURES ==========================================
______ TestDoFormatCode.test_format_code_strip_blank_line_after_module_variable[args0] _______

self = <tests.formatter.test_do_format_code.TestDoFormatCode object at 0x7f57dda00b30>
test_args = Namespace(in_place=False, check=False, recursive=False, exclude=None, non_cap=None, style='sphinx', rest_section_adorn...ne=False, close_quotes_on_newline=False, line_range=None, length_range=None, non_strict=False, config=None, files=[''])
args = ['']

    @pytest.mark.unit
    @pytest.mark.parametrize("args", [[""]])
    def test_format_code_strip_blank_line_after_module_variable(
        self,
        test_args,
        args,
    ):
        """Strip newlines between module variable definition and docstring."""
        uut = Formatter(
            test_args,
            sys.stderr,
            sys.stdin,
            sys.stdout,
        )

        instring = self.TEST_STRINGS["newline_module_variable"]["instring"]
        outstring = self.TEST_STRINGS["newline_module_variable"]["outstring"]

>       assert outstring == uut._do_format_code(
            instring,
        )
E       assert '    CONST = ...r CONST."""\n' == '    CONST = ...NST."""\n    '
E         Skipping 36 identical leading characters in diff, use -v to show
E            CONST."""
E         -

tests/formatter/test_do_format_code.py:108: AssertionError
__________________ TestDoFormatCode.test_format_code_class_docstring[args0] __________________

self = <tests.formatter.test_do_format_code.TestDoFormatCode object at 0x7f57dda00d10>
test_args = Namespace(in_place=False, check=False, recursive=False, exclude=None, non_cap=None, style='sphinx', rest_section_adorn...ne=False, close_quotes_on_newline=False, line_range=None, length_range=None, non_strict=False, config=None, files=[''])
args = ['']

    @pytest.mark.unit
    @pytest.mark.parametrize("args", [[""]])
    def test_format_code_class_docstring(self, test_args, args):
        """Format class docstring."""
        uut = Formatter(
            test_args,
            sys.stderr,
            sys.stdin,
            sys.stdout,
        )

        instring = self.TEST_STRINGS["class_docstring"]["instring"]
        outstring = self.TEST_STRINGS["class_docstring"]["outstring"]

>       assert outstring == uut._do_format_code(
            instring,
        )
E       assert '    class Te...        """\n' == '    class Te...    """\n    '
E         Skipping 138 identical leading characters in diff, use -v to show
E                  """
E         -

tests/formatter/test_do_format_code.py:126: AssertionError
_______ TestDoFormatCode.test_format_code_strip_blank_line_after_class_variable[args0] _______

self = <tests.formatter.test_do_format_code.TestDoFormatCode object at 0x7f57dda00ef0>
test_args = Namespace(in_place=False, check=False, recursive=False, exclude=None, non_cap=None, style='sphinx', rest_section_adorn...ne=False, close_quotes_on_newline=False, line_range=None, length_range=None, non_strict=False, config=None, files=[''])
args = ['']

    @pytest.mark.unit
    @pytest.mark.parametrize("args", [[""]])
    def test_format_code_strip_blank_line_after_class_variable(
        self,
        test_args,
        args,
    ):
        """Strip any newlines between a class variable definition and docstring.

        See requirement .
        """
        uut = Formatter(
            test_args,
            sys.stderr,
            sys.stdin,
            sys.stdout,
        )

        instring = self.TEST_STRINGS["newline_class_variable"]["instring"]
        outstring = self.TEST_STRINGS["newline_class_variable"]["outstring"]

>       assert outstring == uut._do_format_code(
            instring,
        )
E       assert '    class Te...cstring."""\n' == '    class Te...ing."""\n    '
E         Skipping 203 identical leading characters in diff, use -v to show
E           string."""
E         -

tests/formatter/test_do_format_code.py:151: AssertionError

---------- coverage: platform linux, python 3.12.1-final-0 -----------
Name                                Stmts   Miss Branch BrPart  Cover   Missing
-------------------------------------------------------------------------------
src/docformatter/__main__.py           20     15      8      1    21%   39, 114-134, 140-144, 155
src/docformatter/__pkginfo__.py         2      0      0      0   100%
src/docformatter/configuration.py      99      2     40      6    94%   47, 89->94, 90->89, 325->329, 348, 349->346, 353->exit
src/docformatter/encode.py             29      2     10      0    95%   64-65
src/docformatter/format.py            178     47     83      2    71%   222-242, 252-271, 286-321, 467, 473
src/docformatter/strings.py            67      0     35      0   100%
src/docformatter/syntax.py            193      4     94      5    97%   551, 758->exit, 778, 931, 976
src/docformatter/util.py               28      1     18      1    96%   86
-------------------------------------------------------------------------------
TOTAL                                 616     71    288     15    87%

================================== short test summary info ===================================
FAILED tests/formatter/test_do_format_code.py::TestDoFormatCode::test_format_code_strip_blank_line_after_module_variable[args0] - assert '    CONST = ...r CONST."""\n' == '    CONST = ...NST."""\n    '
FAILED tests/formatter/test_do_format_code.py::TestDoFormatCode::test_format_code_class_docstring[args0] - assert '    class Te...        """\n' == '    class Te...    """\n    '
FAILED tests/formatter/test_do_format_code.py::TestDoFormatCode::test_format_code_strip_blank_line_after_class_variable[args0] - assert '    class Te...cstring."""\n' == '    class Te...ing."""\n    '
======================== 3 failed, 233 passed, 41 deselected in 1.15s ========================
py312: exit 1 (1.40 seconds) /tmp/docformatter> pytest -s -c /tmp/docformatter/pyproject.toml -m unit --cache-clear --cov=docformatter --cov-config=/tmp/docformatter/pyproject.toml --cov-branch /tmp/docformatter/tests/ pid=682397
  py312: FAIL code 1 (4.45=setup[0.05]+cmd[0.83,2.18,1.40] seconds)
  evaluation failed :( (4.52 seconds)
s3v- commented 5 months ago

Hi, Removing leading blank spaces from lines below solves the issue but I don't know whether they are intended.

https://github.com/PyCQA/docformatter/blob/504107bdc4618f83a3378faac610e02cd62ef5f9/tests/_data/string_files/do_format_code.toml#L40 https://github.com/PyCQA/docformatter/blob/504107bdc4618f83a3378faac610e02cd62ef5f9/tests/_data/string_files/do_format_code.toml#L53 https://github.com/PyCQA/docformatter/blob/504107bdc4618f83a3378faac610e02cd62ef5f9/tests/_data/string_files/do_format_code.toml#L77

Kind Regards