4 new revisions:
Revision: e266e0ee670a
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 04:29:38 2011
Log: comment about else branch
http://code.google.com/p/robotframework/source/detail?r=e266e0ee670a
Revision: e0753e55bfd1
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 04:29:47 2011
Log: Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=e0753e55bfd1
Revision: 8e3a9d99da13
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 06:14:08 2011
Log: timeouts: cleanup
http://code.google.com/p/robotframework/source/detail?r=8e3a9d99da13
Revision: ce5b969e9769
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 06:14:15 2011
Log: Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=ce5b969e9769
==============================================================================
Revision: e266e0ee670a
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 04:29:38 2011
Log: comment about else branch
http://code.google.com/p/robotframework/source/detail?r=e266e0ee670a
Modified:
/src/robot/running/timeouts/__init__.py
=======================================
--- /src/robot/running/timeouts/__init__.py Wed Dec 14 04:01:31 2011
+++ /src/robot/running/timeouts/__init__.py Wed Dec 14 04:29:38 2011
@@ -21,7 +21,7 @@
from timeoutwin import Timeout
elif os.name == 'java':
from timeoutthread import Timeout
-else:
+else: # python in *nix or mac
try:
from timeoutsignaling import Timeout
except ImportError:
==============================================================================
Revision: e0753e55bfd1
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 04:29:47 2011
Log: Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=e0753e55bfd1
==============================================================================
Revision: 8e3a9d99da13
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 06:14:08 2011
Log: timeouts: cleanup
http://code.google.com/p/robotframework/source/detail?r=8e3a9d99da13
Deleted:
/src/robot/running/timeouts/robotthread.py
/utest/running/test_robotthread.py
Modified:
/src/robot/running/timeouts/__init__.py
/src/robot/running/timeouts/timeoutsignaling.py
/src/robot/running/timeouts/timeoutthread.py
/src/robot/running/timeouts/timeoutwin.py
=======================================
--- /src/robot/running/timeouts/robotthread.py Wed Dec 14 01:32:15 2011
+++ /dev/null
@@ -1,57 +0,0 @@
-# Copyright 2008-2011 Nokia Siemens Networks Oyj
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import sys
-from threading import Event
-
-if sys.platform.startswith('java'):
- from java.lang import Thread, Runnable
-else:
- from stoppablethread import Thread
- Runnable = object
-
-
-class ThreadedRunner(Runnable):
-
- def __init__(self, runnable, args=None, kwargs=None, notifier=None):
- self._runnable = lambda: runnable(*(args or ()), **(kwargs or {}))
- self._notifier = Event()
- self._result = None
- self._error = None
- self._traceback = None
- self._thread = None
-
- def run(self):
- try:
- self._result = self._runnable()
- except:
- self._error, self._traceback = sys.exc_info()[1:]
- self._notifier.set()
-
- __call__ = run
-
- def run_in_thread(self, timeout):
- self._thread = Thread(self)
- self._thread.setDaemon(True)
- self._thread.start()
- self._notifier.wait(timeout)
- return self._notifier.isSet()
-
- def get_result(self):
- if self._error:
- raise self._error, None, self._traceback
- return self._result
-
- def stop_thread(self):
- self._thread.stop()
=======================================
--- /utest/running/test_robotthread.py Wed Dec 14 01:32:15 2011
+++ /dev/null
@@ -1,39 +0,0 @@
-import unittest
-import sys
-from robot.running.timeouts.robotthread import ThreadedRunner
-
-from robot.utils.asserts import *
-from thread_resources import *
-
-
-
-class TestRunner(unittest.TestCase):
-
- def test_passing(self):
- runner = ThreadedRunner(passing)
- runner.run()
- assert_none(runner.get_result())
-
- def test_returning(self):
- for arg in [ 10, 'hello', ['l','i','s','t'], unittest]:
- runner = ThreadedRunner(returning, args=(arg,))
- runner.run()
- assert_equals(runner.get_result(), arg)
-
- def test_failing(self):
- runner = ThreadedRunner(failing, args=('hello world',))
- runner.run()
- assert_raises_with_msg(Exception, 'hello world', runner.get_result)
-
- if sys.platform.startswith('java'):
- from java.lang import Error
-
- def test_java_failing(self):
- runner = ThreadedRunner(java_failing, args=('hi tellus',))
- runner.run()
- assert_raises_with_msg(Error, 'java.lang.Error: hi tellus',
- runner.get_result)
-
-
-if __name__ == '__main__':
- unittest.main()
=======================================
--- /src/robot/running/timeouts/__init__.py Wed Dec 14 04:29:38 2011
+++ /src/robot/running/timeouts/__init__.py Wed Dec 14 06:14:08 2011
@@ -14,25 +14,24 @@
import sys
import os
+import time
if sys.platform == 'cli':
from timeoutthread import Timeout
elif os.name == 'nt':
from timeoutwin import Timeout
-elif os.name == 'java':
- from timeoutthread import Timeout
-else: # python in *nix or mac
+else:
try:
+ # python 2.6 or newer in *nix or mac
from timeoutsignaling import Timeout
except ImportError:
- # For old python 2.5 releases where signaling is not available
+ # python < 2.6 and jython don't have complete signal module
from timeoutthread import Timeout
-import time
-
from robot import utils
from robot.errors import TimeoutError, DataError, FrameworkError
+
class _Timeout(object):
def __init__(self, timeout=None, message='', variables=None):
@@ -44,10 +43,6 @@
if variables:
self.replace_variables(variables)
- @property
- def type(self):
- return type(self).__name__.replace('Timeout', ' timeout')
-
@property
def active(self):
return self.starttime > 0
@@ -62,7 +57,7 @@
self.message = variables.replace_string(self.message)
except (DataError, ValueError), err:
self.secs = 0.000001 # to make timeout active
- self.error = 'Setting %s failed: %s' % (self.type.lower(),
unicode(err))
+ self.error = 'Setting %s timeout failed: %s' %
(self.type.lower(), unicode(err))
def start(self):
if self.secs > 0:
@@ -94,27 +89,27 @@
timeout = self.time_left()
if timeout <= 0:
raise TimeoutError(self.get_message())
- return Timeout(timeout, self._get_timeout_error(), self.type).\
- execute(runnable, args, kwargs)
-
- def _execute_with_timeout(self, timeout, runnable, args, kwargs):
- raise NotImplementedError(self.__class__)
+ executable = lambda:runnable(*(args or ()), **(kwargs or {}))
+ return Timeout(timeout, self._timeout_error).execute(executable)
def get_message(self):
if not self.active:
- return '%s not active.' % self.type
+ return '%s timeout not active.' % self.type
if not self.timed_out():
- return '%s %s active. %s seconds left.' % (self.type,
self.string,
+ return '%s timeout %s active. %s seconds left.' % (self.type,
self.string,
self.time_left())
- return self._get_timeout_error()
-
- def _get_timeout_error(self):
+ return self._timeout_error
+
+ @property
+ def _timeout_error(self):
if self.message:
return self.message
- return '%s %s exceeded.' % (self.type, self.string)
+ return '%s timeout %s exceeded.' % (self.type, self.string)
+
class TestTimeout(_Timeout):
_keyword_timeouted = False
+ type = 'Test'
def set_keyword_timeout(self, timeout_occurred):
self._keyword_timeouted = self._keyword_timeouted or
timeout_occurred
@@ -124,4 +119,4 @@
class KeywordTimeout(_Timeout):
- pass
+ type = 'Keyword'
=======================================
--- /src/robot/running/timeouts/timeoutsignaling.py Mon Dec 12 05:23:40 2011
+++ /src/robot/running/timeouts/timeoutsignaling.py Wed Dec 14 06:14:08 2011
@@ -13,19 +13,20 @@
# limitations under the License.
from signal import setitimer, signal, SIGALRM, ITIMER_REAL
+
from robot.errors import TimeoutError
class Timeout(object):
- def __init__(self, timeout, error, timeout_type):
+ def __init__(self, timeout, error):
self._timeout = timeout
self._error = error
- def execute(self, runnable, args, kwargs):
+ def execute(self, runnable):
self._start_timer()
try:
- return runnable(*(args or ()), **(kwargs or {}))
+ return runnable()
finally:
self._stop_timer()
=======================================
--- /src/robot/running/timeouts/timeoutthread.py Wed Dec 14 01:32:15 2011
+++ /src/robot/running/timeouts/timeoutthread.py Wed Dec 14 06:14:08 2011
@@ -11,30 +11,65 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-from robot import utils
+
from robot.errors import TimeoutError
-from .robotthread import ThreadedRunner
+
+import sys
+from threading import Event
+
+if sys.platform.startswith('java'):
+ from java.lang import Thread, Runnable
+else:
+ from stoppablethread import Thread
+ Runnable = object
+
+
+class ThreadedRunner(Runnable):
+
+ def __init__(self, runnable):
+ self._runnable = runnable
+ self._notifier = Event()
+ self._result = None
+ self._error = None
+ self._traceback = None
+ self._thread = None
+
+ def run(self):
+ try:
+ self._result = self._runnable()
+ except:
+ self._error, self._traceback = sys.exc_info()[1:]
+ self._notifier.set()
+
+ __call__ = run
+
+ def run_in_thread(self, timeout):
+ self._thread = Thread(self)
+ self._thread.setDaemon(True)
+ self._thread.start()
+ self._notifier.wait(timeout)
+ return self._notifier.isSet()
+
+ def get_result(self):
+ if self._error:
+ raise self._error, None, self._traceback
+ return self._result
+
+ def stop_thread(self):
+ self._thread.stop()
class Timeout(object):
- def __init__(self, timeout, error, timeout_type):
+ def __init__(self, timeout, error):
self._timeout = timeout
self._error = error
- self._timeout_type = timeout_type
-
- def execute(self, runnable, args, kwargs):
- runner = ThreadedRunner(runnable, args, kwargs)
+
+ def execute(self, runnable):
+ runner = ThreadedRunner(runnable)
if runner.run_in_thread(self._timeout):
return runner.get_result()
- try:
- runner.stop_thread()
- except:
- raise TimeoutError(self._stopping_failed)
+ runner.stop_thread()
raise TimeoutError(self._error)
- @property
- def _stopping_failed(self):
- return 'Stopping keyword after timeout failed: %s' %
(self._timeout_type,
-
utils.get_error_message())
-
+
=======================================
--- /src/robot/running/timeouts/timeoutwin.py Mon Dec 12 06:03:03 2011
+++ /src/robot/running/timeouts/timeoutwin.py Wed Dec 14 06:14:08 2011
@@ -11,29 +11,32 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
from __future__ import with_statement
import ctypes
import thread
-import threading
import time
+from threading import Timer
+
from robot.errors import TimeoutError
+
class Timeout(object):
- def __init__(self, timeout, timeout_error, timeout_type):
+ def __init__(self, timeout, timeout_error):
self._runner_thread_id = thread.get_ident()
- self._timeout_error = self._error_with_message(timeout_error)
- self._timer = threading.Timer(timeout, self)
+ self._timeout_error =
self._create_timeout_error_class(timeout_error)
+ self._timer = Timer(timeout, self._raise_timeout_error)
self._timeout_occurred = False
- def _error_with_message(self, message):
+ def _create_timeout_error_class(self, timeout_error):
return type(TimeoutError.__name__,
- (TimeoutError,),
- {'__unicode__': lambda s: message})
-
- def execute(self, runnable, args, kwargs):
+ (TimeoutError,),
+ {'__unicode__': lambda s: timeout_error})
+
+ def execute(self, runnable):
with self:
- return runnable(*(args or ()), **(kwargs or {}))
+ return runnable()
def __enter__(self):
self._timer.start()
@@ -47,7 +50,7 @@
self._cancel_exception()
raise self._timeout_error()
- def __call__(self):
+ def _raise_timeout_error(self):
self._timeout_occurred = True
return_code = self._try_to_raise_timeout_error_in_runner_thread()
# return code tells how many threads have been influenced
==============================================================================
Revision: ce5b969e9769
Author: Mikko Korpela <[email protected]>
Date: Wed Dec 14 06:14:15 2011
Log: Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=ce5b969e9769
Deleted:
/src/robot/running/timeouts/robotthread.py
/utest/running/test_robotthread.py
=======================================
--- /src/robot/running/timeouts/robotthread.py Wed Dec 14 01:32:15 2011
+++ /dev/null
@@ -1,57 +0,0 @@
-# Copyright 2008-2011 Nokia Siemens Networks Oyj
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import sys
-from threading import Event
-
-if sys.platform.startswith('java'):
- from java.lang import Thread, Runnable
-else:
- from stoppablethread import Thread
- Runnable = object
-
-
-class ThreadedRunner(Runnable):
-
- def __init__(self, runnable, args=None, kwargs=None, notifier=None):
- self._runnable = lambda: runnable(*(args or ()), **(kwargs or {}))
- self._notifier = Event()
- self._result = None
- self._error = None
- self._traceback = None
- self._thread = None
-
- def run(self):
- try:
- self._result = self._runnable()
- except:
- self._error, self._traceback = sys.exc_info()[1:]
- self._notifier.set()
-
- __call__ = run
-
- def run_in_thread(self, timeout):
- self._thread = Thread(self)
- self._thread.setDaemon(True)
- self._thread.start()
- self._notifier.wait(timeout)
- return self._notifier.isSet()
-
- def get_result(self):
- if self._error:
- raise self._error, None, self._traceback
- return self._result
-
- def stop_thread(self):
- self._thread.stop()
=======================================
--- /utest/running/test_robotthread.py Wed Dec 14 01:32:15 2011
+++ /dev/null
@@ -1,39 +0,0 @@
-import unittest
-import sys
-from robot.running.timeouts.robotthread import ThreadedRunner
-
-from robot.utils.asserts import *
-from thread_resources import *
-
-
-
-class TestRunner(unittest.TestCase):
-
- def test_passing(self):
- runner = ThreadedRunner(passing)
- runner.run()
- assert_none(runner.get_result())
-
- def test_returning(self):
- for arg in [ 10, 'hello', ['l','i','s','t'], unittest]:
- runner = ThreadedRunner(returning, args=(arg,))
- runner.run()
- assert_equals(runner.get_result(), arg)
-
- def test_failing(self):
- runner = ThreadedRunner(failing, args=('hello world',))
- runner.run()
- assert_raises_with_msg(Exception, 'hello world', runner.get_result)
-
- if sys.platform.startswith('java'):
- from java.lang import Error
-
- def test_java_failing(self):
- runner = ThreadedRunner(java_failing, args=('hi tellus',))
- runner.run()
- assert_raises_with_msg(Error, 'java.lang.Error: hi tellus',
- runner.get_result)
-
-
-if __name__ == '__main__':
- unittest.main()