Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#63: Implement fileno(), so the StandardOutputReplication() could mor…
Browse files Browse the repository at this point in the history
…e realistic look
  • Loading branch information
blackandred committed Dec 7, 2020
1 parent 192cbd9 commit 3aa1f31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions rkd/api/inputoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@

class StandardOutputReplication(object):
_out_streams: list
_fileno: int

def __init__(self, out_streams: list):
def __init__(self, out_streams: list, fileno: int = None):
self._out_streams = out_streams
self._fileno = fileno

def write(self, buf):
for stream in self._out_streams:
Expand All @@ -60,7 +62,7 @@ def write(self, buf):
self.flush()

def fileno(self):
return 1
return self._fileno

def flush(self):
pass
Expand Down Expand Up @@ -113,8 +115,8 @@ def capture_descriptors(self, target_files: List[str] = None, stream=None, enabl
outputs_stderr.append(stream)

# 4. Mock
sys.stdout = StandardOutputReplication(outputs_stdout)
sys.stderr = StandardOutputReplication(outputs_stderr)
sys.stdout = StandardOutputReplication(outputs_stdout, sys.stdout.fileno())
sys.stderr = StandardOutputReplication(outputs_stderr, sys.stderr.fileno())

# 5. Action!
yield
Expand Down
4 changes: 2 additions & 2 deletions test/test_inputoutput_standardoutputreplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_writing_to_multiple_streams_of_different_types(self):
bytes_io = BytesIO()
str_io = StringIO()

out = StandardOutputReplication([bytes_io, str_io])
out = StandardOutputReplication([bytes_io, str_io], 1)
out.write('12 June 1963 Medgar Wiley Evers, African American civil rights activist from Mississippi')
out.write(' was shot in the back and killed by a member of the White Citizens\' Council.')

Expand All @@ -28,7 +28,7 @@ def test_non_printable_is_converted_to_string_like_print_does(self):

str_io = StringIO()

out = StandardOutputReplication([str_io])
out = StandardOutputReplication([str_io], 1)
out.write(unittest)

self.assertIn("<module 'unittest'", str_io.getvalue())

0 comments on commit 3aa1f31

Please sign in to comment.