From 82f5986424aad0fc4a1d560bff9d25876e8bb9d9 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 20 Feb 2020 11:00:19 +0100 Subject: [PATCH] capture: re-order classes (#6768) This better reflects the inheritance / smartness with regard to raw or encoded. - FDCaptureBinary - FDCapture - SysCaptureBinary - SysCapture - TeeSysCapture --- src/_pytest/capture.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 54c084205..3643d782d 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -621,9 +621,9 @@ class FDCapture(FDCaptureBinary): return res -class SysCapture: +class SysCaptureBinary: - EMPTY_BUFFER = str() + EMPTY_BUFFER = b"" _state = None def __init__(self, fd, tmpfile=None): @@ -651,7 +651,7 @@ class SysCapture: self._state = "started" def snap(self): - res = self.tmpfile.getvalue() + res = self.tmpfile.buffer.getvalue() self.tmpfile.seek(0) self.tmpfile.truncate() return res @@ -675,6 +675,16 @@ class SysCapture: self._old.flush() +class SysCapture(SysCaptureBinary): + EMPTY_BUFFER = str() # type: ignore[assignment] # noqa: F821 + + def snap(self): + res = self.tmpfile.getvalue() + self.tmpfile.seek(0) + self.tmpfile.truncate() + return res + + class TeeSysCapture(SysCapture): def __init__(self, fd, tmpfile=None): name = patchsysdict[fd] @@ -688,17 +698,6 @@ class TeeSysCapture(SysCapture): self.tmpfile = tmpfile -class SysCaptureBinary(SysCapture): - # Ignore type because it doesn't match the type in the superclass (str). - EMPTY_BUFFER = b"" # type: ignore - - def snap(self): - res = self.tmpfile.buffer.getvalue() - self.tmpfile.seek(0) - self.tmpfile.truncate() - return res - - map_fixname_class = { "capfd": FDCapture, "capfdbinary": FDCaptureBinary,