Skip to content

Commit

Permalink
capture: re-order classes (#6768)
Browse files Browse the repository at this point in the history
This better reflects the inheritance / smartness with regard to raw or
encoded.

- FDCaptureBinary
- FDCapture
- SysCaptureBinary
- SysCapture
- TeeSysCapture
  • Loading branch information
blueyed committed Feb 20, 2020
1 parent fb16d3e commit 82f5986
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/_pytest/capture.py
Expand Up @@ -621,9 +621,9 @@ def snap(self):
return res


class SysCapture:
class SysCaptureBinary:

EMPTY_BUFFER = str()
EMPTY_BUFFER = b""
_state = None

def __init__(self, fd, tmpfile=None):
Expand Down Expand Up @@ -651,7 +651,7 @@ def start(self):
self._state = "started"

def snap(self):
res = self.tmpfile.getvalue()
res = self.tmpfile.buffer.getvalue()
self.tmpfile.seek(0)
self.tmpfile.truncate()
return res
Expand All @@ -675,6 +675,16 @@ def writeorg(self, data):
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]
Expand All @@ -688,17 +698,6 @@ def __init__(self, fd, tmpfile=None):
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,
Expand Down

0 comments on commit 82f5986

Please sign in to comment.