Package test_suite :: Package unit_tests :: Package _specific_analyses :: Module test_api
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._specific_analyses.test_api

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2014 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  # Python module imports. 
 23  from inspect import getargspec 
 24  from re import search 
 25  import types 
 26  from unittest import TestCase 
 27   
 28  # relax module imports. 
 29  from specific_analyses.api_base import API_base 
 30  from specific_analyses.consistency_tests.api import Consistency_tests 
 31  from specific_analyses.frame_order.api import Frame_order 
 32  from specific_analyses.hybrid import Hybrid 
 33  from specific_analyses.jw_mapping.api import Jw_mapping 
 34  from specific_analyses.model_free.api import Model_free 
 35  from specific_analyses.n_state_model.api import N_state_model 
 36  from specific_analyses.noe.api import Noe 
 37  from specific_analyses.relax_disp.api import Relax_disp 
 38  from specific_analyses.relax_fit.api import Relax_fit 
 39   
 40   
41 -class Test_api(TestCase):
42 """Unit tests for the specific analyses API.""" 43
44 - def __format_method(self, name, args, varargs, varkw, defaults):
45 """Method for formatting the method.""" 46 47 # Method start. 48 text = name + '(' 49 50 # No keywords. 51 if defaults == None: 52 defaults = () 53 54 # Counts. 55 num_args = len(args) - len(defaults) 56 num_kw = len(defaults) 57 58 # Args. 59 for i in range(num_args): 60 # Separator. 61 if i != 0: 62 text = text + ', ' 63 64 # The arg. 65 text = text + args[i] 66 67 # Keyword args. 68 for j in range(num_kw): 69 # Separator. 70 if num_args or j != 0: 71 text = text + ', ' 72 73 # The keyword. 74 text = text + args[num_args+j] + '=' + repr(defaults[j]) 75 76 # End. 77 text = text + ')' 78 return text
79 80
81 - def __check_method_args(self, analysis_obj):
82 """Check the args of all API methods. 83 84 @param analysis_obj: The specific analysis object. 85 @type analysis_obj: instance 86 """ 87 88 # The base object. 89 base = API_base() 90 91 # Loop over the objects of the specific analysis. 92 for name in dir(analysis_obj): 93 # Skip anything starting with '_'. 94 if search('^_', name): 95 continue 96 97 # Skip the singleton instance. 98 if name == 'instance': 99 continue 100 101 # Get the object in the two classes. 102 obj_base = getattr(base, name) 103 obj = getattr(analysis_obj, name) 104 105 # Skip non-method objects. 106 if not isinstance(obj_base, types.MethodType): 107 continue 108 109 # Get the args and their default values. 110 args_base, varargs_base, varkw_base, defaults_base = getargspec(obj_base) 111 args, varargs, varkw, defaults = getargspec(obj) 112 113 # Check the args. 114 if args_base != args or varargs_base != varargs or varkw_base != varkw: 115 # Get string representations of the methods. 116 doc_base = self.__format_method(name, args_base, varargs_base, varkw_base, defaults_base) 117 doc = self.__format_method(name, args, varargs, varkw, defaults) 118 print(doc_base) 119 120 # Fail. 121 self.fail('The args of the method:\n\t' + doc + '\ndo not match those of the API method:\n\t' + doc_base)
122 123
124 - def __check_objects(self, analysis_obj):
125 """Check the args of all API methods. 126 127 @param analysis_obj: The specific analysis object. 128 @type analysis_obj: instance 129 """ 130 131 # The base object. 132 base = API_base() 133 134 # The objects in the base class. 135 base_names = dir(base) 136 137 # Loop over the objects of the specific analysis. 138 for name in dir(analysis_obj): 139 # Skip anything starting with '_'. 140 if search('^_', name): 141 continue 142 143 # Skip the singleton instance. 144 if name == 'instance': 145 continue 146 147 # Get the object in the derived class. 148 obj = getattr(analysis_obj, name) 149 150 # Not present. 151 if name not in base_names: 152 self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + ' cannot be found in the API base class.')
153 154
156 """The consistency tests object public method args check.""" 157 158 # Check. 159 self.__check_method_args(Consistency_tests())
160 161
163 """The consistency tests object public objects check.""" 164 165 # Check. 166 self.__check_objects(Consistency_tests())
167 168
170 """The frame order object public method args check.""" 171 172 # Check. 173 self.__check_method_args(Frame_order())
174 175
176 - def test_frame_order_objects(self):
177 """The frame order object public objects check.""" 178 179 # Check. 180 self.__check_objects(Frame_order())
181 182
183 - def test_hybrid_method_args(self):
184 """The hybrid object public method args check.""" 185 186 # Check. 187 self.__check_method_args(Hybrid())
188 189
190 - def test_hybrid_objects(self):
191 """The hybrid object public objects check.""" 192 193 # Check. 194 self.__check_objects(Hybrid())
195 196
198 """The reduced spectral density mapping object public method args check.""" 199 200 # Check. 201 self.__check_method_args(Jw_mapping())
202 203
204 - def test_jw_mapping_objects(self):
205 """The reduced spectral density mapping object public objects check.""" 206 207 # Check. 208 self.__check_objects(Jw_mapping())
209 210
212 """The model-free object public method args check.""" 213 214 # Check. 215 self.__check_method_args(Model_free())
216 217
218 - def test_model_free_objects(self):
219 """The model-free object public objects check.""" 220 221 # Check. 222 self.__check_objects(Model_free())
223 224
226 """The N-state model object public method args check.""" 227 228 # Check. 229 self.__check_method_args(N_state_model())
230 231
233 """The N-state model object public objects check.""" 234 235 # Check. 236 self.__check_objects(N_state_model())
237 238
239 - def test_noe_method_args(self):
240 """The NOE object public method args check.""" 241 242 # Check. 243 self.__check_method_args(Noe())
244 245
246 - def test_noe_objects(self):
247 """The NOE object public objects check.""" 248 249 # Check. 250 self.__check_objects(Noe())
251 252
254 """The relaxation curve fitting object public method args check.""" 255 256 # Check. 257 self.__check_method_args(Relax_fit())
258 259
260 - def test_relax_fit_objects(self):
261 """The relaxation curve fitting object public objects check.""" 262 263 # Check. 264 self.__check_objects(Relax_fit())
265 266
268 """The relaxation dispersion curve fitting object public method args check.""" 269 270 # Check. 271 self.__check_method_args(Relax_disp())
272 273
274 - def test_relax_disp_objects(self):
275 """The relaxation dispersion curve fitting object public objects check.""" 276 277 # Check. 278 self.__check_objects(Relax_disp())
279