Unverified Commit 94a0b07d authored by Richard Si's avatar Richard Si Committed by GitHub
Browse files

Remove useless flake8 config + test support code (#2221)

We've depended on Click 7.x ever since we broke CI systems across the
world (oops lol) and flake8-mypy was purged a fair bit back: #1867

Also remove the primer tests import in tests/test_black.py because it's
annoying when just trying to actually target tests/test_black.py tests.
`pytest -k test_black.py` doesn't do what you expect due to that import.
parent 53d9bace
Loading
Loading
Loading
Loading
+0 −4
Changes for .flake8: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -5,7 +5,3 @@ extend-ignore = E203, E266, E501
max-line-length = 80
max-complexity = 18
select = B,C,E,F,W,T4,B9
# We need to configure the mypy.ini because the flake8-mypy's default
# options don't properly override it, so if we don't specify it we get
# half of the config from mypy.ini and half from flake8-mypy.
mypy_config = mypy.ini
+7 −28
Changes for tests/test_black.py: 7 added lines, 28 removed lines.
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
from contextlib import contextmanager
from dataclasses import replace
import inspect
from io import BytesIO, TextIOWrapper
from io import BytesIO
import os
from pathlib import Path
from platform import system
@@ -16,10 +16,8 @@
import types
from typing import (
    Any,
    BinaryIO,
    Callable,
    Dict,
    Generator,
    List,
    Iterator,
    TypeVar,
@@ -52,7 +50,6 @@
    ff,
    dump_to_stderr,
)
from .test_primer import PrimerCLITests  # noqa: F401


THIS_FILE = Path(__file__)
@@ -104,28 +101,10 @@ def __init__(self) -> None:


class BlackRunner(CliRunner):
    """Modify CliRunner so that stderr is not merged with stdout.

    This is a hack that can be removed once we depend on Click 7.x"""
    """Make sure STDOUT and STDERR are kept seperate when testing Black via its CLI."""

    def __init__(self) -> None:
        self.stderrbuf = BytesIO()
        self.stdoutbuf = BytesIO()
        self.stdout_bytes = b""
        self.stderr_bytes = b""
        super().__init__()

    @contextmanager
    def isolation(self, *args: Any, **kwargs: Any) -> Generator[BinaryIO, None, None]:
        with super().isolation(*args, **kwargs) as output:
            try:
                hold_stderr = sys.stderr
                sys.stderr = TextIOWrapper(self.stderrbuf, encoding=self.charset)
                yield output
            finally:
                self.stdout_bytes = sys.stdout.buffer.getvalue()  # type: ignore
                self.stderr_bytes = sys.stderr.buffer.getvalue()  # type: ignore
                sys.stderr = hold_stderr
        super().__init__(mix_stderr=False)


class BlackTestCase(BlackBaseTestCase):
@@ -141,8 +120,8 @@ def invokeBlack(
            exit_code,
            msg=(
                f"Failed with args: {args}\n"
                f"stdout: {runner.stdout_bytes.decode()!r}\n"
                f"stderr: {runner.stderr_bytes.decode()!r}\n"
                f"stdout: {result.stdout_bytes.decode()!r}\n"
                f"stderr: {result.stderr_bytes.decode()!r}\n"
                f"exception: {result.exception}"
            ),
        )
@@ -483,7 +462,7 @@ def test_python2_should_fail_without_optional_install(self) -> None:
        finally:
            os.unlink(tmp_file)
        actual = (
            runner.stderr_bytes.decode()
            result.stderr_bytes.decode()
            .replace("\n", "")
            .replace("\\n", "")
            .replace("\\r", "")
@@ -1806,7 +1785,7 @@ def test_preserves_line_endings_via_stdin(self) -> None:
                black.main, ["-", "--fast"], input=BytesIO(contents.encode("utf8"))
            )
            self.assertEqual(result.exit_code, 0)
            output = runner.stdout_bytes
            output = result.stdout_bytes
            self.assertIn(nl.encode("utf8"), output)
            if nl == "\n":
                self.assertNotIn(b"\r\n", output)