mailr19703 - in /trunk: relax.py test_suite/relax_test_runner.py test_suite/test_suite_runner.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on May 23, 2013 - 18:39:
Author: bugman
Date: Thu May 23 18:39:09 2013
New Revision: 19703

URL: http://svn.gna.org/viewcvs/relax?rev=19703&view=rev
Log:
The timing of individual tests in the relax test suite can now be printed out.

The new command line argument --time has been added which, when supplied with 
one of the test suite
arguments, will cause the time required to complete each individual test to 
be displayed.  Instead
of just printing the characters '.', 'F', and 'E' for each test, now these 
characters are postfixed
with the time in seconds, the name of the test and ending in a newline 
character.


Modified:
    trunk/relax.py
    trunk/test_suite/relax_test_runner.py
    trunk/test_suite/test_suite_runner.py

Modified: trunk/relax.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/relax.py?rev=19703&r1=19702&r2=19703&view=diff
==============================================================================
--- trunk/relax.py (original)
+++ trunk/relax.py Thu May 23 18:39:09 2013
@@ -215,7 +215,7 @@
             self.interpreter.on()
 
             # Run the tests.
-            runner = Test_suite_runner(self.tests)
+            runner = Test_suite_runner(self.tests, timing=self.test_timings)
             runner.run_all_tests()
 
         # Execute the relax system tests.
@@ -228,7 +228,7 @@
             self.interpreter.on()
 
             # Run the tests.
-            runner = Test_suite_runner(self.tests)
+            runner = Test_suite_runner(self.tests, timing=self.test_timings)
             runner.run_system_tests()
 
         # Execute the relax unit tests.
@@ -237,7 +237,7 @@
             from test_suite.test_suite_runner import Test_suite_runner
 
             # Run the tests.
-            runner = Test_suite_runner(self.tests)
+            runner = Test_suite_runner(self.tests, timing=self.test_timings)
             runner.run_unit_tests()
 
         # Execute the relax GUI tests.
@@ -246,7 +246,7 @@
             from test_suite.test_suite_runner import Test_suite_runner
 
             # Run the tests.
-            runner = Test_suite_runner(self.tests)
+            runner = Test_suite_runner(self.tests, timing=self.test_timings)
             runner.run_gui_tests()
 
         # Test mode.
@@ -280,6 +280,7 @@
         parser.add_option('-s', '--system-tests', action='store_true', 
dest='system_tests', default=0, help='execute the relax system/functional 
tests (part of the test suite)')
         parser.add_option('-u', '--unit-tests', action='store_true', 
dest='unit_tests', default=0, help='execute the relax unit tests (part of the 
test suite)')
         parser.add_option('--gui-tests', action='store_true', 
dest='gui_tests', default=0, help='execute the relax GUI tests (part of the 
test suite)')
+        parser.add_option('--time', action='store_true', dest='tt', 
default=0, help='enable the timing of individual tests in the test suite')
         parser.add_option('-i', '--info', action='store_true', dest='info', 
default=0, help='display information about this version of relax')
         parser.add_option('-v', '--version', action='store_true', 
dest='version', default=0, help='show the version number and exit')
         parser.add_option('-m', '--multi', action='store', type='string', 
dest='multiprocessor', default='uni', help='set multi processor method')
@@ -328,7 +329,13 @@
 
         # Test suite mode, therefore the args are the tests to run and not a 
script file.
         if options.test_suite or options.system_tests or options.unit_tests 
or options.gui_tests:
+            # Store the arguments.
             self.tests = args
+
+            # Test timings.
+            self.test_timings = False
+            if options.tt:
+                self.test_timings = True
 
         # The argument is a script.
         else:

Modified: trunk/test_suite/relax_test_runner.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/relax_test_runner.py?rev=19703&r1=19702&r2=19703&view=diff
==============================================================================
--- trunk/test_suite/relax_test_runner.py (original)
+++ trunk/test_suite/relax_test_runner.py Thu May 23 18:39:09 2013
@@ -22,6 +22,7 @@
 # Python module imports.
 import dep_check
 import sys
+from time import time
 from unittest import TextTestRunner
 if dep_check.wx_module:
     import wx
@@ -38,6 +39,81 @@
     This class is designed to catch STDOUT and STDERR during the execution 
of each test and to
     prepend the output to the failure and error reports normally generated 
by TextTestRunner.
     """
+
+    def __init__(self, stream, descriptions, verbosity, timing=False):
+        """Initialise the RelaxTestResult object with relax specific 
variables.
+
+        @keyword timing:    A flag which if True will enable timing of 
individual tests.
+        @type timing:       bool
+        """
+
+        # Normal setup.
+        super(RelaxTestResult, self).__init__(stream, descriptions, 
verbosity)
+
+        # Store the timing flag.
+        self.timing_flag = timing
+
+
+    def addError(self, test, err):
+        """Override of the TestResult.addError() method.
+
+        The STDOUT and STDERR captured text is prepended to the error text 
here.
+
+
+        @param test:    The test object.
+        @type test:     TestCase instance
+        @param err:     A tuple of values as returned by sys.exc_info().
+        @type err:      tuple of values
+        """
+
+        # Execute the base class method to print the 'E' and handle the 
error.
+        super(RelaxTestResult, self).addError(test, err)
+
+        # Prepend the STDOUT and STDERR messages to the second element of 
the tuple.
+        self.errors[-1] = (self.errors[-1][0], self.capt.getvalue() + 
self.errors[-1][1])
+
+        # Write out timing info.
+        if self.timing_flag:
+            self.write_time(test.id())
+
+
+    def addFailure(self, test, err):
+        """Override of the TestResult.addFailure() method.
+
+        The STDOUT and STDERR captured text is prepended to the failure text 
here.
+
+
+        @param test:    The test object.
+        @type test:     TestCase instance
+        @param err:     A tuple of values as returned by sys.exc_info().
+        @type err:      tuple of values
+        """
+
+        # Execute the base class method to print the 'F' and handle the 
failure.
+        super(RelaxTestResult, self).addFailure(test, err)
+
+        # Prepend the STDOUT and STDERR messages to the second element of 
the tuple.
+        self.failures[-1] = (self.failures[-1][0], self.capt.getvalue() + 
self.failures[-1][1])
+
+        # Write out timing info.
+        if self.timing_flag:
+            self.write_time(test.id())
+
+
+    def addSuccess(self, test):
+        """The method for a successful test.
+
+        @param test:    The test object.
+        @type test:     TestCase instance
+        """
+
+        # Execute the base class method to print the '.'.
+        super(RelaxTestResult, self).addSuccess(test)
+
+        # Write out timing info.
+        if self.timing_flag:
+            self.write_time(test.id())
+
 
     def startTest(self, test):
         """Override of the TextTestResult.startTest() method.
@@ -58,8 +134,12 @@
         # Place the test name in the status object.
         status.exec_lock.test_name = str(test)
 
+        # Store the starting time.
+        if self.timing_flag:
+            self.time = time()
+
         # Execute the normal startTest method.
-        TextTestResult.startTest(self, test)
+        super(RelaxTestResult, self).startTest(test)
 
 
     def stopTest(self, test):
@@ -73,30 +153,18 @@
         sys.stderr = self.orig_stderr
 
 
-    def addError(self, test, err):
-        """Override of the TestResult.addError() method.
-
-        The STDOUT and STDERR captured text is prepended to the error text 
here.
-        """
-
-        # Execute the normal addError method.
-        TextTestResult.addError(self, test, err)
-
-        # Prepend the STDOUT and STDERR messages to the second element of 
the tuple.
-        self.errors[-1] = (self.errors[-1][0], self.capt.getvalue() + 
self.errors[-1][1])
-
-
-    def addFailure(self, test, err):
-        """Override of the TestResult.addFailure() method.
-
-        The STDOUT and STDERR captured text is prepended to the failure text 
here.
-        """
-
-        # Execute the normal addFailure method.
-        TextTestResult.addFailure(self, test, err)
-
-        # Prepend the STDOUT and STDERR messages to the second element of 
the tuple.
-        self.failures[-1] = (self.failures[-1][0], self.capt.getvalue() + 
self.failures[-1][1])
+    def write_time(self, test_name):
+        """Write the timing of the test to the stream.
+
+        @param test:    The TestCase name.
+        @type test:     str
+        """
+
+        # Subtract the end time from the start time.
+        self.time -= time()
+
+        # The printout.
+        self.stream.write('  %7.2f s for %s.\n' % (-self.time, test_name))
 
 
 
@@ -124,10 +192,24 @@
     output to the failure and error reports normally generated by 
TextTestRunner.
     """
 
+    def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, 
failfast=False, buffer=False, resultclass=None, timing=False):
+        """Initialise the class, storing the timing flag.
+
+        @keyword timing:        A flag which if True will enable timing of 
individual tests.
+        @type timing:           bool
+        """
+
+        # Execute the base method.
+        super(RelaxTestRunner, self).__init__(stream=stream, 
descriptions=descriptions, verbosity=verbosity, failfast=failfast, 
buffer=buffer, resultclass=resultclass)
+
+        # Store the flag.
+        self.timing_flag = timing
+
+
     def _makeResult(self):
         """Override of the TextTestRunner._makeResult() method."""
 
-        return RelaxTestResult(self.stream, self.descriptions, 
self.verbosity)
+        return RelaxTestResult(self.stream, self.descriptions, 
self.verbosity, timing=self.timing_flag)
 
 
 
@@ -138,7 +220,21 @@
     output to the failure and error reports normally generated by 
TextTestRunner.
     """
 
+    def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, 
failfast=False, buffer=False, resultclass=None, timing=False):
+        """Initialise the class, storing the timing flag.
+
+        @keyword timing:        A flag which if True will enable timing of 
individual tests.
+        @type timing:           bool
+        """
+
+        # Execute the base method.
+        super(GuiTestRunner, self).__init__(stream=stream, 
descriptions=descriptions, verbosity=verbosity, failfast=failfast, 
buffer=buffer, resultclass=resultclass)
+
+        # Store the flag.
+        self.timing_flag = timing
+
+
     def _makeResult(self):
         """Override of the TextTestRunner._makeResult() method."""
 
-        return GuiTestResult(self.stream, self.descriptions, self.verbosity)
+        return GuiTestResult(self.stream, self.descriptions, self.verbosity, 
timing=self.timing_flag)

Modified: trunk/test_suite/test_suite_runner.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/test_suite_runner.py?rev=19703&r1=19702&r2=19703&view=diff
==============================================================================
--- trunk/test_suite/test_suite_runner.py (original)
+++ trunk/test_suite/test_suite_runner.py Thu May 23 18:39:09 2013
@@ -55,7 +55,7 @@
         - GUI tests.
     """
 
-    def __init__(self, tests=[], from_gui=False, categories=['system', 
'unit', 'gui']):
+    def __init__(self, tests=[], from_gui=False, categories=['system', 
'unit', 'gui'], timing=False):
         """Store the list of tests to preform.
 
         The test list should be something like 
['N_state_model.test_stereochem_analysis'].  The first part is the imported 
test case class, the second is the specific test.
@@ -67,6 +67,8 @@
         @type from_gui:         bool
         @keyword categories:    The list of test categories to run, for 
example ['system', 'unit', 'gui'] for all tests.
         @type categories:       list of str
+        @keyword timing:        A flag which if True will enable timing of 
individual tests.
+        @type timing:           bool
         """
 
         # Store the args.
@@ -79,9 +81,9 @@
 
         # Set up the test runner.
         if from_gui:
-            self.runner = GuiTestRunner(stream=sys.stdout)
+            self.runner = GuiTestRunner(stream=sys.stdout, timing=timing)
         else:
-            self.runner = RelaxTestRunner(stream=sys.stdout)
+            self.runner = RelaxTestRunner(stream=sys.stdout, timing=timing)
 
 
     def run_all_tests(self):




Related Messages


Powered by MHonArc, Updated Thu May 23 19:00:02 2013