diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-29 09:34:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-29 09:34:25 +0000 |
commit | 2ee9e61602b53a25db056d99ea0308b245120c03 (patch) | |
tree | 5fc6890331d99ec0f2ba060b90cc68ea62f714f1 /tests/conftest.py | |
parent | Adding upstream version 3.7.1. (diff) | |
download | pre-commit-2ee9e61602b53a25db056d99ea0308b245120c03.tar.xz pre-commit-2ee9e61602b53a25db056d99ea0308b245120c03.zip |
Adding upstream version 3.8.0.upstream/3.8.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/conftest.py')
-rw-r--r-- | tests/conftest.py | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 3076171..bd4af9a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -209,36 +209,25 @@ def log_info_mock(): yield mck -class FakeStream: - def __init__(self): - self.data = io.BytesIO() - - def write(self, s): - self.data.write(s) - - def flush(self): - pass - - class Fixture: - def __init__(self, stream): + def __init__(self, stream: io.BytesIO) -> None: self._stream = stream - def get_bytes(self): + def get_bytes(self) -> bytes: """Get the output as-if no encoding occurred""" - data = self._stream.data.getvalue() - self._stream.data.seek(0) - self._stream.data.truncate() + data = self._stream.getvalue() + self._stream.seek(0) + self._stream.truncate() return data.replace(b'\r\n', b'\n') - def get(self): + def get(self) -> str: """Get the output assuming it was written as UTF-8 bytes""" return self.get_bytes().decode() @pytest.fixture def cap_out(): - stream = FakeStream() + stream = io.BytesIO() write = functools.partial(output.write, stream=stream) write_line_b = functools.partial(output.write_line_b, stream=stream) with mock.patch.multiple(output, write=write, write_line_b=write_line_b): |