"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test_suite/relax_test_runner.py" between
relax-4.1.3.src.tar.bz2 and relax-5.0.0.src.tar.bz2

About: relax allows the study of molecular dynamics through the analysis of experimental NMR data. Organic molecules, proteins, RNA, DNA, sugars, and other biomolecules are all supported.

relax_test_runner.py  (relax-4.1.3.src.tar.bz2):relax_test_runner.py  (relax-5.0.0.src.tar.bz2)
############################################################################### ###############################################################################
# # # #
# Copyright (C) 2008,2011,2013-2014 Edward d'Auvergne # # Copyright (C) 2008,2011,2013-2014,2019 Edward d'Auvergne #
# # # #
# This file is part of the program relax (http://www.nmr-relax.com). # # This file is part of the program relax (http://www.nmr-relax.com). #
# # # #
# This program is free software: you can redistribute it and/or modify # # This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by # # it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or # # the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. # # (at your option) any later version. #
# # # #
# This program is distributed in the hope that it will be useful, # # This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of # # but WITHOUT ANY WARRANTY; without even the implied warranty of #
skipping to change at line 27 skipping to change at line 27
# You should have received a copy of the GNU General Public License # # You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. # # along with this program. If not, see <http://www.gnu.org/licenses/>. #
# # # #
############################################################################### ###############################################################################
# Python module imports. # Python module imports.
import dep_check import dep_check
from re import search, split from re import search, split
import sys import sys
from time import time from time import time
from traceback import print_exception
from unittest import TextTestRunner from unittest import TextTestRunner
if dep_check.wx_module: if dep_check.wx_module:
import wx import wx
# relax module imports. # relax module imports.
from lib.compat import StringIO from lib.compat import StringIO
from lib.compat import TextTestResult from lib.compat import TextTestResult
from status import Status; status = Status() from status import Status; status = Status()
from test_suite.formatting import divider, format_test_name, test_title
class RelaxTestResult(TextTestResult): class RelaxTestResult(TextTestResult):
"""A replacement for the TextTestResult class. """A replacement for the TextTestResult class.
This class is designed to catch STDOUT and STDERR during the execution of ea ch test and to This class is designed to catch STDOUT and STDERR during the execution of ea ch test and to
prepend the output to the failure and error reports normally generated by Te xtTestRunner. prepend the output to the failure and error reports normally generated by Te xtTestRunner.
""" """
def __init__(self, stream, descriptions, verbosity, timing=False, category=N one): def __init__(self, stream, descriptions, verbosity, category=None, timing=Fa lse, io_capture=True):
"""Initialise the RelaxTestResult object with relax specific variables. """Initialise the RelaxTestResult object with relax specific variables.
@keyword timing: A flag which if True will enable timing of individua @param stream: The IO stream to write all output to.
l tests. @type stream: writable object
@type timing: bool @param descriptions: A flag which if True will cause the test descrip
@keyword category: The type of test being performed, to allow the print tion to be printed out, when the verbosity is > 1.
outs to be changed. This can be one of 'system', 'unit', 'gui', or 'verificatio @type descriptions: bool
n'. the printout. @param verbosity: The verbosity level.
@type category: str @type verbosity: int
@keyword category: The type of test being performed, to allow the p
rintouts to be changed. This can be one of 'system', 'unit', 'gui', or 'verific
ation'.
@type category: str
@keyword timing: A flag which if True will enable timing of indiv
idual tests.
@type timing: bool
@keyword io_capture: A flag which if True will cause all IO to be cap
tured and only printed out for failing or error tests.
@type io_capture: bool
""" """
# Normal setup. # Normal setup.
super(RelaxTestResult, self).__init__(stream, descriptions, verbosity) super(RelaxTestResult, self).__init__(stream, descriptions, verbosity)
# Store the timing flag and category. # Store the flags and category.
self.timing_flag = timing self.timing_flag = timing
self.io_capture = io_capture
self.category = category self.category = category
# Set the separator widths.
self.separator1 = '=' * status.text_width
self.separator2 = '-' * status.text_width
def addError(self, test, err): def addError(self, test, err):
"""Override of the TestResult.addError() method. """Override of the TestResult.addError() method.
The STDOUT and STDERR captured text is prepended to the error text here. The STDOUT and STDERR captured text is prepended to the error text here.
@param test: The test object. @param test: The test object.
@type test: TestCase instance @type test: TestCase instance
@param err: A tuple of values as returned by sys.exc_info(). @param err: A tuple of values as returned by sys.exc_info().
@type err: tuple of values @type err: tuple of values
""" """
# Extra formatting for no IO capture.
if not self.io_capture:
self.stream.write(self._exc_info_to_string(err, test))
divider('-', width=status.text_width)
# Execute the base class method to print the 'E' and handle the error. # Execute the base class method to print the 'E' and handle the error.
super(RelaxTestResult, self).addError(test, err) super(RelaxTestResult, self).addError(test, err)
# Prepend the STDOUT and STDERR messages to the second element of the tu ple. # Prepend the STDOUT and STDERR messages to the second element of the tu ple.
self.errors[-1] = (self.errors[-1][0], self.capt.getvalue() + self.error if self.io_capture:
s[-1][1]) self.errors[-1] = (self.errors[-1][0], self.capt.getvalue() + self.e
rrors[-1][1])
# Write out timing info. # Write out timing info.
if self.timing_flag: if self.timing_flag or not self.io_capture:
self.write_time(test.id()) self.write_time(test.id())
def addFailure(self, test, err): def addFailure(self, test, err):
"""Override of the TestResult.addFailure() method. """Override of the TestResult.addFailure() method.
The STDOUT and STDERR captured text is prepended to the failure text her e. The STDOUT and STDERR captured text is prepended to the failure text her e.
@param test: The test object. @param test: The test object.
@type test: TestCase instance @type test: TestCase instance
@param err: A tuple of values as returned by sys.exc_info(). @param err: A tuple of values as returned by sys.exc_info().
@type err: tuple of values @type err: tuple of values
""" """
# Extra formatting for no IO capture.
if not self.io_capture:
self.stream.write(self._exc_info_to_string(err, test))
divider('-', width=status.text_width)
# Execute the base class method to print the 'F' and handle the failure. # Execute the base class method to print the 'F' and handle the failure.
super(RelaxTestResult, self).addFailure(test, err) super(RelaxTestResult, self).addFailure(test, err)
# Prepend the STDOUT and STDERR messages to the second element of the tu ple. # Prepend the STDOUT and STDERR messages to the second element of the tu ple.
self.failures[-1] = (self.failures[-1][0], self.capt.getvalue() + self.f if self.io_capture:
ailures[-1][1]) self.failures[-1] = (self.failures[-1][0], self.capt.getvalue() + se
lf.failures[-1][1])
# Write out timing info. # Write out timing info.
if self.timing_flag: if self.timing_flag or not self.io_capture:
self.write_time(test.id()) self.write_time(test.id())
def addSuccess(self, test): def addSuccess(self, test):
"""The method for a successful test. """The method for a successful test.
@param test: The test object. @param test: The test object.
@type test: TestCase instance @type test: TestCase instance
""" """
# Extra formatting for no IO capture.
if not self.io_capture:
divider('-', width=status.text_width)
# Execute the base class method to print the '.'. # Execute the base class method to print the '.'.
super(RelaxTestResult, self).addSuccess(test) super(RelaxTestResult, self).addSuccess(test)
# Write out timing info. # Write out timing info.
if self.timing_flag: if self.timing_flag or not self.io_capture:
self.write_time(test.id()) self.write_time(test.id())
def startTest(self, test): def startTest(self, test):
"""Override of the TextTestResult.startTest() method. """Override of the TextTestResult.startTest() method.
The start of STDOUT and STDERR capture occurs here. The start of STDOUT and STDERR capture occurs here.
""" """
# Store the original STDOUT and STDERR for restoring later on. # IO capture.
self.orig_stdout = sys.stdout if self.io_capture:
self.orig_stderr = sys.stderr # Store the original STDOUT and STDERR for restoring later on.
self.orig_stdout = sys.stdout
# Catch stdout and stderr. self.orig_stderr = sys.stderr
self.capt = StringIO()
if not status.debug: # Catch stdout and stderr.
self.capt = StringIO()
sys.stdout = self.capt sys.stdout = self.capt
sys.stderr = self.capt sys.stderr = self.capt
# No capture.
else:
test_title(format_test_name(test.id()), desc=test.shortDescription()
, width=status.text_width)
# Place the test name in the status object. # Place the test name in the status object.
status.exec_lock.test_name = str(test) status.exec_lock.test_name = str(test)
# Store the starting time. # Store the starting time.
if self.timing_flag: if self.timing_flag or not self.io_capture:
self.time = time() self.time = time()
# Execute the normal startTest method. # Execute the normal startTest method.
super(RelaxTestResult, self).startTest(test) super(RelaxTestResult, self).startTest(test)
def stopTest(self, test): def stopTest(self, test):
"""Override of the TextTestResult.stopTest() method. """Override of the TextTestResult.stopTest() method.
The end of STDOUT and STDERR capture occurs here. The end of STDOUT and STDERR capture occurs here.
""" """
# Restore the IO streams. # Restore the IO streams.
sys.stdout = self.orig_stdout if self.io_capture:
sys.stderr = self.orig_stderr sys.stdout = self.orig_stdout
sys.stderr = self.orig_stderr
def write_time(self, test_name): def write_time(self, test_name):
"""Write the timing of the test to the stream. """Write the timing of the test to the stream.
@param test_name: The TestCase name. @param test_name: The TestCase name.
@type test_name: str @type test_name: str
""" """
# Subtract the end time from the start time. # Subtract the end time from the start time.
self.time -= time() self.time -= time()
# Change the test name for all but unit tests. # Format the name.
if self.category != 'unit': test_name = format_test_name(test_name)
test_name = test_name.split('.')
test_name = "%s.%s" % (test_name[-2], test_name[-1])
# Handle errors.
elif search('Error', test_name):
pass
# Modify the unit test name printout.
else:
# Strip out the leading 'test_suite.unit_tests.' text.
test_name = test_name.replace('test_suite.unit_tests.', '')
# Split out the module name from the test name.
module_name, test_name = split('.Test_', test_name)
# Rebuild the test name.
test_name = "module %s, test Test_%s" % (module_name, test_name)
# The printout. # The printout.
if self.category == 'unit': if self.category == 'unit':
time_str = '%7.2f ms' % (abs(self.time) * 1000) time_str = '%7.2f ms' % (abs(self.time) * 1000)
else: else:
time_str = '%7.2f s' % abs(self.time) time_str = '%7.2f s' % abs(self.time)
self.stream.write(' %s for %s\n' % (time_str, test_name)) self.stream.write(' %s for %s\n' % (time_str, test_name))
class GuiTestResult(RelaxTestResult): class GuiTestResult(RelaxTestResult):
"""A replacement for the TextTestResult class for the GUI.""" """A replacement for the TextTestResult class for the GUI."""
skipping to change at line 213 skipping to change at line 233
class RelaxTestRunner(TextTestRunner): class RelaxTestRunner(TextTestRunner):
"""A replacement unittest runner. """A replacement unittest runner.
This runner is designed to catch STDOUT during the execution of each test an d to prepend the This runner is designed to catch STDOUT during the execution of each test an d to prepend the
output to the failure and error reports normally generated by TextTestRunner . output to the failure and error reports normally generated by TextTestRunner .
""" """
# Variable for specifying the type of test being performed, to change the pr intout. # Variable for specifying the type of test being performed, to change the pr intout.
category = None category = None
def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfa st=False, buffer=False, resultclass=None, timing=False): def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfa st=False, buffer=False, resultclass=None, timing=False, io_capture=True):
"""Initialise the class, storing the timing flag. """Initialise the class, storing the timing flag.
@param stream: The IO stream to write all output to.
@type stream: writable object
@param descriptions: A flag which if True will cause the test descrip
tion to be printed out, when the verbosity is > 1.
@type descriptions: bool
@param verbosity: The verbosity level.
@type verbosity: int
@keyword timing: A flag which if True will enable timing of indiv idual tests. @keyword timing: A flag which if True will enable timing of indiv idual tests.
@type timing: bool @type timing: bool
@keyword io_capture: A flag which if True will cause all IO to be cap
tured and only printed out for failing or error tests.
@type io_capture: bool
""" """
# Execute the base method (with different Python version compatibility). # Execute the base method (with different Python version compatibility).
if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.versi on_info[0] == 2 and sys.version_info[1] <= 6): if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.versi on_info[0] == 2 and sys.version_info[1] <= 6):
super(RelaxTestRunner, self).__init__(stream=stream, descriptions=de scriptions, verbosity=verbosity) super(RelaxTestRunner, self).__init__(stream=stream, descriptions=de scriptions, verbosity=verbosity)
else: else:
super(RelaxTestRunner, self).__init__(stream=stream, descriptions=de scriptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=r esultclass) super(RelaxTestRunner, self).__init__(stream=stream, descriptions=de scriptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=r esultclass)
# Store the flag. # Store the flags.
self.timing_flag = timing self.timing_flag = timing
self.io_capture = io_capture
def _makeResult(self): def _makeResult(self):
"""Override of the TextTestRunner._makeResult() method.""" """Override of the TextTestRunner._makeResult() method."""
return RelaxTestResult(self.stream, self.descriptions, self.verbosity, t iming=self.timing_flag, category=self.category) return RelaxTestResult(self.stream, self.descriptions, self.verbosity, t iming=self.timing_flag, io_capture=self.io_capture, category=self.category)
class GuiTestRunner(TextTestRunner): class GuiTestRunner(TextTestRunner):
"""A replacement unittest runner. """A replacement unittest runner.
This runner is designed to catch STDOUT during the execution of each test an d to prepend the This runner is designed to catch STDOUT during the execution of each test an d to prepend the
output to the failure and error reports normally generated by TextTestRunner . output to the failure and error reports normally generated by TextTestRunner .
""" """
def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfa st=False, buffer=False, resultclass=None, timing=False): def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, failfa st=False, buffer=False, resultclass=None, timing=False, io_capture=True):
"""Initialise the class, storing the timing flag. """Initialise the class, storing the timing flag.
@param stream: The IO stream to write all output to.
@type stream: writable object
@param descriptions: A flag which if True will cause the test descrip
tion to be printed out, when the verbosity is > 1.
@type descriptions: bool
@param verbosity: The verbosity level.
@type verbosity: int
@keyword timing: A flag which if True will enable timing of indiv idual tests. @keyword timing: A flag which if True will enable timing of indiv idual tests.
@type timing: bool @type timing: bool
@keyword io_capture: A flag which if True will cause all IO to be cap
tured and only printed out for failing or error tests.
@type io_capture: bool
""" """
# Execute the base method. # Execute the base method.
if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.versi on_info[0] == 2 and sys.version_info[1] <= 6): if (sys.version_info[0] == 3 and sys.version_info[1] == 1) or (sys.versi on_info[0] == 2 and sys.version_info[1] <= 6):
super(GuiTestRunner, self).__init__(stream=stream, descriptions=desc riptions, verbosity=verbosity) super(GuiTestRunner, self).__init__(stream=stream, descriptions=desc riptions, verbosity=verbosity)
else: else:
super(GuiTestRunner, self).__init__(stream=stream, descriptions=desc riptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=res ultclass) super(GuiTestRunner, self).__init__(stream=stream, descriptions=desc riptions, verbosity=verbosity, failfast=failfast, buffer=buffer, resultclass=res ultclass)
# Store the flag. # Store the flags.
self.timing_flag = timing self.timing_flag = timing
self.io_capture = io_capture
def _makeResult(self): def _makeResult(self):
"""Override of the TextTestRunner._makeResult() method.""" """Override of the TextTestRunner._makeResult() method."""
return GuiTestResult(self.stream, self.descriptions, self.verbosity, tim ing=self.timing_flag) return GuiTestResult(self.stream, self.descriptions, self.verbosity, tim ing=self.timing_flag, io_capture=self.io_capture)
 End of changes. 33 change blocks. 
51 lines changed or deleted 96 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)