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.
This commit is contained in:
parent
53d9bace12
commit
94a0b07dbe
4
.flake8
4
.flake8
@ -5,7 +5,3 @@ extend-ignore = E203, E266, E501
|
|||||||
max-line-length = 80
|
max-line-length = 80
|
||||||
max-complexity = 18
|
max-complexity = 18
|
||||||
select = B,C,E,F,W,T4,B9
|
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
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from dataclasses import replace
|
from dataclasses import replace
|
||||||
import inspect
|
import inspect
|
||||||
from io import BytesIO, TextIOWrapper
|
from io import BytesIO
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from platform import system
|
from platform import system
|
||||||
@ -16,10 +16,8 @@
|
|||||||
import types
|
import types
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
BinaryIO,
|
|
||||||
Callable,
|
Callable,
|
||||||
Dict,
|
Dict,
|
||||||
Generator,
|
|
||||||
List,
|
List,
|
||||||
Iterator,
|
Iterator,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
@ -52,7 +50,6 @@
|
|||||||
ff,
|
ff,
|
||||||
dump_to_stderr,
|
dump_to_stderr,
|
||||||
)
|
)
|
||||||
from .test_primer import PrimerCLITests # noqa: F401
|
|
||||||
|
|
||||||
|
|
||||||
THIS_FILE = Path(__file__)
|
THIS_FILE = Path(__file__)
|
||||||
@ -104,28 +101,10 @@ def __init__(self) -> None:
|
|||||||
|
|
||||||
|
|
||||||
class BlackRunner(CliRunner):
|
class BlackRunner(CliRunner):
|
||||||
"""Modify CliRunner so that stderr is not merged with stdout.
|
"""Make sure STDOUT and STDERR are kept seperate when testing Black via its CLI."""
|
||||||
|
|
||||||
This is a hack that can be removed once we depend on Click 7.x"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.stderrbuf = BytesIO()
|
super().__init__(mix_stderr=False)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class BlackTestCase(BlackBaseTestCase):
|
class BlackTestCase(BlackBaseTestCase):
|
||||||
@ -141,8 +120,8 @@ def invokeBlack(
|
|||||||
exit_code,
|
exit_code,
|
||||||
msg=(
|
msg=(
|
||||||
f"Failed with args: {args}\n"
|
f"Failed with args: {args}\n"
|
||||||
f"stdout: {runner.stdout_bytes.decode()!r}\n"
|
f"stdout: {result.stdout_bytes.decode()!r}\n"
|
||||||
f"stderr: {runner.stderr_bytes.decode()!r}\n"
|
f"stderr: {result.stderr_bytes.decode()!r}\n"
|
||||||
f"exception: {result.exception}"
|
f"exception: {result.exception}"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -483,7 +462,7 @@ def test_python2_should_fail_without_optional_install(self) -> None:
|
|||||||
finally:
|
finally:
|
||||||
os.unlink(tmp_file)
|
os.unlink(tmp_file)
|
||||||
actual = (
|
actual = (
|
||||||
runner.stderr_bytes.decode()
|
result.stderr_bytes.decode()
|
||||||
.replace("\n", "")
|
.replace("\n", "")
|
||||||
.replace("\\n", "")
|
.replace("\\n", "")
|
||||||
.replace("\\r", "")
|
.replace("\\r", "")
|
||||||
@ -1806,7 +1785,7 @@ def test_preserves_line_endings_via_stdin(self) -> None:
|
|||||||
black.main, ["-", "--fast"], input=BytesIO(contents.encode("utf8"))
|
black.main, ["-", "--fast"], input=BytesIO(contents.encode("utf8"))
|
||||||
)
|
)
|
||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0)
|
||||||
output = runner.stdout_bytes
|
output = result.stdout_bytes
|
||||||
self.assertIn(nl.encode("utf8"), output)
|
self.assertIn(nl.encode("utf8"), output)
|
||||||
if nl == "\n":
|
if nl == "\n":
|
||||||
self.assertNotIn(b"\r\n", output)
|
self.assertNotIn(b"\r\n", output)
|
||||||
|
Loading…
Reference in New Issue
Block a user