2 new revisions:
Revision: aba9bf46f7f0
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Thu Oct 31 15:10:46 2013 UTC
Log: Little cleanup to Process lib tests. A bigger cleanup would also
be in...
http://code.google.com/p/robotframework/source/detail?r=aba9bf46f7f0
Revision: dd7bc392c2fa
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Thu Oct 31 16:36:17 2013 UTC
Log: Process: Condider 'false' string False when used as Boolean
argument....
http://code.google.com/p/robotframework/source/detail?r=dd7bc392c2fa
==============================================================================
Revision: aba9bf46f7f0
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Thu Oct 31 15:10:46 2013 UTC
Log: Little cleanup to Process lib tests. A bigger cleanup would also
be in order.
http://code.google.com/p/robotframework/source/detail?r=aba9bf46f7f0
Modified:
/atest/robot/standard_libraries/process/process_library.txt
/atest/robot/standard_libraries/process/terminate_and_pid.txt
/atest/testdata/standard_libraries/process/process_library.txt
/atest/testdata/standard_libraries/process/resource.txt
/atest/testdata/standard_libraries/process/terminate_and_pid.txt
=======================================
--- /atest/robot/standard_libraries/process/process_library.txt Thu Jun 13
23:28:50 2013 UTC
+++ /atest/robot/standard_libraries/process/process_library.txt Thu Oct 31
15:10:46 2013 UTC
@@ -72,3 +72,6 @@
Current working directory should not be used with stdout and stderr when
absolute path in use
Check Test Case ${TESTNAME}
+
+Lot of output
+ Check Test Case ${TESTNAME}
=======================================
--- /atest/robot/standard_libraries/process/terminate_and_pid.txt Mon Oct
28 13:22:46 2013 UTC
+++ /atest/robot/standard_libraries/process/terminate_and_pid.txt Thu Oct
31 15:10:46 2013 UTC
@@ -10,11 +10,11 @@
Killing process
${tc} = Check Test Case ${TESTNAME}
- Check Log Message ${tc.kws[2].msgs[0]} Forcefully killing
process.
+ Check Log Message ${tc.kws[1].msgs[0]} Forcefully killing
process.
Terminating process
${tc} = Check Test Case ${TESTNAME}
- Check Log Message ${tc.kws[2].msgs[0]} Gracefully terminating
process.
+ Check Log Message ${tc.kws[1].msgs[0]} Gracefully terminating
process.
Kill Process When Terminate Fails
${tc} = Check Test Case ${TESTNAME}
@@ -23,9 +23,6 @@
Check Log Message ${tc.kws[6].msgs[1]} Graceful termination
failed.
Check Log Message ${tc.kws[6].msgs[2]} Forcefully killing
process.
Should Be True ${tc.elapsedtime} >= 2000
-
-Pid
- Check Test Case ${TESTNAME}
Terminate All Processes
${tc} = Check Test Case ${TESTNAME}
@@ -34,18 +31,17 @@
Terminate All Empties Cache
Check Test Case ${TESTNAME}
-Kill Process Which Does Not Exist
+Terminating already terminated process is ok
Check Test Case ${TESTNAME}
-Wait For Process Which Does Not Exist
+Waiting for terminated process is ok
Check Test Case ${TESTNAME}
-Lot of output
+Pid
Check Test Case ${TESTNAME}
Getting PIDs in different ways should give same result
Check Test Case ${TESTNAME}
-
*** Keywords ***
Check Preconditions
=======================================
--- /atest/testdata/standard_libraries/process/process_library.txt Thu Jun
13 23:28:50 2013 UTC
+++ /atest/testdata/standard_libraries/process/process_library.txt Thu Oct
31 15:10:46 2013 UTC
@@ -157,6 +157,13 @@
[Teardown] Run Keywords
... Safe Remove Directory %{TEMPDIR}/hc AND
... Safe Remove File ${stdout_path}
+
+Lot of output
+ [Tags] performance
+ ${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] Safe Remove File ${stdout}
*** Keywords ***
Restart Suite Process If Needed
=======================================
--- /atest/testdata/standard_libraries/process/resource.txt Mon Oct 28
07:57:05 2013 UTC
+++ /atest/testdata/standard_libraries/process/resource.txt Thu Oct 31
15:10:46 2013 UTC
@@ -6,6 +6,7 @@
Some process
[Arguments] ${alias}=${null}
${handle}= Start Python Process raw_input() alias=${alias}
+ Process should be running
[Return] ${handle}
Stop some process
=======================================
--- /atest/testdata/standard_libraries/process/terminate_and_pid.txt Thu
Oct 17 14:57:20 2013 UTC
+++ /atest/testdata/standard_libraries/process/terminate_and_pid.txt Thu
Oct 31 15:10:46 2013 UTC
@@ -17,8 +17,7 @@
Killing process
${handle}= Some process
- Process Should Be Running
- ${result} = Terminate Process ${handle} kill=${True}
+ ${result} = Terminate Process ${handle} kill=true
Process Should Be Stopped ${handle}
Should Not Be Equal As Integers ${result.rc} 0
Should Be Empty ${result.stdout}
@@ -26,7 +25,6 @@
Terminating process
${handle}= Some process
- Process Should Be Running
${result} = Terminate Process ${handle}
Process Should Be Stopped ${handle}
Should Not Be Equal As Integers ${result.rc} 0
@@ -45,13 +43,15 @@
Process Should Be Stopped ${process}
Should Not Be Equal As Integers ${result.rc} 0
-Pid
+Terminating already terminated process is ok
${handle}= Some process
- ${pid}= Get Process Id ${handle}
- Should Not Be Equal ${pid} ${None}
- Evaluate os.kill(int(${pid}),signal.SIGTERM) if hasattr(os, 'kill')
else os.system('taskkill /pid ${pid} /f') os,signal
+ Terminate Process ${handle}
+ Terminate Process ${handle}
+
+Waiting for terminated process is ok
+ ${handle}= Some process
+ Terminate Process ${handle}
Wait For Process ${handle}
- Process Should Be Stopped ${handle}
Terminate All Processes
${h1}= Some process
@@ -78,26 +78,17 @@
Terminate All Empties Cache
Some process
- Terminate All Processes
+ Terminate All Processes kill=True
${handle} = Some Process
Should Be Equal ${handle} ${1}
-Kill Process Which Does Not Exist
- ${handle}= Some process
- Terminate Process ${handle} kill=${True}
- Terminate Process ${handle} kill=${True}
-
-Wait For Process Which Does Not Exist
+Pid
${handle}= Some process
- Terminate Process ${handle} kill=${True}
+ ${pid}= Get Process Id ${handle}
+ Should Not Be Equal ${pid} ${None}
+ Evaluate os.kill(int(${pid}),signal.SIGTERM) if hasattr(os, 'kill')
else os.system('taskkill /pid ${pid} /f') os,signal
Wait For Process ${handle}
-
-Lot of output
- [Tags] performance
- ${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] Safe Remove File ${stdout}
+ Process Should Be Stopped ${handle}
Getting PIDs in different ways should give same result
${handle}= Start Process python -c "print 'hello'"
shell=True alias=hello
==============================================================================
Revision: dd7bc392c2fa
Branch: default
Author: Robot Framework Developers (robotframew...@gmail.com)
Date: Thu Oct 31 16:36:17 2013 UTC
Log: Process: Condider 'false' string False when used as Boolean
argument.
New issue
Summary: `Process` library: Consider string 'false' as Boolean False
Status: Done
Owner: pekka.klarck
Labels: Priority-Low Target-2.8.2 Type-Enhancement
Now it is possible to use string 'false', case-insensitively, in with
arguments handled as Boolean values. For example, the following are now
identical:
Terminate Process kill=False
Terminate Process kill=${FALSE}
Earlier the former would set kill `True'. This isn't such a big enhancement
in practice because, at least currently, all Boolean arguments are False by
default.
http://code.google.com/p/robotframework/source/detail?r=dd7bc392c2fa
Modified:
/atest/testdata/standard_libraries/process/get_process_result.txt
/atest/testdata/standard_libraries/process/process_library.txt
/atest/testdata/standard_libraries/process/terminate_and_pid.txt
/src/robot/libraries/Process.py
=======================================
--- /atest/testdata/standard_libraries/process/get_process_result.txt Mon
Oct 28 07:57:05 2013 UTC
+++ /atest/testdata/standard_libraries/process/get_process_result.txt Thu
Oct 31 16:36:17 2013 UTC
@@ -17,11 +17,11 @@
Should Be Equal ${result.stderr_path} ${TEMPFILE}
Get one result attribute
- ${rc} = Get Process Result rc=yes handle=robot
+ ${rc} = Get Process Result rc=yes handle=robot stdout=FALSE
Should Be Equal ${rc} ${2}
Get two result attribute
- ${rc} ${stdout} = Get Process Result robot 1 2
+ ${rc} ${stdout} = Get Process Result robot 1 2 false
Should Be Equal ${rc} ${2}
Should Be Equal ${stdout} Robot
=======================================
--- /atest/testdata/standard_libraries/process/process_library.txt Thu Oct
31 15:10:46 2013 UTC
+++ /atest/testdata/standard_libraries/process/process_library.txt Thu Oct
31 16:36:17 2013 UTC
@@ -97,7 +97,12 @@
Running a process in a shell
${result}= Run Process python -c "print 'hello'" shell=True
Result should equal ${result} stdout=hello
+ ${result}= Run Process python -c "print 'hello'" shell=0
+ Result should equal ${result} stdout=hello
Run Keyword And Expect Error * Run Process python
-c "print 'hello'" shell=${False}
+ Run Keyword And Expect Error * Run Process python
-c "print 'hello'" shell=${0}
+ Run Keyword And Expect Error * Run Process python
-c "print 'hello'" shell=False
+ Run Keyword And Expect Error * Run Process python
-c "print 'hello'" shell=false
Input things to process
Start Process python -c "print 'inp %s' % raw_input()" shell=True
=======================================
--- /atest/testdata/standard_libraries/process/terminate_and_pid.txt Thu
Oct 31 15:10:46 2013 UTC
+++ /atest/testdata/standard_libraries/process/terminate_and_pid.txt Thu
Oct 31 16:36:17 2013 UTC
@@ -38,7 +38,7 @@
${process} = Start Process python ${NONTERM}
Process Should Be Running ${process}
Sleep 0.1
- ${result} = Terminate Process ${process}
+ ${result} = Terminate Process ${process} kill=false
Wait For Process ${process}
Process Should Be Stopped ${process}
Should Not Be Equal As Integers ${result.rc} 0
=======================================
--- /src/robot/libraries/Process.py Thu Oct 31 14:43:54 2013 UTC
+++ /src/robot/libraries/Process.py Thu Oct 31 16:36:17 2013 UTC
@@ -51,6 +51,7 @@
- `Process configuration`
- `Active process`
- `Result object`
+ - `Boolean arguments`
- `Using with OperatingSystem library`
- `Example`
- `Shortcuts`
@@ -161,7 +162,7 @@
| ${result} = | `Run Process` | program | stderr=STDOUT |
| `Log` | all output: ${result.stdout} |
- *NOTE:* The created output files are not automatically removed after
+ Note that the created output files are not automatically removed after
the test run. The user is responsible to remove them if needed.
== Alias ==
@@ -210,6 +211,31 @@
| `Should Be Equal` | ${stdout} |
${result.stdout} |
| `File Should Be Empty` | ${result.stderr_path}
| |
+ = Boolean arguments =
+
+ Some keywords accept arguments that are handled as Boolean values.
+ If such an argument is given as a string, it is considered false if it
+ is either empty or case-insensitively equal to `false`. Other strings
+ are considered true regardless what they contain, and other argument
+ types are tested using same
+ [http://docs.python.org/2/library/stdtypes.html#truth-value-testing|
rules
+ as in Python].
+
+ True examples:
+ | `Terminate Process` | kill=True | # Strings are generally
true. |
+ | `Terminate Process` | kill=yes | # Same as
above. |
+ | `Terminate Process` | kill=${TRUE} | # Python `True` is
true. |
+ | `Terminate Process` | kill=${42} | # Numbers other than 0 are
true. |
+
+ False examples:
+ | `Terminate Process` | kill=False | # String `False` is
false. |
+ | `Terminate Process` | kill=${EMPTY} | # Empty string is
false. |
+ | `Terminate Process` | kill=${FALSE} | # Python `False` is
false. |
+ | `Terminate Process` | kill=${0} | # Number 0 is
false. |
+
+ Note that prior to Robot Framework 2.8 all non-empty strings, including
+ `false`, were considered true.
+
= Using with OperatingSystem library =
The OperatingSystem library also contains keywords for running
processes.
@@ -405,22 +431,26 @@
If `handle` is not given, uses the current `active process`.
- Returns a `result object` containing information about the
execution
+ Waits for the process to stop after terminating it. Returns
+ a `result object` containing information about the execution
similarly as `Wait For Process`.
On Unix-like machines, by default, first tries to terminate the
process
gracefully, but forcefully kills it if it does not stop in 30
seconds.
- Kills the process immediately if the `kill` argument is given any
true
- value (e.g. any non-empty string). Termination is done using `TERM
- (15)` signal and killing using `KILL (9)`. Use `Send Signal To
- Process` if you just want to send the `TERM` signal.
+ Kills the process immediately if the `kill` argument is given any
value
+ considered true. See `Boolean arguments` section for more details
about
+ true and false values.
- On Windows the Win32 API function `TerminateProcess` is used
directly
+ Termination is done using `TERM (15)` signal and killing using
+ `KILL (9)`. Use `Send Signal To Process` instead if you just want
to
+ send either of these signals without waiting for the process to
stop.
+
+ On Windows the Win32 API function `TerminateProcess()` is used
directly
to stop the process. Using the `kill` argument has no special
effect.
- | ${result} = | Terminate Process | |
- | Should Be Equal As Integers | ${result.rc} | -15 |
- | Terminate Process | myproc | kill=yes |
+ | ${result} = | Terminate Process | |
+ | Should Be Equal As Integers | ${result.rc} | -15 |
+ | Terminate Process | myproc | kill=true |
*NOTE:* Stopping processes requires the
[http://docs.python.org/2/library/subprocess.html|subprocess]
@@ -437,7 +467,7 @@
if not hasattr(process, 'terminate'):
raise RuntimeError('Terminating processes is not supported '
'by this Python version.')
- terminator = self._kill_process if kill else
self._terminate_process
+ terminator = self._kill if is_true(kill) else self._terminate
try:
terminator(process)
except OSError:
@@ -447,18 +477,18 @@
result.rc = process.wait() or 0
return result
- def _kill_process(self, process):
+ def _kill(self, process):
logger.info('Forcefully killing process.')
process.kill()
if not self._process_is_stopped(process, self.KILL_TIMEOUT):
- raise
+ raise RuntimeError('Failed to kill process.')
- def _terminate_process(self, process):
+ def _terminate(self, process):
logger.info('Gracefully terminating process.')
process.terminate()
if not self._process_is_stopped(process, self.TERMINATE_TIMEOUT):
logger.info('Graceful termination failed.')
- self._kill_process(process)
+ self._kill(process)
def terminate_all_processes(self, kill=False):
"""Terminates all still running processes started by this library.
@@ -560,11 +590,12 @@
keyword.
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.
+ `result object` is returned. If one or more of the other arguments
+ are given any true value, 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.
+ See `Boolean arguments` section for more details about true and
false
+ values.
Examples:
| Run Process | python | -c |
print 'Hello, world!' | alias=myproc |
@@ -604,6 +635,7 @@
def _get_result_attributes(self, result, *includes):
attributes = (result.rc, result.stdout, result.stderr,
result.stdout_path, result.stderr_path)
+ includes = (is_true(incl) for incl in includes)
return tuple(attr for attr, incl in zip(attributes, includes) if
incl)
def switch_process(self, handle):
@@ -684,7 +716,7 @@
self.cwd = self._get_cwd(cwd)
self.stdout_stream = self._new_stream(stdout)
self.stderr_stream = self._get_stderr(stderr, stdout)
- self.shell = bool(shell)
+ self.shell = is_true(shell)
self.alias = alias
self.env = self._construct_env(env, rest)
@@ -728,3 +760,9 @@
alias = %s
env = %r""" % (self.cwd, self.stdout_stream, self.stderr_stream,
self.shell, self.alias, self.env))
+
+
+def is_true(argument):
+ if isinstance(argument, basestring) and argument.upper() == 'FALSE':
+ return False
+ return bool(argument)
--
---
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.