Skip to content

[self tests] test_codemod_formatter_error_input fails with black 25.9.0 #1423

@stanislavlevin

Description

@stanislavlevin

test_codemod_formatter_error_input fails with black 25.9.0:

FAIL: test_codemod_formatter_error_input (codemod.tests.test_codemod_cli.TestCodemodCLI.test_codemod_formatter_error_input)
----------------------------------------------------------------------           
Traceback (most recent call last):                                                  
  File "/usr/src/RPM/BUILD/python3-module-libcst-1.8.5/libcst/codemod/tests/test_codemod_cli.py", line 39, in test_codemod_formatter_error_input
    self.assertIn(                                                               
    ~~~~~~~~~~~~~^                                                               
        "error: cannot format -: Cannot parse for target version Python 3.6: 13:10:     async with AsyncExitStack() as stack:",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        rlt.stderr.decode("utf-8"),                                              
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                              
    )                                                                            
    ^                                                                            
AssertionError: 'error: cannot format -: Cannot parse for target version Python 3.6: 13:10:     async with AsyncExitStack() as stack:' not found in 'Calculating full-repo metadata...\nExecuting codemod...\nAll done! ✨ 🍰 ✨\n1 file left unchanged.\n\r\x1b[2K0.28s 0% complete, [calculating] estimated for 1 files to go...\r\x1b[2KFinished codemodding 1 files!\n - Transformed 1 files successfully.\n - Skipped 0 files.\n - Failed to codemod 0 files.\n - 0 warnings were generated.\n'

This test checks the error message in case of source having syntax error.
But https://black.readthedocs.io/en/stable/faq.html#why-does-black-not-detect-syntax-errors-in-my-code

Black is an autoformatter, not a Python linter or interpreter. Detecting
all syntax errors is not a goal. It can format all code accepted by
CPython (if you find an example where that doesn’t hold, please report a
bug!), but it may also format some code that CPython doesn’t accept.

With black < 25.9.0:

$ black --check -t py36 ./lib/python3/site-packages/libcst/codemod/tests/codemod_formatter_error_input.py.txt
error: cannot format lib/python3/site-packages/libcst/codemod/tests/codemod_formatter_error_input.py.txt: Cannot parse for target version Python 3.6: 13:10:     async with AsyncExitStack() as stack:
                                                                                 
Oh no! 💥 💔 💥                                                                  
1 file would fail to reformat.                                                   

black 25.9.0:

$ black --check -t py36 ./lib/python3/site-packages/libcst/codemod/tests/codemod_formatter_error_input.py.txt
All done! ✨ 🍰 ✨                                                                  
1 file would be left unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions