Skip to content

Commit 82f5986

Browse files
authored
capture: re-order classes (pytest-dev#6768)
This better reflects the inheritance / smartness with regard to raw or encoded. - FDCaptureBinary - FDCapture - SysCaptureBinary - SysCapture - TeeSysCapture
1 parent fb16d3e commit 82f5986

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

src/_pytest/capture.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ def snap(self):
621621
return res
622622

623623

624-
class SysCapture:
624+
class SysCaptureBinary:
625625

626-
EMPTY_BUFFER = str()
626+
EMPTY_BUFFER = b""
627627
_state = None
628628

629629
def __init__(self, fd, tmpfile=None):
@@ -651,7 +651,7 @@ def start(self):
651651
self._state = "started"
652652

653653
def snap(self):
654-
res = self.tmpfile.getvalue()
654+
res = self.tmpfile.buffer.getvalue()
655655
self.tmpfile.seek(0)
656656
self.tmpfile.truncate()
657657
return res
@@ -675,6 +675,16 @@ def writeorg(self, data):
675675
self._old.flush()
676676

677677

678+
class SysCapture(SysCaptureBinary):
679+
EMPTY_BUFFER = str() # type: ignore[assignment] # noqa: F821
680+
681+
def snap(self):
682+
res = self.tmpfile.getvalue()
683+
self.tmpfile.seek(0)
684+
self.tmpfile.truncate()
685+
return res
686+
687+
678688
class TeeSysCapture(SysCapture):
679689
def __init__(self, fd, tmpfile=None):
680690
name = patchsysdict[fd]
@@ -688,17 +698,6 @@ def __init__(self, fd, tmpfile=None):
688698
self.tmpfile = tmpfile
689699

690700

691-
class SysCaptureBinary(SysCapture):
692-
# Ignore type because it doesn't match the type in the superclass (str).
693-
EMPTY_BUFFER = b"" # type: ignore
694-
695-
def snap(self):
696-
res = self.tmpfile.buffer.getvalue()
697-
self.tmpfile.seek(0)
698-
self.tmpfile.truncate()
699-
return res
700-
701-
702701
map_fixname_class = {
703702
"capfd": FDCapture,
704703
"capfdbinary": FDCaptureBinary,

0 commit comments

Comments
 (0)