Revision: 4064
Author: pekka.klarck
Date: Thu Sep 16 00:17:34 2010
Log: signals and ctrl-c stop execution even if keyword swallows exceptions (issue 657). review and tests needed.
http://code.google.com/p/robotframework/source/detail?r=4064

Modified:
 /trunk/src/robot/running/handlers.py
 /trunk/src/robot/running/signalhandler.py
 /trunk/utest/running/test_testlibrary.py

=======================================
--- /trunk/src/robot/running/handlers.py        Sat Sep 11 04:53:32 2010
+++ /trunk/src/robot/running/handlers.py        Thu Sep 16 00:17:34 2010
@@ -109,11 +109,11 @@

     def _run(self, context, args):
         output = context.output
- positional, named = self.arguments.resolve(args, context.get_current_vars(),
-                                                   output)
+        positional, named = \
+ self.arguments.resolve(args, context.get_current_vars(), output) runner = self._runner_for(self._current_handler(), output, positional, named, self._get_timeout(context.namespace)) - return self._run_with_output_captured_and_signal_monitor(runner, output) + return self._run_with_output_captured_and_signal_monitor(runner, context)

     def _runner_for(self, handler, output, positional, named, timeout):
         if timeout and timeout.active:
@@ -121,20 +121,20 @@
return lambda: timeout.run(handler, args=positional, kwargs=named)
         return lambda: handler(*positional, **named)

-    def _run_with_output_captured_and_signal_monitor(self, runner, output):
+ def _run_with_output_captured_and_signal_monitor(self, runner, context):
         capturer = OutputCapturer()
         try:
-            return self._run_with_signal_monitoring(runner)
+            return self._run_with_signal_monitoring(runner, context)
         finally:
             stdout, stderr = capturer.release()
-            output.log_output(stdout)
-            output.log_output(stderr)
+            context.output.log_output(stdout)
+            context.output.log_output(stderr)
             if stderr:
                 sys.__stderr__.write(stderr+'\n')

-    def _run_with_signal_monitoring(self, runner):
+    def _run_with_signal_monitoring(self, runner, context):
         try:
-            STOP_SIGNAL_MONITOR.start_running_keyword()
+            STOP_SIGNAL_MONITOR.start_running_keyword(context.teardown)
             return runner()
         finally:
             STOP_SIGNAL_MONITOR.stop_running_keyword()
@@ -214,7 +214,7 @@
_PythonHandler.__init__(self, library, handler_name, handler_method)
         self._handler_method = handler_method

-    def _run_with_signal_monitoring(self, runner):
+    def _run_with_signal_monitoring(self, runner, context):
         # With run keyword variants, only the keyword to be run can fail
         # and therefore monitoring should not raise exception yet.
         return runner()
=======================================
--- /trunk/src/robot/running/signalhandler.py   Sat Sep 11 04:28:16 2010
+++ /trunk/src/robot/running/signalhandler.py   Thu Sep 16 00:17:34 2010
@@ -24,7 +24,6 @@
     def __init__(self):
         self._signal_count = 0
         self._running_keyword = False
-        self._error_reported = False

     def __call__(self, signum, frame):
         self._signal_count += 1
@@ -37,17 +36,15 @@
             self._stop_execution_gracefully()

     def _stop_execution_gracefully(self):
-        if not self._error_reported:
-            self._error_reported = True
- raise ExecutionFailed('Execution terminated by signal', exit=True)
+        raise ExecutionFailed('Execution terminated by signal', exit=True)

     def start(self):
         signal.signal(signal.SIGINT, self)
         signal.signal(signal.SIGTERM, self)

-    def start_running_keyword(self):
+    def start_running_keyword(self, in_teardown):
         self._running_keyword = True
-        if self._signal_count:
+        if self._signal_count and not in_teardown:
             self._stop_execution_gracefully()

     def stop_running_keyword(self):
=======================================
--- /trunk/utest/running/test_testlibrary.py    Tue Jul 20 06:53:37 2010
+++ /trunk/utest/running/test_testlibrary.py    Thu Sep 16 00:17:34 2010
@@ -1,14 +1,14 @@
 import unittest
 import sys

-from robot.running.testlibraries import TestLibrary, _ClassLibrary, \
-        _ModuleLibrary, _DynamicLibrary
+from robot.running.testlibraries import (TestLibrary, _ClassLibrary,
+                                         _ModuleLibrary, _DynamicLibrary)
 from robot.utils.asserts import *
 from robot import utils
 from robot.errors import DataError

-from classes import NameLibrary, DocLibrary, ArgInfoLibrary, GetattrLibrary, \
-        SynonymLibrary
+from classes import (NameLibrary, DocLibrary, ArgInfoLibrary, GetattrLibrary,
+                     SynonymLibrary)
 if utils.is_jython:
import ArgumentTypes, Extended, MultipleArguments, MultipleSignatures, NoHandlers

@@ -511,6 +511,7 @@
         self.output = _FakeOutput()
         self.namespace =  _FakeNamespace()
         self.dry_run = False
+        self.teardown = False

     def get_current_vars(self):
         return self.namespace.variables

Reply via email to