3 new revisions:
Revision: 4e5d461a5d87
Branch: default
Author: Pekka Klärck
Date: Mon Oct 28 07:11:27 2013 UTC
Log: Process.Get Result: Fail if process hasn't finised yet....
http://code.google.com/p/robotframework/source/detail?r=4e5d461a5d87
Revision: 42b9c714c194
Branch: default
Author: Pekka Klärck
Date: Mon Oct 28 07:57:05 2013 UTC
Log: Process.Get Process Result: Allow retuning also stdout_path and
stderr...
http://code.google.com/p/robotframework/source/detail?r=42b9c714c194
Revision: c3a00a5f54af
Branch: default
Author: Pekka Klärck
Date: Mon Oct 28 08:22:30 2013 UTC
Log: Process: Enhanced docs related to Get Process Result...
http://code.google.com/p/robotframework/source/detail?r=c3a00a5f54af
==============================================================================
Revision: 4e5d461a5d87
Branch: default
Author: Pekka Klärck
Date: Mon Oct 28 07:11:27 2013 UTC
Log: Process.Get Result: Fail if process hasn't finised yet.
Update issue 1490
Status: Started
Cc: pekka.klarck
Fixed keyword not to allow returning results of unfinished processes.
Also enhanced other tests.
http://code.google.com/p/robotframework/source/detail?r=4e5d461a5d87
Modified:
/atest/robot/standard_libraries/process/get_process_result.txt
/atest/testdata/standard_libraries/process/get_process_result.txt
/atest/testdata/standard_libraries/process/resource.txt
/src/robot/libraries/Process.py
=======================================
--- /atest/robot/standard_libraries/process/get_process_result.txt Fri Oct
25 09:32:39 2013 UTC
+++ /atest/robot/standard_libraries/process/get_process_result.txt Mon Oct
28 07:11:27 2013 UTC
@@ -4,11 +4,20 @@
Resource atest_resource.txt
*** Test Cases ***
-Get Process Result
+Get whole result object
+ Check Test Case ${TESTNAME}
+
+Get one result attribute
+ Check Test Case ${TESTNAME}
+
+Get multiple result attributes
+ Check Test Case ${TESTNAME}
+
+Get same result multiple times
Check Test Case ${TESTNAME}
-Get Process Result Multiple Return Values
+Get result of active process
Check Test Case ${TESTNAME}
-Get Process Result Empty Parameters Should Return Result Object
+Getting results of unfinished processes is not supported
Check Test Case ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/process/get_process_result.txt Fri
Oct 25 09:32:39 2013 UTC
+++ /atest/testdata/standard_libraries/process/get_process_result.txt Mon
Oct 28 07:11:27 2013 UTC
@@ -1,23 +1,53 @@
*** Settings ***
Library Process
Resource resource.txt
+Test Setup Run Robot Process
*** Test Cases ****
-Get Process Result
- Start Python Process print 'Robot Framework'
- Wait For Process
- ${rc} = Get Process Result rc=yes
- Should Be Equal As Integers ${rc} 0
+Get whole result object
+ ${result} = Get Process Result robot
+ Should Be Equal ${result.rc} ${2}
+ Should Be Equal ${result.stdout} Robot
+ Should Be Equal ${result.stderr} Framework
-Get Process Result Multiple Return Values
- Start Python Process 1/0 alias=proc1
- Wait For Process proc1
- ${rc} ${stderr} = Get Process Result proc1 rc=yes
stderr=yep
- Should Be Equal As Integers ${rc} 1
- Should Match ${stderr} *ZeroDivisionError: integer division or
modulo by zero*
+Get one result attribute
+ ${rc} = Get Process Result rc=yes handle=robot
+ Should Be Equal ${rc} ${2}
-Get Process Result Empty Parameters Should Return Result Object
- Start Python Process print 'R'
+Get multiple result attributes
+ ${rc} ${stdout} ${stderr} =
+ ... Get Process Result robot stderr=yep rc=x
stdout=${TRUE}
+ Should Be Equal ${rc} ${2}
+ Should Be Equal ${stdout} Robot
+ Should Be Equal ${stderr} Framework
+
+Get same result multiple times
+ ${result} = Get Process Result robot
+ ${stdout} = Get Process Result robot stdout=out
+ ${stderr} = Get Process Result robot stderr=err
+ Should Be Equal ${result.rc} ${2}
+ Should Be Equal ${stdout} Robot
+ Should Be Equal ${stderr} Framework
+
+Get result of active process
+ Start Python Process print 'Robot Framework'
Wait For Process
${result} = Get Process Result
- Should Be Equal As Integers ${result.rc} 0
+ ${stdout} = Get Process Result stdout=true
+ Should Be Equal ${result.rc} ${0}
+ Should Be Equal ${result.stdout} Robot Framework
+ Should Be Equal ${stdout} Robot Framework
+
+Getting results of unfinished processes is not supported
+ [Documentation] FAIL Getting results of unfinished processes is
not supported.
+ Start Python Process print 'Robot Framework'
+ Get Process Result
+
+*** Keywords ***
+Run Robot Process
+ ${command} = Catenate SEPARATOR=;
+ ... import sys
+ ... sys.stdout.write('Robot')
+ ... sys.stderr.write('Framework')
+ ... sys.exit(2)
+ Run Python Process ${command} alias=robot
=======================================
--- /atest/testdata/standard_libraries/process/resource.txt Tue Oct 8
08:58:02 2013 UTC
+++ /atest/testdata/standard_libraries/process/resource.txt Mon Oct 28
07:11:27 2013 UTC
@@ -33,10 +33,8 @@
[Return] ${handle}
Run Python Process
- [Arguments] ${command}
- ${result}= Run Process python -c ${command}
- Log ${result.rc}
- Log ${result.stderr}
+ [Arguments] ${command} ${alias}=${null}
+ ${result}= Run Process python -c ${command}
alias=${alias}
[Return] ${result}
Safe Remove File
=======================================
--- /src/robot/libraries/Process.py Fri Oct 25 09:32:39 2013 UTC
+++ /src/robot/libraries/Process.py Mon Oct 28 07:11:27 2013 UTC
@@ -569,6 +569,9 @@
New in Robot Framework 2.8.2.
"""
result = self._results[self._processes[handle]]
+ if result.rc is None:
+ raise RuntimeError('Getting results of unfinished processes '
+ 'is not supported.')
result_values = self._get_result_attributes(result, rc, stdout,
stderr)
if not result_values:
return result
==============================================================================
Revision: 42b9c714c194
Branch: default
Author: Pekka Klärck
Date: Mon Oct 28 07:57:05 2013 UTC
Log: Process.Get Process Result: Allow retuning also stdout_path and
stderr_path
Update issue 1490
Decided to allow returning also stdout_path and stderr_path. Now all
attributes
of the result object can be returned.
http://code.google.com/p/robotframework/source/detail?r=42b9c714c194
Modified:
/atest/robot/standard_libraries/process/get_process_result.txt
/atest/testdata/standard_libraries/process/get_process_result.txt
/atest/testdata/standard_libraries/process/resource.txt
/src/robot/libraries/Process.py
=======================================
--- /atest/robot/standard_libraries/process/get_process_result.txt Mon Oct
28 07:11:27 2013 UTC
+++ /atest/robot/standard_libraries/process/get_process_result.txt Mon Oct
28 07:57:05 2013 UTC
@@ -10,7 +10,10 @@
Get one result attribute
Check Test Case ${TESTNAME}
-Get multiple result attributes
+Get two result attribute
+ Check Test Case ${TESTNAME}
+
+Get all result attributes
Check Test Case ${TESTNAME}
Get same result multiple times
=======================================
--- /atest/testdata/standard_libraries/process/get_process_result.txt Mon
Oct 28 07:11:27 2013 UTC
+++ /atest/testdata/standard_libraries/process/get_process_result.txt Mon
Oct 28 07:57:05 2013 UTC
@@ -2,6 +2,10 @@
Library Process
Resource resource.txt
Test Setup Run Robot Process
+Suite Teardown Remove File ${TEMP FILE}
+
+*** Variables ***
+${TEMPFILE} %{TEMPDIR}/get-process-result.txt
*** Test Cases ****
Get whole result object
@@ -9,17 +13,27 @@
Should Be Equal ${result.rc} ${2}
Should Be Equal ${result.stdout} Robot
Should Be Equal ${result.stderr} Framework
+ Should Be Equal ${result.stdout_path} ${NONE}
+ Should Be Equal ${result.stderr_path} ${TEMPFILE}
Get one result attribute
${rc} = Get Process Result rc=yes handle=robot
Should Be Equal ${rc} ${2}
-Get multiple result attributes
- ${rc} ${stdout} ${stderr} =
+Get two result attribute
+ ${rc} ${stdout} = Get Process Result robot 1 2
+ Should Be Equal ${rc} ${2}
+ Should Be Equal ${stdout} Robot
+
+Get all result attributes
+ ${rc} ${stdout} ${stderr} ${stdout_path} ${stderr_path} =
... Get Process Result robot stderr=yep rc=x
stdout=${TRUE}
+ ... stderr_path=nämä stdout_path=myös
Should Be Equal ${rc} ${2}
Should Be Equal ${stdout} Robot
Should Be Equal ${stderr} Framework
+ Should Be Equal ${stdout_path} ${NONE}
+ Should Be Equal ${stderr_path} ${TEMPFILE}
Get same result multiple times
${result} = Get Process Result robot
@@ -50,4 +64,4 @@
... sys.stdout.write('Robot')
... sys.stderr.write('Framework')
... sys.exit(2)
- Run Python Process ${command} alias=robot
+ Run Python Process ${command} alias=robot stderr=${TEMPFILE}
=======================================
--- /atest/testdata/standard_libraries/process/resource.txt Mon Oct 28
07:11:27 2013 UTC
+++ /atest/testdata/standard_libraries/process/resource.txt Mon Oct 28
07:57:05 2013 UTC
@@ -28,13 +28,15 @@
Should Be Equal As Integers ${result.rc} ${rc}
Start Python Process
- [Arguments] ${command} ${alias}=${null}
- ${handle}= Start Process python -c ${command}
alias=${alias}
+ [Arguments] ${command} ${alias}=${NONE} ${stdout}=${NONE}
${stderr}=${NONE}
+ ${handle}= Start Process python -c ${command}
+ ... alias=${alias} stdout=${stdout} stderr=${stderr}
[Return] ${handle}
Run Python Process
- [Arguments] ${command} ${alias}=${null}
- ${result}= Run Process python -c ${command}
alias=${alias}
+ [Arguments] ${command} ${alias}=${NONE} ${stdout}=${NONE}
${stderr}=${NONE}
+ ${result}= Run Process python -c ${command}
+ ... alias=${alias} stdout=${stdout} stderr=${stderr}
[Return] ${result}
Safe Remove File
=======================================
--- /src/robot/libraries/Process.py Mon Oct 28 07:11:27 2013 UTC
+++ /src/robot/libraries/Process.py Mon Oct 28 07:57:05 2013 UTC
@@ -530,8 +530,8 @@
"""
return self._processes[handle]
- def get_process_result(self, handle=None, rc=False, stdout=False,
stderr=False):
- """Returns a list of result attributes or a result object from a
process.
+ def get_process_result(self, handle=None, rc=False, stdout=False,
+ stderr=False, stdout_path=False,
stderr_path=False):
The process must be started with `Start Process`, and it must be
stopped
by using `Wait For Process` or `Terminate Process` before using
this
@@ -572,22 +572,18 @@
if result.rc is None:
raise RuntimeError('Getting results of unfinished processes '
'is not supported.')
- result_values = self._get_result_attributes(result, rc, stdout,
stderr)
- if not result_values:
+ attributes = self._get_result_attributes(result, rc, stdout,
stderr,
+ stdout_path, stderr_path)
+ if not attributes:
return result
- elif len(result_values) == 1:
- return result_values[0]
- return result_values
+ elif len(attributes) == 1:
+ return attributes[0]
+ return attributes
- def _get_result_attributes(self, result, rc, stdout, stderr):
- result_values = []
- if rc:
- result_values.append(result.rc)
- if stdout:
- result_values.append(result.stdout)
- if stderr:
- result_values.append(result.stderr)
- return result_values
+ def _get_result_attributes(self, result, *includes):
+ attributes = (result.rc, result.stdout, result.stderr,
+ result.stdout_path, result.stderr_path)
+ return tuple(attr for attr, incl in zip(attributes, includes) if
incl)
def switch_process(self, handle):
"""Makes the specified process the current `active process`.
==============================================================================
Revision: c3a00a5f54af
Branch: default
Author: Pekka Klärck
Date: Mon Oct 28 08:22:30 2013 UTC
Log: Process: Enhanced docs related to Get Process Result
Update issue 1490
Status: Review
Updated the docs to match the current functionality and enhanced them in
general too.
I still want to proofread the docs myself or, preferably, get someone else
to take a look at them. Otherwise this issue ought to be done.
http://code.google.com/p/robotframework/source/detail?r=c3a00a5f54af
Modified:
/src/robot/libraries/Process.py
=======================================
--- /src/robot/libraries/Process.py Mon Oct 28 07:57:05 2013 UTC
+++ /src/robot/libraries/Process.py Mon Oct 28 08:22:30 2013 UTC
@@ -53,6 +53,8 @@
- `Result object`
- `Using with OperatingSystem library`
- `Example`
+ - `Shortcuts`
+ - `Keywords`
= Specifying command and arguments =
@@ -208,7 +210,9 @@
`Run Process`, `Wait For Process` and `Terminate Process` keywords
return a
result object that contains information about the process execution as
its
- attibutes. What is available is documented in the table below.
+ attributes. The same result object, or some of its attributes, can also
+ be get using `Get Process Result` keyword. Attributes available in the
+ object are documented in the table below.
| = Attribute = | = Explanation = |
| rc | Return code of the process as an integer. |
@@ -219,12 +223,12 @@
Example:
| ${result} = | `Run Process` |
program |
- | `Should Be Equal As Integers` | ${result.rc}
| |
+ | `Should Be Equal As Integers` | ${result.rc} |
0 |
| `Should Match` | ${result.stdout} | Some
t?xt* |
| `Should Be Empty` | ${result.stderr}
| |
| ${stdout} = | `Get File` |
${result.stdout_path} |
+ | `Should Be Equal` | ${stdout} |
${result.stdout} |
| `File Should Be Empty` | ${result.stderr_path}
| |
- | `Should Be Equal` | ${result.stdout} |
${stdout} |
= Using with OperatingSystem library =
@@ -532,39 +536,40 @@
def get_process_result(self, handle=None, rc=False, stdout=False,
stderr=False, stdout_path=False,
stderr_path=False):
+ """Returns the specified `result object` or some of its attributes.
- The process must be started with `Start Process`, and it must be
stopped
- by using `Wait For Process` or `Terminate Process` before using
this
- keyword. Getting result attributes for running processes is not
- supported.
+ The given `handle` specifies the process whose results should be
+ returned. If no `handle` is given, results of the current `active
+ process` are returned. In either case, the process must have been
+ finishes before this keyword can be used.
- If `handle` is not given, uses the current `active process`.
-
- If no arguments are given a result object is returned. Enabling one
- or more of the arguments will return a list containing
attribute(s) of
- the process result which are explained below:
-
- | = Argument = | = Attribute = |
- | `rc` | return code |
- | `stdout` | standard output |
- | `stderr` | error output |
+ If no other arguments than the optional `handle` are given, a whole
+ `result object` is returned. If one or more of the other arguments
are
+ given any true value (e.g. any non-empty string), only the
specified
+ attributes of the `result object` are returned. These attributes
are
+ always returned in the same order as arguments are specified in the
+ keyword signature.
Examples:
- | #Single return value |
- | ${rc} = | Get Process Result |
exampleprocess | rc=true |
- | Should Be Equal As Integers | ${rc} |
0 |
- | #Multiple return values |
- | ${rc} | ${stdout} = | Get
Process Result | rc=true | stdout=true |
- | Should Be Equal As Integers | ${rc} |
0 |
- | Should Be Equal | ${stdout} | Robot
Framework |
- | #No arguments given |
- | ${result} = | Get Process Result |
- | Should Be Equal As Integers | ${result.rc} |
0 |
+ | Run Process | python | -c |
print 'Hello, world!' | alias=myproc |
+ | # Get result object | | |
+ | ${result} = | Get Process Result | myproc |
+ | Should Be Equal | ${result.rc} | ${0} |
+ | Should Be Equal | ${result.stdout} | Hello, world! |
+ | Should Be Empty | ${result.stderr} | |
+ | # Get one attribute | | |
+ | ${stdout} = | Get Process Result | myproc |
stdout=true |
+ | Should Be Equal | ${stdout} | Hello, world! |
+ | # Multiple attributes | | |
+ | ${stdout} | ${stderr} = | Get Process Result
| myproc | stdout=yes | stderr=yes |
+ | Should Be Equal | ${stdout} | Hello, world! |
+ | Should Be Empty | ${stderr} | |
- Getting only certain attributes is especially useful when using
this
- library via the Remote library interface. This interface does not
- support returning custom objects, but individual attributes can be
- returned just fine.
+ Although getting results of a previously executed process can be
handy
+ in general, the main use case for this keyword is returning results
+ over the remote library interface. The remote interface does not
+ support returning the whole result object, but individual
attributes
+ can be returned without problems.
New in Robot Framework 2.8.2.
"""
--
---
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.