From: Richard Si <63936253+ichard26@users.noreply.github.com> Date: Tue, 11 May 2021 18:09:33 +0000 (-0400) Subject: Remove useless flake8 config + test support code (#2221) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/94a0b07dbebabe344991dc27f9eb0b11597bb3b5?ds=inline 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. --- diff --git a/.flake8 b/.flake8 index 68d1501..4866133 100644 --- a/.flake8 +++ b/.flake8 @@ -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 diff --git a/tests/test_black.py b/tests/test_black.py index 347eaf6..4cbb022 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -6,7 +6,7 @@ from concurrent.futures import ThreadPoolExecutor 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 @@ from tempfile import TemporaryDirectory import types from typing import ( Any, - BinaryIO, Callable, Dict, - Generator, List, Iterator, TypeVar, @@ -52,7 +50,6 @@ from tests.util import ( ff, dump_to_stderr, ) -from .test_primer import PrimerCLITests # noqa: F401 THIS_FILE = Path(__file__) @@ -104,28 +101,10 @@ class FakeParameter(click.Parameter): 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 @@ class BlackTestCase(BlackBaseTestCase): 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 @@ class BlackTestCase(BlackBaseTestCase): finally: os.unlink(tmp_file) actual = ( - runner.stderr_bytes.decode() + result.stderr_bytes.decode() .replace("\n", "") .replace("\\n", "") .replace("\\r", "") @@ -1806,7 +1785,7 @@ class BlackTestCase(BlackBaseTestCase): 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)