Revision: 74bbd314feae
Branch: default
Author: Pekka Klärck
Date: Tue Jun 10 08:45:07 2014 UTC
Log: Process: Fixed reading standard streams if they are already
closed.
Update issue 1700
Earlier implementation did not take into account that standard streams may
have been closed externally.
http://code.google.com/p/robotframework/source/detail?r=74bbd314feae
Modified:
/atest/robot/standard_libraries/process/stdout_and_stderr.txt
/atest/testdata/standard_libraries/process/stdout_and_stderr.txt
/src/robot/libraries/Process.py
=======================================
--- /atest/robot/standard_libraries/process/stdout_and_stderr.txt Tue Jan
28 23:10:45 2014 UTC
+++ /atest/robot/standard_libraries/process/stdout_and_stderr.txt Tue Jun
10 08:45:07 2014 UTC
@@ -39,3 +39,6 @@
Run multiple times using custom streams
Check Test Case ${TESTNAME}
+
+Read standard streams when they are already closed externally
+ Check Test Case ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/process/stdout_and_stderr.txt Tue
May 20 08:20:51 2014 UTC
+++ /atest/testdata/standard_libraries/process/stdout_and_stderr.txt Tue
Jun 10 08:45:07 2014 UTC
@@ -61,6 +61,20 @@
:FOR ${i} IN RANGE 500
\ Run And Test Once ${i} ${STDOUT} ${STDERR}
+Read standard streams when they are already closed externally
+ ${code} = Catenate SEPARATOR=;
+ ... import sys
+ ... message = raw_input()
+ ... sys.stdout.write('%s out' % message)
+ ... sys.stderr.write('%s err' % message)
+ Start Python Process ${code}
+ ${process} = Get Process Object
+ ${stdout} ${stderr} = Call Method ${process}
communicate hi\n
+ Should Be Equal ${stdout}--${stderr} hi out--hi err
+ Should Be True ${process.stdout.closed}
+ Should Be True ${process.stderr.closed}
+ ${result} = Wait For Process
+ Should Be Equal ${result.stdout}--${result.stderr} --
*** Keywords ***
Run Stdout Stderr Process
=======================================
--- /src/robot/libraries/Process.py Tue May 20 08:20:51 2014 UTC
+++ /src/robot/libraries/Process.py Tue Jun 10 08:45:07 2014 UTC
@@ -767,12 +767,17 @@
def _read_stream(self, stream_path, stream):
if stream_path:
stream = open(stream_path, 'r')
+ elif not self._is_open(stream):
+ return ''
try:
- return self._format_output(stream.read() if stream else '')
+ return self._format_output(stream.read())
finally:
if stream_path:
stream.close()
+ def _is_open(self, stream):
+ return stream and not stream.closed
+
def _format_output(self, output):
if output.endswith('\n'):
output = output[:-1]
@@ -781,8 +786,7 @@
def close_streams(self):
standard_streams =
self._get_and_read_standard_streams(self._process)
for stream in standard_streams + self._custom_streams:
- if stream and not stream.closed:
- stream.flush()
+ if self._is_open(stream):
stream.close()
def _get_and_read_standard_streams(self, process):
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.