"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/test_suite/system_tests/__init__.py" (6 Dec 2019, 10392 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-2010,2012,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 system/functional tests."""
   24 
   25 # Python module imports.
   26 from re import search
   27 from unittest import TestSuite
   28 
   29 # relax module imports.
   30 from lib.errors import RelaxError
   31 
   32 # relax system/functional test module imports.
   33 from test_suite.formatting import format_test_name
   34 from test_suite.relax_test_loader import RelaxTestLoader as TestLoader
   35 from test_suite.system_tests.align_tensor import Align_tensor
   36 from test_suite.system_tests.angles import Angles
   37 from test_suite.system_tests.bmrb import Bmrb
   38 from test_suite.system_tests.bruker import Bruker
   39 from test_suite.system_tests.chemical_shift import Chemical_shift
   40 from test_suite.system_tests.consistency_tests import Ct
   41 from test_suite.system_tests.dasha import Dasha
   42 from test_suite.system_tests.diffusion_tensor import Diffusion_tensor
   43 from test_suite.system_tests.frame_order import Frame_order
   44 from test_suite.system_tests.generic import Generic
   45 from test_suite.system_tests.grace import Grace
   46 from test_suite.system_tests.interatomic import Interatomic
   47 from test_suite.system_tests.jw_mapping import Jw
   48 from test_suite.system_tests.load_spins import Load_spins
   49 from test_suite.system_tests.model_elimination import Modelim
   50 from test_suite.system_tests.model_free import Mf
   51 from test_suite.system_tests.model_selection import Modsel
   52 from test_suite.system_tests.mol_res_spin import Mol_res_spin
   53 from test_suite.system_tests.n_state_model import N_state_model
   54 from test_suite.system_tests.noe import Noe
   55 from test_suite.system_tests.noe_restraints import Noe_restraints
   56 from test_suite.system_tests.palmer import Palmer
   57 from test_suite.system_tests.pcs import Pcs
   58 from test_suite.system_tests.peak_lists import Peak_lists
   59 from test_suite.system_tests.pipes import Pipes
   60 from test_suite.system_tests.rdc import Rdc
   61 from test_suite.system_tests.relax_data import Relax_data
   62 from test_suite.system_tests.relax_disp import Relax_disp
   63 from test_suite.system_tests.relax_fit import Relax_fit
   64 from test_suite.system_tests.results import Results
   65 from test_suite.system_tests.selection import Selection
   66 from test_suite.system_tests.sequence import Sequence
   67 from test_suite.system_tests.spectrum import Spectrum
   68 from test_suite.system_tests.state import State
   69 from test_suite.system_tests.structure import Structure
   70 from test_suite.system_tests.unit_vectors import Unit_vectors
   71 from test_suite.system_tests.value import Value
   72 
   73 
   74 __all__ = ['align_tensor',
   75            'angles',
   76            'bmrb',
   77            'bruker',
   78            'chemical_shift'
   79            'consistency_tests',
   80            'dasha'
   81            'diffusion_tensor',
   82            'frame_order',
   83            'generic',
   84            'grace',
   85            'interatomic',
   86            'jw_mapping',
   87            'load_spins',
   88            'model_elimination',
   89            'model_free',
   90            'model_selection',
   91            'n_state_model',
   92            'noe',
   93            'noe_restraints',
   94            'palmer',
   95            'pcs'
   96            'peak_lists'
   97            'pipes',
   98            'rdc',
   99            'relax_data',
  100            'relax_disp',
  101            'relax_fit',
  102            'results',
  103            'scripts',
  104            'selection',
  105            'sequence',
  106            'spectrum',
  107            'state',
  108            'structure',
  109            'unit_vectors',
  110            'value']
  111 
  112 
  113 class System_test_runner:
  114     """Class for executing all of the system/functional tests."""
  115 
  116     def run(self, tests=None, runner=None, list_tests=False):
  117         """Run the system/functional tests.
  118 
  119         The system 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.
  120 
  121 
  122         @keyword tests:         The list of system tests to preform.
  123         @type tests:            list of str
  124         @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.
  125         @type runner:           Test runner instance (TextTestRunner, BaseGUITestRunner subclass, etc.)
  126         @keyword list_tests:    A flag which if True will cause the tests to be listed rather than executed.
  127         @type list_tests:       bool
  128         """
  129 
  130         # Create an array of test suites (add your new TestCase classes here).
  131         suite_array = []
  132 
  133         # Specific tests.
  134         for test in tests:
  135             # The entire test class.
  136             if not search('\.', test):
  137                 # Check that the class exists.
  138                 if test not in globals():
  139                     raise RelaxError("The system test class '%s' does not exist." % test)
  140 
  141                 # The uninstantiated class object.
  142                 obj = globals()[test]
  143 
  144                 # Add the tests.
  145                 suite_array.append(TestLoader().loadTestsFromTestCase(obj))
  146 
  147             # Single system test.
  148             else:
  149                 # Split.
  150                 row = test.split('.')
  151 
  152                 # Check.
  153                 if len(row) != 2:
  154                     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)
  155 
  156                 # Unpack.
  157                 class_name, test_name = row
  158 
  159                 # Get the class object.
  160                 obj = globals()[class_name]
  161 
  162                 # Add the test.
  163                 suite_array.append(TestLoader().loadTestsFromNames([test_name], obj))
  164 
  165         # All tests.
  166         if not tests:
  167             suite_array.append(TestLoader().loadTestsFromTestCase(Align_tensor))
  168             suite_array.append(TestLoader().loadTestsFromTestCase(Bmrb))
  169             suite_array.append(TestLoader().loadTestsFromTestCase(Bruker))
  170             suite_array.append(TestLoader().loadTestsFromTestCase(Angles))
  171             suite_array.append(TestLoader().loadTestsFromTestCase(Chemical_shift))
  172             suite_array.append(TestLoader().loadTestsFromTestCase(Ct))
  173             suite_array.append(TestLoader().loadTestsFromTestCase(Dasha))
  174             suite_array.append(TestLoader().loadTestsFromTestCase(Diffusion_tensor))
  175             suite_array.append(TestLoader().loadTestsFromTestCase(Frame_order))
  176             suite_array.append(TestLoader().loadTestsFromTestCase(Generic))
  177             suite_array.append(TestLoader().loadTestsFromTestCase(Grace))
  178             suite_array.append(TestLoader().loadTestsFromTestCase(Interatomic))
  179             suite_array.append(TestLoader().loadTestsFromTestCase(Jw))
  180             suite_array.append(TestLoader().loadTestsFromTestCase(Load_spins))
  181             suite_array.append(TestLoader().loadTestsFromTestCase(Modelim))
  182             suite_array.append(TestLoader().loadTestsFromTestCase(Mf))
  183             suite_array.append(TestLoader().loadTestsFromTestCase(Modsel))
  184             suite_array.append(TestLoader().loadTestsFromTestCase(Mol_res_spin))
  185             suite_array.append(TestLoader().loadTestsFromTestCase(N_state_model))
  186             suite_array.append(TestLoader().loadTestsFromTestCase(Noe))
  187             suite_array.append(TestLoader().loadTestsFromTestCase(Noe_restraints))
  188             suite_array.append(TestLoader().loadTestsFromTestCase(Palmer))
  189             suite_array.append(TestLoader().loadTestsFromTestCase(Pcs))
  190             suite_array.append(TestLoader().loadTestsFromTestCase(Peak_lists))
  191             suite_array.append(TestLoader().loadTestsFromTestCase(Pipes))
  192             suite_array.append(TestLoader().loadTestsFromTestCase(Rdc))
  193             suite_array.append(TestLoader().loadTestsFromTestCase(Relax_data))
  194             suite_array.append(TestLoader().loadTestsFromTestCase(Relax_disp))
  195             suite_array.append(TestLoader().loadTestsFromTestCase(Relax_fit))
  196             suite_array.append(TestLoader().loadTestsFromTestCase(Results))
  197             suite_array.append(TestLoader().loadTestsFromTestCase(Selection))
  198             suite_array.append(TestLoader().loadTestsFromTestCase(Sequence))
  199             suite_array.append(TestLoader().loadTestsFromTestCase(Spectrum))
  200             suite_array.append(TestLoader().loadTestsFromTestCase(State))
  201             suite_array.append(TestLoader().loadTestsFromTestCase(Structure))
  202             suite_array.append(TestLoader().loadTestsFromTestCase(Unit_vectors))
  203             suite_array.append(TestLoader().loadTestsFromTestCase(Value))
  204 
  205         # Group all tests together.
  206         full_suite = TestSuite(suite_array)
  207 
  208         # Only list the tests.
  209         if list_tests:
  210             for suite in full_suite._tests:
  211                 for test in suite:
  212                     print(format_test_name(test.id()))
  213             return True
  214 
  215         # Run the test suite.
  216         results = runner.run(full_suite)
  217 
  218         # Return the status of the tests.
  219         return results.wasSuccessful()