6 new revisions:
Revision: e64840065f49
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 12:29:31 2013
Log: ConnectionCache: iter and len
http://code.google.com/p/robotframework/source/detail?r=e64840065f49
Revision: 6c57367cf131
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 12:57:07 2013
Log: Process: clean-up enabled by new ConnectionCache features
http://code.google.com/p/robotframework/source/detail?r=6c57367cf131
Revision: f2e05f5ff9bb
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 12:58:53 2013
Log: Process: Fixed Terminate All Processes...
http://code.google.com/p/robotframework/source/detail?r=f2e05f5ff9bb
Revision: 6bb5f5574ab7
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 13:32:38 2013
Log: Process: Terminate All empties caches...
http://code.google.com/p/robotframework/source/detail?r=6bb5f5574ab7
Revision: 0e58930489f8
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 14:24:46 2013
Log: ConnectionCache: 1) get_connection returns current if given None,
whic...
http://code.google.com/p/robotframework/source/detail?r=0e58930489f8
Revision: 9103d7c69450
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 14:29:24 2013
Log: Process: took more new ConnectionCache features into use
http://code.google.com/p/robotframework/source/detail?r=9103d7c69450
==============================================================================
Revision: e64840065f49
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 12:29:31 2013
Log: ConnectionCache: iter and len
http://code.google.com/p/robotframework/source/detail?r=e64840065f49
Modified:
/src/robot/utils/connectioncache.py
/utest/utils/test_connectioncache.py
=======================================
--- /src/robot/utils/connectioncache.py Thu Jun 13 11:14:21 2013
+++ /src/robot/utils/connectioncache.py Thu Jun 13 12:29:31 2013
@@ -100,6 +100,12 @@
self._connections = []
self._aliases = NormalizedDict()
+ def __iter__(self):
+ return iter(self._connections)
+
+ def __len__(self):
+ return len(self._connections)
+
def __nonzero__(self):
return self.current is not self._no_current
=======================================
--- /utest/utils/test_connectioncache.py Thu Jun 13 10:58:32 2013
+++ /utest/utils/test_connectioncache.py Thu Jun 13 12:29:31 2013
@@ -148,6 +148,21 @@
assert_false(conn.closed_by_close)
assert_false(conn.closed_by_exit)
+ def test_iter(self):
+ conns = ['a', object(), 1, None]
+ for c in conns:
+ self.cache.register(c)
+ assert_equals(list(self.cache), conns)
+
+ def test_len(self):
+ assert_equals(len(self.cache), 0)
+ self.cache.register(None)
+ assert_equals(len(self.cache), 1)
+ self.cache.register(None)
+ assert_equals(len(self.cache), 2)
+ self.cache.empty_cache()
+ assert_equals(len(self.cache), 0)
+
def test_truthy(self):
assert_false(self.cache)
self.cache.register(None)
==============================================================================
Revision: 6c57367cf131
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 12:57:07 2013
Log: Process: clean-up enabled by new ConnectionCache features
http://code.google.com/p/robotframework/source/detail?r=6c57367cf131
Modified:
/src/robot/libraries/Process.py
=======================================
--- /src/robot/libraries/Process.py Tue Jun 11 05:57:43 2013
+++ /src/robot/libraries/Process.py Thu Jun 13 12:57:07 2013
@@ -274,15 +274,12 @@
This command does not change the `active process`.
"""
- active_process_index = self._started_processes.current_index
+ current_index = self._started_processes.current_index
try:
- p = self.start_process(command, *arguments, **configuration)
- return self.wait_for_process(p)
+ handle = self.start_process(command, *arguments,
**configuration)
+ return self.wait_for_process(handle)
finally:
- if active_process_index is not None:
- self._started_processes.switch(active_process_index)
- else:
- self._started_processes.empty_cache()
+ self._started_processes.current_index = current_index
def start_process(self, command, *arguments, **configuration):
"""Starts a new process on background.
@@ -432,7 +429,7 @@
def _process(self, handle):
if handle:
return self._started_processes.get_connection(handle)
- if self._started_processes.current_index is None:
+ if not self._started_processes:
raise RuntimeError("No active process.")
return self._started_processes.current
==============================================================================
Revision: f2e05f5ff9bb
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 12:58:53 2013
Log: Process: Fixed Terminate All Processes
Update issue 1475
Status: Done
Owner: pekka.klarck
http://code.google.com/p/robotframework/source/detail?r=f2e05f5ff9bb
Modified:
/atest/testdata/standard_libraries/process/terminate_and_pid.txt
/src/robot/libraries/Process.py
=======================================
--- /atest/testdata/standard_libraries/process/terminate_and_pid.txt Tue
Jun 11 05:45:43 2013
+++ /atest/testdata/standard_libraries/process/terminate_and_pid.txt Thu
Jun 13 12:58:53 2013
@@ -46,6 +46,8 @@
Process Should Be Running ${handle3}
Process Should Be Running ${handle4}
Process Should Be Running ${handle5}
+ Switch Process ${handle3}
+ Terminate Process ${handle2}
Terminate All Processes
Sleep 0.1
Process Should Be Stopped ${handle1}
=======================================
--- /src/robot/libraries/Process.py Thu Jun 13 12:57:07 2013
+++ /src/robot/libraries/Process.py Thu Jun 13 12:58:53 2013
@@ -386,7 +386,7 @@
See `Stopping processes` for more details.
"""
- for handle in range(len(self._started_processes._connections)):
+ for handle in range(1, len(self._started_processes) + 1):
if self.is_process_running(handle):
self.terminate_process(handle, kill=kill)
@@ -427,7 +427,7 @@
self._started_processes.switch(handle)
def _process(self, handle):
- if handle:
+ if handle is not None:
return self._started_processes.get_connection(handle)
if not self._started_processes:
raise RuntimeError("No active process.")
==============================================================================
Revision: 6bb5f5574ab7
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 13:32:38 2013
Log: Process: Terminate All empties caches
Update issue 1476
Status: Done
Owner: pekka.klarck
http://code.google.com/p/robotframework/source/detail?r=6bb5f5574ab7
Modified:
/atest/robot/standard_libraries/process/terminate_and_pid.txt
/atest/testdata/standard_libraries/process/terminate_and_pid.txt
/src/robot/libraries/Process.py
=======================================
--- /atest/robot/standard_libraries/process/terminate_and_pid.txt Mon May
20 05:56:44 2013
+++ /atest/robot/standard_libraries/process/terminate_and_pid.txt Thu Jun
13 13:32:38 2013
@@ -17,7 +17,10 @@
Pid
Check Test Case ${TESTNAME}
-Starting many processes and killing all
+Terminate All Processes
+ Check Test Case ${TESTNAME}
+
+Terminate All Empties Cache
Check Test Case ${TESTNAME}
Kill Process Which Does Not Exist
@@ -31,7 +34,7 @@
Getting PIDs in different ways should give same result
Check Test Case ${TESTNAME}
-
+
*** Keywords ***
Check Preconditions
Run Keyword If '${SUITE.metadata.get('info')}'
== 'precondition_fail' Fail precondition fail -regression
=======================================
--- /atest/testdata/standard_libraries/process/terminate_and_pid.txt Thu
Jun 13 12:58:53 2013
+++ /atest/testdata/standard_libraries/process/terminate_and_pid.txt Thu
Jun 13 13:32:38 2013
@@ -34,27 +34,34 @@
Wait For Process ${handle}
Process Should Be Stopped ${handle}
-Starting many processes and killing all
- ${handle1}= Some process
- ${handle2}= Some process
- ${handle3}= Some process
- ${handle4}= Some process
- ${handle5}= Some process
+Terminate All Processes
+ ${h1}= Some process
+ ${h2}= Some process
+ ${h3}= Some process
+ ${h4}= Some process
+ ${h5}= Some process
Sleep 0.1
- Process Should Be Running ${handle1}
- Process Should Be Running ${handle2}
- Process Should Be Running ${handle3}
- Process Should Be Running ${handle4}
- Process Should Be Running ${handle5}
- Switch Process ${handle3}
- Terminate Process ${handle2}
+ ${p1}= Get Process Object ${h1}
+ ${p2}= Get Process Object ${h2}
+ ${p3}= Get Process Object ${h3}
+ ${p4}= Get Process Object ${h4}
+ ${p5}= Get Process Object ${h5}
+ :FOR ${process} IN ${p1} ${p2} ${p3} ${p4} ${p5}
+ \ ${poll}= Call Method ${process} poll
+ \ Should Be Equal ${poll} ${NONE}
+ Switch Process ${h3}
+ Terminate Process ${h2}
Terminate All Processes
Sleep 0.1
- Process Should Be Stopped ${handle1}
- Process Should Be Stopped ${handle2}
- Process Should Be Stopped ${handle3}
- Process Should Be Stopped ${handle4}
- Process Should Be Stopped ${handle5}
+ :FOR ${process} IN ${p1} ${p2} ${p3} ${p4} ${p5}
+ \ ${poll}= Call Method ${process} poll
+ \ Should Not Be Equal ${poll} ${NONE}
+
+Terminate All Empties Cache
+ Some process
+ Terminate All Processes
+ ${handle} = Some Process
+ Should Be Equal ${handle} ${1}
Kill Process Which Does Not Exist
${handle}= Some process
=======================================
--- /src/robot/libraries/Process.py Thu Jun 13 12:58:53 2013
+++ /src/robot/libraries/Process.py Thu Jun 13 13:32:38 2013
@@ -389,6 +389,7 @@
for handle in range(1, len(self._started_processes) + 1):
if self.is_process_running(handle):
self.terminate_process(handle, kill=kill)
+ self.__init__()
def get_process_id(self, handle=None):
"""Returns the process ID (pid) of the process.
==============================================================================
Revision: 0e58930489f8
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 14:24:46 2013
Log: ConnectionCache: 1) get_connection returns current if given None,
which is also the default, or raises exception if current is not active, 2)
apidoc enhancements, 3) cleanup
http://code.google.com/p/robotframework/source/detail?r=0e58930489f8
Modified:
/src/robot/utils/connectioncache.py
/utest/utils/test_connectioncache.py
=======================================
--- /src/robot/utils/connectioncache.py Thu Jun 13 12:29:31 2013
+++ /src/robot/utils/connectioncache.py Thu Jun 13 14:24:46 2013
@@ -29,7 +29,8 @@
"""
def __init__(self, no_current_msg='No open connection.'):
- self.current = self._no_current = NoConnection(no_current_msg)
+ self._no_current = NoConnection(no_current_msg)
+ self.current = self._no_current #: Current active connection.
self._connections = []
self._aliases = NormalizedDict()
@@ -45,9 +46,13 @@
def register(self, connection, alias=None):
"""Registers given connection with optional alias and returns its
index.
- Given connection is set to be the current connection. Alias must be
- a string. The index of the first connection after initialization or
- close_all or empty_cache is 1, second is 2, etc.
+ Given connection is set to be the :attr:`current` connection.
+
+ If alias is given, it must be a string. Aliases are case and space
+ insensitive.
+
+ The index of the first connection after initialization, or
+ :meth:`close_all` or :meth:`empty_cache`, is 1, second is 2, etc.
"""
self.current = connection
self._connections.append(connection)
@@ -58,20 +63,29 @@
def switch(self, index_or_alias):
"""Switches to the connection specified by given index or alias.
- If alias is given it must be a string. Indexes can be either
integers
- or strings that can be converted into integer. Raises RuntimeError
- if no connection with given index or alias found.
+ Alias is whatever was given to :meth:`register` method and indices
+ are returned by it. Index can be given either as an integer or
+ as a string that can be converted to an integer. Raises an error
+ if no connection with the given index or alias found.
"""
self.current = self.get_connection(index_or_alias)
return self.current
- def get_connection(self, index_or_alias):
+ def get_connection(self, index_or_alias=None):
"""Get the connection specified by given index or alias.
- If alias is given it must be a string. Indexes can be either
integers
- or strings that can be converted into integer. Raises RuntimeError
- if no connection with given index or alias found.
+ If ``index_or_alias`` is ``None``, returns the current connection
+ if it is active, or raises an error if it is not.
+
+ Alias is whatever was given to :meth:`register` method and indices
+ are returned by it. Index can be given either as an integer or
+ as a string that can be converted to an integer. Raises an error
+ if no connection with the given index or alias found.
"""
+ if index_or_alias is None:
+ if not self:
+ self.current.raise_error()
+ return self.current
try:
index = self._resolve_index_or_alias(index_or_alias)
except ValueError:
@@ -124,7 +138,10 @@
raise ValueError
def _resolve_index(self, index):
- index = int(index)
+ try:
+ index = int(index)
+ except TypeError:
+ raise ValueError
if not 0 < index <= len(self._connections):
raise ValueError
return index
@@ -132,13 +149,16 @@
class NoConnection(object):
- def __init__(self, msg):
- self._msg = msg
+ def __init__(self, message):
+ self.message = message
def __getattr__(self, name):
if name.startswith('__') and name.endswith('__'):
raise AttributeError
- raise RuntimeError(self._msg)
+ self.raise_error()
+
+ def raise_error(self):
+ raise RuntimeError(self.message)
def __nonzero__(self):
return False
=======================================
--- /utest/utils/test_connectioncache.py Thu Jun 13 12:29:31 2013
+++ /utest/utils/test_connectioncache.py Thu Jun 13 14:24:46 2013
@@ -53,17 +53,16 @@
def test_set_current_index(self):
self.cache.current_index = None
assert_equals(self.cache.current_index, None)
- self.cache.register('a')
- self.cache.register('b')
+ self._register('a', 'b')
self.cache.current_index = 1
assert_equals(self.cache.current_index, 1)
- assert_equals(self.cache.current, 'a')
+ assert_equals(self.cache.current.id, 'a')
self.cache.current_index = None
assert_equals(self.cache.current_index, None)
assert_equals(self.cache.current, self.cache._no_current)
self.cache.current_index = 2
assert_equals(self.cache.current_index, 2)
- assert_equals(self.cache.current, 'b')
+ assert_equals(self.cache.current.id, 'b')
def test_set_invalid_index(self):
assert_raises(IndexError, setattr, self.cache, 'current_index', 1)
@@ -116,7 +115,8 @@
def test_switch_with_non_existing_alias(self):
self._register('a', 'b')
- assert_raises_with_msg(RuntimeError, "Non-existing index or
alias 'whatever'.",
+ assert_raises_with_msg(RuntimeError,
+ "Non-existing index or alias 'whatever'.",
self.cache.switch, 'whatever')
def test_switch_with_alias_overriding_index(self):
@@ -126,6 +126,28 @@
self.cache.switch('1')
assert_equals(self.cache.current.id, '1')
+ def test_get_connection_with_index(self):
+ self._register('a', 'b')
+ assert_equals(self.cache.get_connection(1).id, 'a')
+ assert_equals(self.cache.current.id, 'b')
+ assert_equals(self.cache.get_connection(2).id, 'b')
+
+ def test_get_connection_with_alias(self):
+ self._register('a', 'b')
+ assert_equals(self.cache.get_connection('a').id, 'a')
+ assert_equals(self.cache.current.id, 'b')
+ assert_equals(self.cache.get_connection('b').id, 'b')
+
+ def test_get_connection_with_none_returns_current(self):
+ self._register('a', 'b')
+ assert_equals(self.cache.get_connection(None).id, 'b')
+ assert_equals(self.cache.get_connection().id, 'b')
+
+ def test_get_connection_with_none_fails_if_no_current(self):
+ assert_raises_with_msg(RuntimeError,
+ 'No open connection.',
+ self.cache.get_connection)
+
def test_close_all(self):
connections = self._register('a', 'b', 'c', 'd')
self.cache.close_all()
==============================================================================
Revision: 9103d7c69450
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 14:29:24 2013
Log: Process: took more new ConnectionCache features into use
http://code.google.com/p/robotframework/source/detail?r=9103d7c69450
Modified:
/src/robot/libraries/Process.py
=======================================
--- /src/robot/libraries/Process.py Thu Jun 13 13:32:38 2013
+++ /src/robot/libraries/Process.py Thu Jun 13 14:29:24 2013
@@ -261,7 +261,7 @@
ROBOT_LIBRARY_VERSION = get_version()
def __init__(self):
- self._started_processes = ConnectionCache('No started processes.')
+ self._started_processes = ConnectionCache('No active process.')
self._results = {}
def run_process(self, command, *arguments, **configuration):
@@ -428,11 +428,7 @@
self._started_processes.switch(handle)
def _process(self, handle):
- if handle is not None:
- return self._started_processes.get_connection(handle)
- if not self._started_processes:
- raise RuntimeError("No active process.")
- return self._started_processes.current
+ return self._started_processes.get_connection(handle)
class ExecutionResult(object):
--
---
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.