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

[self tests] test_black_pyi_file fails with black 24.2.0 #2233

Open
stanislavlevin opened this issue Feb 15, 2024 · 0 comments
Open

[self tests] test_black_pyi_file fails with black 24.2.0 #2233

stanislavlevin opened this issue Feb 15, 2024 · 0 comments

Comments

@stanislavlevin
Copy link

stanislavlevin commented Feb 15, 2024

_____________________________ test_black_pyi_file ______________________________

    def test_black_pyi_file():
        """Test consistent code formatting between isort and black for `.pyi` files.
    
        black only allows no more than two consecutive blank lines in a `.pyi` file.
        """
    
>       black_test(
            """# comment     


    import math
    
    from typing import Sequence
    import numpy as np
    
    
    def add(a: np.ndarray, b: np.ndarray) -> np.ndarray:
        ...
    
    
    def sub(a: np.ndarray, b: np.ndarray) -> np.ndarray:
        ...
    """,
            """# comment
    
    
    import math
    from typing import Sequence
    
    import numpy as np
    
    
    def add(a: np.ndarray, b: np.ndarray) -> np.ndarray:
        ...
    
    
    def sub(a: np.ndarray, b: np.ndarray) -> np.ndarray:
        ...
    """,
            is_pyi=False,
            lines_before_imports=2,
            lines_after_imports=2,
        )
tests/unit/profiles/test_black.py:385: 

code = '# comment\n\n\nimport math\n\nfrom typing import Sequence\nimport numpy as np\n\n\ndef add(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n\n\ndef sub(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n'
expected_output = '# comment\n\n\nimport math\nfrom typing import Sequence\n\nimport numpy as np\n\n\ndef add(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n\n\ndef sub(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n'
is_pyi = False
config_kwargs = {'extension': None, 'lines_after_imports': 2, 'lines_before_imports': 2, 'profile': 'black'}
output = '# comment\n\n\nimport math\nfrom typing import Sequence\n\nimport numpy as np\n\n\ndef add(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n\n\ndef sub(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n'
@py_assert3 = None, @py_assert7 = None, @py_assert1 = False

    def black_test(code: str, expected_output: str = "", *, is_pyi: bool = False, **config_kwargs):
        """Tests that the given code:
        - Behaves the same when formatted multiple times with isort.
        - Agrees with black formatting.
        - Matches the desired output or itself if none is provided.
        """
        expected_output = expected_output or code
        config_kwargs = {
            "extension": "pyi" if is_pyi else None,
            "profile": "black",
            **config_kwargs,
        }
    
        # output should stay consistent over multiple runs
        output = isort.code(code, **config_kwargs)
        assert output == isort.code(code, **config_kwargs)
    
        # output should agree with black
        black_output = black_format(output, is_pyi=is_pyi)
>       assert output == black_output
E       AssertionError: assert '# comment\n\n\nimport math\nfrom typing import Sequence\n\nimport numpy as np\n\n\ndef add(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n\n\ndef sub(a: np.ndarray, b: np.ndarray) -> np.ndarray:\n    ...\n' == '# comment\n\n\nimport math\nfrom typing import Sequence\n\nimport numpy as np\n\n\ndef add(a: np.ndarray, b: np.ndarray) -> np.ndarray: ...\n\n\ndef sub(a: np.ndarray, b: np.ndarray) -> np.ndarray: ...\n'
E         
E           # comment
E           
E           
E           import math
E           from typing import Sequence
E           
E           import numpy as np
E           
E           
E         - def add(a: np.ndarray, b: np.ndarray) -> np.ndarray: ...
E         ?                                                     ----
E         + def add(a: np.ndarray, b: np.ndarray) -> np.ndarray:
E         +     ...
E           
E           
E         - def sub(a: np.ndarray, b: np.ndarray) -> np.ndarray: ...
E         ?                                                     ----
E         + def sub(a: np.ndarray, b: np.ndarray) -> np.ndarray:
E         +     ...

tests/unit/profiles/test_black.py:41: AssertionError

https://github.com/psf/black/blob/main/CHANGES.md#2410

Dummy class and function implementations consisting only of ... are formatted more compactly (#3796)

psf/black#3796
psf/black#1797 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant