python: Reformat with Black, except quotes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:19:30 -08:00
committed by Tim Abbott
parent 5028c081cb
commit 11741543da
817 changed files with 44952 additions and 24860 deletions

View File

@@ -8,30 +8,25 @@ from typing import Iterable, Optional, Type, cast
class ExtraConsoleOutputInTestException(Exception):
pass
class ExtraConsoleOutputFinder:
def __init__(self) -> None:
self.latest_test_name = ""
valid_line_patterns = [
# Example: Running zerver.tests.test_attachments.AttachmentsTests.test_delete_unauthenticated
"^Running ",
# Example: ** Test is TOO slow: analytics.tests.test_counts.TestRealmActiveHumans.test_end_to_end (0.581 s)
"^\\*\\* Test is TOO slow: ",
"^----------------------------------------------------------------------",
# Example: INFO: URL coverage report is in var/url_coverage.txt
"^INFO: URL coverage report is in",
# Example: INFO: Try running: ./tools/create-test-api-docs
"^INFO: Try running:",
# Example: -- Running tests in parallel mode with 4 processes
"^-- Running tests in",
"^OK",
# Example: Ran 2139 tests in 115.659s
"^Ran [0-9]+ tests in",
# Destroying test database for alias 'default'...
"^Destroying test database for alias ",
"^Using existing clone",
@@ -55,12 +50,15 @@ class ExtraConsoleOutputFinder:
if found_extra_output:
self.full_extra_output += f'{line}\n'
class TeeStderrAndFindExtraConsoleOutput():
class TeeStderrAndFindExtraConsoleOutput:
def __init__(self, extra_output_finder: ExtraConsoleOutputFinder) -> None:
self.stderr_stream = sys.stderr
# get shared console handler instance from any logger that have it
self.console_log_handler = cast(logging.StreamHandler, logging.getLogger('django.server').handlers[0])
self.console_log_handler = cast(
logging.StreamHandler, logging.getLogger('django.server').handlers[0]
)
assert isinstance(self.console_log_handler, logging.StreamHandler)
assert self.console_log_handler.stream == sys.stderr
@@ -70,9 +68,12 @@ class TeeStderrAndFindExtraConsoleOutput():
sys.stderr = self # type: ignore[assignment] # Doing tee by swapping stderr stream with custom file like class
self.console_log_handler.stream = self # type: ignore[assignment] # Doing tee by swapping stderr stream with custom file like class
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType]) -> None:
def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType],
) -> None:
sys.stderr = self.stderr_stream
self.console_log_handler.stream = sys.stderr
@@ -88,7 +89,8 @@ class TeeStderrAndFindExtraConsoleOutput():
def flush(self) -> None:
self.stderr_stream.flush()
class TeeStdoutAndFindExtraConsoleOutput():
class TeeStdoutAndFindExtraConsoleOutput:
def __init__(self, extra_output_finder: ExtraConsoleOutputFinder) -> None:
self.stdout_stream = sys.stdout
self.extra_output_finder = extra_output_finder
@@ -96,9 +98,12 @@ class TeeStdoutAndFindExtraConsoleOutput():
def __enter__(self) -> None:
sys.stdout = self # type: ignore[assignment] # Doing tee by swapping stderr stream with custom file like class
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType]) -> None:
def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType],
) -> None:
sys.stdout = self.stdout_stream
def write(self, data: str) -> None: