Author: bugman Date: Thu Jun 12 14:47:31 2014 New Revision: 23881 URL: http://svn.gna.org/viewcvs/relax?rev=23881&view=rev Log: Better handling of the control-C keyboard interrupt signal in the relax test suite. This includes two changes. The Python 2.7 and higher unittest.installHandler() function is now called, when present, to terminate all tests using the unittest module control-C handler. The second change is that the keyboard interrupt signal is caught in a try-except statement, a message printed out, and the tests terminated. This should be an improvement for all systems. Modified: trunk/test_suite/test_suite_runner.py Modified: trunk/test_suite/test_suite_runner.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/test_suite_runner.py?rev=23881&r1=23880&r2=23881&view=diff ============================================================================== --- trunk/test_suite/test_suite_runner.py (original) +++ trunk/test_suite/test_suite_runner.py Thu Jun 12 14:47:31 2014 @@ -27,6 +27,7 @@ import sys if dep_check.wx_module: import wx +import unittest # Formatting. from test_suite.formatting import summary_line @@ -87,133 +88,192 @@ else: self.runner = RelaxTestRunner(stream=sys.stdout, timing=timing) + # Let the tests handle the keyboard interrupt (for Python 2.7 and higher). + if hasattr(unittest, 'installHandler'): + unittest.installHandler() + def run_all_tests(self): """Execute all of the test suite test types.""" # Execute the system/functional tests. if 'system' in self.categories: - self.run_system_tests(summary=False) + status = self.run_system_tests(summary=False) + if not status: + return # Execute the unit tests. if 'unit' in self.categories: - self.run_unit_tests(summary=False) + status = self.run_unit_tests(summary=False) + if not status: + return # Execute the GUI tests. if 'gui' in self.categories: - self.run_gui_tests(summary=False) + status = self.run_gui_tests(summary=False) + if not status: + return # Execute the GUI tests. if 'verification' in self.categories: - self.run_verification_tests(summary=False) + status = self.run_verification_tests(summary=False) + if not status: + return # Print out a summary of the test suite. self.summary() + def run_gui_tests(self, summary=True): """Execute the GUI tests. + + @keyword summary: A flag which if True will cause a summary to be printed. + @type summary: bool + @return: True if the tests were run, False if a KeyboardInterrupt occurred. + @rtype: bool + """ + + # Run the tests, catching the keyboard interrupt. + try: + # Print a header. + title(file=sys.stdout, text='GUI tests') + + # Run the tests. + if dep_check.wx_module: + # Set up the GUI if needed (i.e. not in GUI mode already). + app = wx.GetApp() + if app == None: + # Initialise. + app = wx.App(redirect=False) + + # Build the GUI. + app.gui = relax_gui.Main(parent=None, id=-1, title="") + + # Execute the GUI tests. + gui_runner = GUI_test_runner() + self.runner.category = 'gui' + self.gui_result = gui_runner.run(self.tests, runner=self.runner) + + # Clean up for the GUI, if not in GUI mode. + if status.test_mode: + # Terminate the interpreter thread to allow the tests to cleanly exit. + interpreter_thread = interpreter.Interpreter() + interpreter_thread.exit() + + # Stop the GUI main loop. + app.ExitMainLoop() + + # No wx module installed. + else: + print("All GUI tests skipped due to the missing/broken wx module.\n") + self.gui_result = 'skip' + + # Print out a summary of the test suite. + if summary: + self.summary() + + # Catch the keyboard interrupt. + except KeyboardInterrupt: + print("\nKeyboardInterrupt: Terminating all tests.\n") + return False + + # All tests were run successfully. + return True + + + def run_system_tests(self, summary=True): + """Execute the system/functional tests. + + @keyword summary: A flag which if True will cause a summary to be printed. + @type summary: bool + @return: True if the tests were run, False if a KeyboardInterrupt occurred. + @rtype: bool + """ + + # Run the tests, catching the keyboard interrupt. + try: + # Print a header. + title(file=sys.stdout, text='System / functional tests') + + # Run the tests. + system_runner = System_test_runner() + self.runner.category = 'system' + self.system_result = system_runner.run(self.tests, runner=self.runner) + + # Print out a summary of the test suite. + if summary: + self.summary() + + # Catch the keyboard interrupt. + except KeyboardInterrupt: + print("\nKeyboardInterrupt: Terminating all tests.\n") + return False + + # All tests were run successfully. + return True + + + def run_unit_tests(self, summary=True): + """Execute the unit tests. + + @keyword summary: A flag which if True will cause a summary to be printed. + @type summary: bool + @return: True if the tests were run, False if a KeyboardInterrupt occurred. + @rtype: bool + """ + + # Run the tests, catching the keyboard interrupt. + try: + # Print a header. + title(file=sys.stdout, text='Unit tests') + + # Run the tests. + unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests') + self.runner.category = 'unit' + self.unit_result = unit_runner.run(runner=self.runner) + + # Print out a summary of the test suite. + if summary: + self.summary() + + # Catch the keyboard interrupt. + except KeyboardInterrupt: + print("\nKeyboardInterrupt: Terminating all tests.\n") + return False + + # All tests were run successfully. + return True + + + def run_verification_tests(self, summary=True): + """Execute the software verification tests. @keyword summary: A flag which if True will cause a summary to be printed. @type summary: bool """ - # Print a header. - title(file=sys.stdout, text='GUI tests') - - # Run the tests. - if dep_check.wx_module: - # Set up the GUI if needed (i.e. not in GUI mode already). - app = wx.GetApp() - if app == None: - # Initialise. - app = wx.App(redirect=False) - - # Build the GUI. - app.gui = relax_gui.Main(parent=None, id=-1, title="") - - # Execute the GUI tests. - gui_runner = GUI_test_runner() - self.runner.category = 'gui' - self.gui_result = gui_runner.run(self.tests, runner=self.runner) - - # Clean up for the GUI, if not in GUI mode. - if status.test_mode: - # Terminate the interpreter thread to allow the tests to cleanly exit. - interpreter_thread = interpreter.Interpreter() - interpreter_thread.exit() - - # Stop the GUI main loop. - app.ExitMainLoop() - - # No wx module installed. - else: - print("All GUI tests skipped due to the missing/broken wx module.\n") - self.gui_result = 'skip' - - # Print out a summary of the test suite. - if summary: - self.summary() - - - def run_system_tests(self, summary=True): - """Execute the system/functional tests. - - @keyword summary: A flag which if True will cause a summary to be printed. - @type summary: bool - """ - - # Print a header. - title(file=sys.stdout, text='System / functional tests') - - # Run the tests. - system_runner = System_test_runner() - self.runner.category = 'system' - self.system_result = system_runner.run(self.tests, runner=self.runner) - - # Print out a summary of the test suite. - if summary: - self.summary() - - - def run_unit_tests(self, summary=True): - """Execute the unit tests. - - @keyword summary: A flag which if True will cause a summary to be printed. - @type summary: bool - """ - - # Print a header. - title(file=sys.stdout, text='Unit tests') - - # Run the tests. - unit_runner = Unit_test_runner(root_path=status.install_path+os.sep+'test_suite'+os.sep+'unit_tests') - self.runner.category = 'unit' - self.unit_result = unit_runner.run(runner=self.runner) - - # Print out a summary of the test suite. - if summary: - self.summary() - - - def run_verification_tests(self, summary=True): - """Execute the software verification tests. - - @keyword summary: A flag which if True will cause a summary to be printed. - @type summary: bool - """ - - # Print a header. - title(file=sys.stdout, text='Software verification tests') - - # Run the tests. - verification_runner = Verification_test_runner() - self.runner.category = 'verification' - self.verification_result = verification_runner.run(self.tests, runner=self.runner) - - # Print out a summary of the test suite. - if summary: - self.summary() + # Run the tests, catching the keyboard interrupt. + try: + # Print a header. + title(file=sys.stdout, text='Software verification tests') + + # Run the tests. + verification_runner = Verification_test_runner() + self.runner.category = 'verification' + self.verification_result = verification_runner.run(self.tests, runner=self.runner) + + # Print out a summary of the test suite. + if summary: + self.summary() + + # Catch the keyboard interrupt. + except KeyboardInterrupt: + print("\nKeyboardInterrupt: Terminating all tests.\n") + return False + + # All tests were run successfully. + return True def summary(self):