3 new revisions:
Revision: a1c9b3fc0c38
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Tue Jun 11 04:01:23 2013
Log: process tests cleanup....
http://code.google.com/p/robotframework/source/detail?r=a1c9b3fc0c38
Revision: 059c5237a4f8
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Tue Jun 11 04:06:55 2013
Log: Process: simplified and cleand up handling stdout, stderr.
http://code.google.com/p/robotframework/source/detail?r=059c5237a4f8
Revision: 7c5ac06465cd
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Tue Jun 11 04:07:01 2013
Log: Automated merge with https://robotframework.googlecode.com/hg/
http://code.google.com/p/robotframework/source/detail?r=7c5ac06465cd
==============================================================================
Revision: a1c9b3fc0c38
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Tue Jun 11 04:01:23 2013
Log: process tests cleanup.
including:
- use %{TEMPDIR}, not ${TEMPDIR}
- avoid creating files to the execution directory
http://code.google.com/p/robotframework/source/detail?r=a1c9b3fc0c38
Modified:
/atest/testdata/standard_libraries/process/process_library.txt
/atest/testdata/standard_libraries/process/terminate_and_pid.txt
=======================================
--- /atest/testdata/standard_libraries/process/process_library.txt Tue Jun
11 01:34:12 2013
+++ /atest/testdata/standard_libraries/process/process_library.txt Tue Jun
11 04:01:23 2013
@@ -42,18 +42,18 @@
Should Not Be Equal ${result.stdout} ${result2.stdout}
Setting Stdout
- ${result}= Run Process python -c "print 'hello'"
shell=True stdout=${TEMPDIR}${/}myfile_1.txt
- ${output}= Get File ${TEMPDIR}${/}myfile_1.txt
+ ${result}= Run Process python -c "print 'hello'"
shell=True stdout=%{TEMPDIR}${/}myfile_1.txt
+ ${output}= Get File %{TEMPDIR}${/}myfile_1.txt
Should Not Be Empty ${output}
Should Match ${output} ${result.stdout}*
- [Teardown] Run Keyword And Ignore Error Remove File
${TEMPDIR}${/}myfile_1.txt
+ [Teardown] Remove File %{TEMPDIR}${/}myfile_1.txt
Setting Stderr
- ${result}= Run Process python -c "1/0" shell=True
stderr=${TEMPDIR}${/}myfile.txt
- ${output}= Get File ${TEMPDIR}${/}myfile.txt
+ ${result}= Run Process python -c "1/0" shell=True
stderr=%{TEMPDIR}${/}myfile.txt
+ ${output}= Get File %{TEMPDIR}${/}myfile.txt
Should Not Be Empty ${output}
Should Match ${output} ${result.stderr}*
- [Teardown] Run Keyword And Ignore Error Remove File
${TEMPDIR}${/}myfile.txt
+ [Teardown] Remove File %{TEMPDIR}${/}myfile.txt
Without Env Configuration the Environment Should Be As It Was
Set Environment Variable normalvar normal
@@ -122,33 +122,34 @@
Log ${result.stderr}
Redirecting Stderr to Stdout with filename
- ${result}= Run Process python -c print 'hello';1/0
stdout=filename.txt stderr=filename.txt
+ ${path}= Normalize Path %{TEMPDIR}/filename.txt
+ ${result}= Run Process python -c print 'hello';1/0
stdout=${path} stderr=${path}
Should Match ${result.stdout} *hello*
Should Match ${result.stdout} *ZeroDivisionError*
- Log ${result.stderr}
- [Teardown] Run Keyword And Ignore Error Remove File
filename.txt
+ [Teardown] Remove File ${path}
Current working directory should be used with stdout and stderr
- Create Directory ${TEMPDIR}${/}hc
- ${result}= Run Process python -c print 'moon kuu';1/0
cwd=${TEMPDIR}${/}hc stdout=myout.txt
+ Create Directory %{TEMPDIR}${/}hc
+ ${result}= Run Process python -c print 'moon kuu';1/0
cwd=%{TEMPDIR}${/}hc stdout=myout.txt
... stderr=myerr.txt
- ${output}= Get File ${TEMPDIR}${/}hc${/}myout.txt
- ${output2}= Get File ${TEMPDIR}${/}hc${/}myerr.txt
+ ${output}= Get File %{TEMPDIR}${/}hc${/}myout.txt
+ ${output2}= Get File %{TEMPDIR}${/}hc${/}myerr.txt
Should Match ${output} *moon kuu*
Should Match ${output2} *ZeroDivisionError*
- [Teardown] Run Keyword And Ignore Error Remove Directory
${TEMPDIR}${/}hc True
+ [Teardown] Remove Directory %{TEMPDIR}${/}hc recursive=True
Current working directory should not be used with stdout and stderr when
absolute path in use
- Create Directory ${TEMPDIR}${/}hc
- ${stdout_path}= Evaluate os.path.abspath('myout.txt') os
- ${result}= Run Process python -c print 'moon kuu';1/0
cwd=${TEMPDIR}${/}hc stdout=${stdout_path}
- ... stderr=myerr.txt
- ${output}= Get File ${stdout_path}
- ${output2}= Get File ${TEMPDIR}${/}hc${/}myerr.txt
- Should Match ${output} *moon kuu*
- Should Match ${output2} *ZeroDivisionError*
- Remove File ${stdout_path}
- [Teardown] Run Keyword And Ignore Error Remove Directory
${TEMPDIR}${/}hc True
+ Create Directory %{TEMPDIR}${/}hc
+ ${stdout_path}= Normalize Path %{TEMPDIR}/stdout.txt
+ ${result}= Run Process python -c print 'moon kuu';1/0
cwd=%{TEMPDIR}${/}hc stdout=${stdout_path}
+ ... stderr=stderr.txt
+ ${stdout}= Get File ${stdout_path}
+ ${stderr}= Get File %{TEMPDIR}/hc/stderr.txt
+ Should Match ${stdout} *moon kuu*
+ Should Match ${stderr} *ZeroDivisionError*
+ [Teardown] Run Keywords
+ ... Remove Directory %{TEMPDIR}${/}hc recursive=True AND
+ ... Remove File ${stdout_path}
Piped stdout
${result}= Run Process python -c print 'hello'
stdout=PIPE
=======================================
--- /atest/testdata/standard_libraries/process/terminate_and_pid.txt Mon
Jun 10 13:32:28 2013
+++ /atest/testdata/standard_libraries/process/terminate_and_pid.txt Tue
Jun 11 04:01:23 2013
@@ -65,9 +65,10 @@
Lot of output
[Tags] performance
- ${handle}= Run Process python -c "for i in range(350000):
\tprint 'a'*400" shell=True stdout=${TEMPDIR}${/}myout.txt
- File Should Not Be Empty ${TEMPDIR}${/}myout.txt
- [Teardown] Remove File ${TEMPDIR}${/}myout.txt
+ ${stdout}= Normalize Path %{TEMPDIR}${/}stdout.txt
+ ${handle}= Run Process python -c "for i in range(350000):
\tprint 'a'*400" shell=True stdout=${stdout} stderr=STDOUT
+ File Should Not Be Empty ${stdout}
+ [Teardown] Remove File ${stdout}
Getting PIDs in different ways should give same result
${handle}= Start Process python -c "print 'hello'"
shell=True alias=hello
==============================================================================
Revision: 059c5237a4f8
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Tue Jun 11 04:06:55 2013
Log: Process: simplified and cleand up handling stdout, stderr.
http://code.google.com/p/robotframework/source/detail?r=059c5237a4f8
Modified:
/atest/testdata/standard_libraries/process/process_library.txt
/src/robot/libraries/Process.py
=======================================
--- /atest/testdata/standard_libraries/process/process_library.txt Tue Jun
11 04:01:23 2013
+++ /atest/testdata/standard_libraries/process/process_library.txt Tue Jun
11 04:06:55 2013
@@ -119,13 +119,19 @@
${result}= Run Process python -c print 'hello';1/0
stderr=STDOUT
Should Match ${result.stdout} *hello*
Should Match ${result.stdout} *ZeroDivisionError*
- Log ${result.stderr}
+ Should Be Equal ${result.stderr} ${EMPTY}
+ Should Be Equal ${result.stdout_path} ${NONE}
+ Should Be Equal ${result.stderr_path} ${NONE}
Redirecting Stderr to Stdout with filename
${path}= Normalize Path %{TEMPDIR}/filename.txt
${result}= Run Process python -c print 'hello';1/0
stdout=${path} stderr=${path}
Should Match ${result.stdout} *hello*
Should Match ${result.stdout} *ZeroDivisionError*
+ Should Match ${result.stderr} *hello*
+ Should Match ${result.stderr} *ZeroDivisionError*
+ Should Be Equal ${result.stdout_path} ${path}
+ Should Be Equal ${result.stderr_path} ${path}
[Teardown] Remove File ${path}
Current working directory should be used with stdout and stderr
@@ -143,10 +149,13 @@
${stdout_path}= Normalize Path %{TEMPDIR}/stdout.txt
${result}= Run Process python -c print 'moon kuu';1/0
cwd=%{TEMPDIR}${/}hc stdout=${stdout_path}
... stderr=stderr.txt
+ ${stderr_path}= Normalize Path %{TEMPDIR}/hc/stderr.txt
${stdout}= Get File ${stdout_path}
- ${stderr}= Get File %{TEMPDIR}/hc/stderr.txt
+ ${stderr}= Get File ${stderr_path}
Should Match ${stdout} *moon kuu*
Should Match ${stderr} *ZeroDivisionError*
+ Should Be Equal ${result.stdout_path} ${stdout_path}
+ Should Be Equal ${result.stderr_path} ${stderr_path}
[Teardown] Run Keywords
... Remove Directory %{TEMPDIR}${/}hc recursive=True AND
... Remove File ${stdout_path}
=======================================
--- /src/robot/libraries/Process.py Tue Jun 11 03:20:21 2013
+++ /src/robot/libraries/Process.py Tue Jun 11 04:06:55 2013
@@ -207,15 +207,12 @@
that contains information about the process execution as its attibutes.
What is available is documented in the table below.
- | *Attribute* | *Explanation* |
- | rc | Return code of the process as an integer. |
- | stdout | Contents of the standard output stream. |
- | stderr | Contents of the standard error stream. |
- | stdout_path | Path of the file where stdout was redirected. |
- | stderr_path | Path of the file where stderr was redirected. |
-
- TODO:
- - value of stdxxx_path when no redirection?
+ | *Attribute* | *Explanation* |
+ | rc | Return code of the process as an integer. |
+ | stdout | Contents of the standard output stream. |
+ | stderr | Contents of the standard error stream. |
+ | stdout_path | Path where stdout was redirected or `None` if not
redirected. |
+ | stderr_path | Path where stderr was redirected or `None` if not
redirected. |
Example:
| ${result} = | `Run Process` |
program |
@@ -463,53 +460,47 @@
class ExecutionResult(object):
- _stdout = _stderr = _process = None
def __init__(self, process, stdout, stderr, rc=None):
self._process = process
- self.stdout_path = self._construct_stdout_path(stdout)
- self.stderr_path = self._construct_stderr_path(stderr)
+ self.stdout_path = self._get_path(stdout)
+ self.stderr_path = self._get_path(stderr)
self.rc = rc
+ self._stdout = None
+ self._stderr = None
- def _construct_stdout_path(self, stdout):
- return stdout.name if stdout != subprocess.PIPE else None
-
- def _construct_stderr_path(self, stderr):
- if stderr == subprocess.PIPE:
+ def _get_path(self, stream):
+ if stream in (subprocess.PIPE, subprocess.STDOUT):
return None
- if stderr == subprocess.STDOUT:
- return subprocess.STDOUT
- return stderr.name
+ return stream.name
@property
def stdout(self):
if self._stdout is None:
- self._stdout = self._construct_stdout()
- if self._stdout.endswith('\n'):
- self._stdout = self._stdout[:-1]
- return decode_from_system(self._stdout)
-
- def _construct_stdout(self):
- if not self.stdout_path:
- return self._process.stdout.read()
- with open(self.stdout_path, 'r') as f:
- return f.read()
+ self._stdout = self._read_stream(self.stdout_path,
+ self._process.stdout)
+ return self._stdout
@property
def stderr(self):
if self._stderr is None:
- self._stderr = self._construct_stderr()
- if self._stderr.endswith('\n'):
- self._stderr = self._stderr[:-1]
- return decode_from_system(self._stderr)
+ self._stderr = self._read_stream(self.stderr_path,
+ self._process.stderr)
+ return self._stderr
+
+ def _read_stream(self, stream_path, stream):
+ if stream_path:
+ stream = open(stream_path, 'r')
+ try:
+ return self._format_output(stream.read() if stream else '')
+ finally:
+ if stream_path:
+ stream.close()
- def _construct_stderr(self):
- if self.stderr_path == subprocess.STDOUT:
- return self.stdout
- elif not self.stderr_path:
- return self._process.stderr.read()
- with open(self.stderr_path, 'r') as f:
- return f.read()
+ def _format_output(self, output):
+ if output.endswith('\n'):
+ output = output[:-1]
+ return decode_from_system(output)
def __str__(self):
return '<result object with rc %d>' % self.rc
==============================================================================
Revision: 7c5ac06465cd
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Tue Jun 11 04:07:01 2013
Log: Automated merge with https://robotframework.googlecode.com/hg/
http://code.google.com/p/robotframework/source/detail?r=7c5ac06465cd
--
---
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/groups/opt_out.