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

Tests fail with Python 3.12 #274

Open
stefanor opened this issue Jan 20, 2024 · 2 comments · May be fixed by #296
Open

Tests fail with Python 3.12 #274

stefanor opened this issue Jan 20, 2024 · 2 comments · May be fixed by #296
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: bug PEP 257 violation or existing functionality that doesn't work as documented U: medium A relatively medium urgency issue

Comments

@stefanor
Copy link

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 (504107b):

==================================== 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)
@github-actions github-actions bot added the fresh This is a new issue label Jan 20, 2024
@s3v-
Copy link

s3v- commented Jan 29, 2024

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



Kind Regards

@weibullguy weibullguy added P: bug PEP 257 violation or existing functionality that doesn't work as documented C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) and removed fresh This is a new issue labels Jan 30, 2024
@github-actions github-actions bot added U: medium A relatively medium urgency issue labels Jan 30, 2024
@finswimmer
Copy link

I discovered this when working on #296 as well.

As far as I could debug it, it looks that something has changed (fixed?) in the ast parsing 🤷‍♂ Removing the whitespaces should be fine, because they don't really belong to the string under test.

@finswimmer finswimmer linked a pull request Nov 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: bug PEP 257 violation or existing functionality that doesn't work as documented U: medium A relatively medium urgency issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants