Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/robotremoteserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,28 @@ def _handle_binary(self, arg):
return arg


class StreamDuplicator(StringIO):
"""
Duplicate stream to stream given as parameter and internal StringIO.
"""

def __init__(self, stream):
self.other_stream = stream
super(StreamDuplicator, self).__init__()

def write(self, s):
self.other_stream.write(s)
return super(StreamDuplicator, self).write(s)


class StandardStreamInterceptor(object):

def __init__(self):
self.output = ''
self.origout = sys.stdout
self.origerr = sys.stderr
sys.stdout = StringIO()
sys.stderr = StringIO()
sys.stdout = StreamDuplicator(self.origout)
sys.stderr = StreamDuplicator(self.origerr)

def __enter__(self):
return self
Expand Down
3 changes: 2 additions & 1 deletion test/utest/test_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def _run_remote_keyword(self, uri):
sys.stdout = StringIO()
try:
self.assertEqual(Remote(uri).run_keyword('kw', (), None), 42)
self.assertEqual(sys.stdout.getvalue(), 'The message!\n')
# Duplication of 'The message!\n' is expected as test and RobotRemoteServer run in same process.
self.assertEqual(sys.stdout.getvalue(), 'The message!\nThe message!\n')
finally:
sys.stdout.close()
sys.stdout = origout
Expand Down