"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/test_suite/verification_tests/__init__.py" (6 Dec 2019, 4956 Bytes) of package /linux/privat/relax-5.0.0.src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "__init__.py": 4.1.3_vs_5.0.0.

    1 ###############################################################################
    2 #                                                                             #
    3 # Copyright (C) 2006,2008-2012,2014,2019 Edward d'Auvergne                    #
    4 #                                                                             #
    5 # This file is part of the program relax (http://www.nmr-relax.com).          #
    6 #                                                                             #
    7 # This program is free software: you can redistribute it and/or modify        #
    8 # it under the terms of the GNU General Public License as published by        #
    9 # the Free Software Foundation, either version 3 of the License, or           #
   10 # (at your option) any later version.                                         #
   11 #                                                                             #
   12 # This program is distributed in the hope that it will be useful,             #
   13 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
   14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
   15 # GNU General Public License for more details.                                #
   16 #                                                                             #
   17 # You should have received a copy of the GNU General Public License           #
   18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
   19 #                                                                             #
   20 ###############################################################################
   21 
   22 # Package docstring.
   23 """The relax software verification tests.
   24 
   25 For a description of verification tests, please see U{Wikipedia<https://en.wikipedia.org/wiki/Verification_and_validation_%28software%29>}.
   26 """
   27 
   28 # Python module imports.
   29 from re import search
   30 from unittest import TestSuite
   31 
   32 # relax module imports.
   33 from lib.errors import RelaxError
   34 
   35 # relax software verification test module imports.
   36 from test_suite.formatting import format_test_name
   37 from test_suite.relax_test_loader import RelaxTestLoader as TestLoader
   38 from test_suite.verification_tests.library import Library
   39 from test_suite.verification_tests.status_object import Status_object
   40 
   41 
   42 __all__ = [
   43     'library',
   44     'status_object'
   45 ]
   46 
   47 
   48 class Verification_test_runner:
   49     """Class for executing all of the software verification tests."""
   50 
   51     def run(self, tests=None, runner=None, list_tests=False):
   52         """Run the software verification tests.
   53 
   54         @keyword tests:         The list of system tests to preform.
   55         @type tests:            list of str
   56         @keyword runner:        A test runner such as TextTestRunner.  For an example of how to write a test runner see the python documentation for TextTestRunner in the python source.
   57         @type runner:           Test runner instance (TextTestRunner, BaseGUITestRunner subclass, etc.)
   58         @keyword list_tests:    A flag which if True will cause the tests to be listed rather than executed.
   59         @type list_tests:       bool
   60         """
   61 
   62         # Create an array of test suites (add your new TestCase classes here).
   63         suite_array = []
   64 
   65         # Specific tests.
   66         for test in tests:
   67             # The entire test class.
   68             if not search('\.', test):
   69                 # Check that the class exists.
   70                 if test not in globals():
   71                     raise RelaxError("The system test class '%s' does not exist." % test)
   72 
   73                 # The uninstantiated class object.
   74                 obj = globals()[test]
   75 
   76                 # Add the tests.
   77                 suite_array.append(TestLoader().loadTestsFromTestCase(obj))
   78 
   79             # Single system test.
   80             else:
   81                 # Split.
   82                 row = test.split('.')
   83 
   84                 # Check.
   85                 if len(row) != 2:
   86                     raise RelaxError("The test '%s' is not in the correct format.  It should consist of the test case class, a dot, and the specific test." % test)
   87 
   88                 # Unpack.
   89                 class_name, test_name = row
   90 
   91                 # Get the class object.
   92                 obj = globals()[class_name]
   93 
   94                 # Add the test.
   95                 suite_array.append(TestLoader().loadTestsFromNames([test_name], obj))
   96 
   97         # All tests.
   98         if not tests:
   99             suite_array.append(TestLoader().loadTestsFromTestCase(Library))
  100             suite_array.append(TestLoader().loadTestsFromTestCase(Status_object))
  101 
  102         # Group all tests together.
  103         full_suite = TestSuite(suite_array)
  104 
  105         # Only list the tests.
  106         if list_tests:
  107             for suite in full_suite._tests:
  108                 for test in suite:
  109                     print(format_test_name(test.id()))
  110             return True
  111 
  112         # Run the test suite.
  113         results = runner.run(full_suite)
  114 
  115         # Return the status of the tests.
  116         return results.wasSuccessful()