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-2013 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 import Consistency_tests 
 31  from specific_analyses.frame_order import Frame_order 
 32  from specific_analyses.hybrid import Hybrid 
 33  from specific_analyses.jw_mapping import Jw_mapping 
 34  from specific_analyses.model_free import Model_free 
 35  from specific_analyses.n_state_model import N_state_model 
 36  from specific_analyses.noe import Noe 
 37  from specific_analyses.relax_disp.api import Relax_disp 
 38  from specific_analyses.relax_fit 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 # Get the object in the two classes. 98 obj_base = getattr(base, name) 99 obj = getattr(analysis_obj, name) 100 101 # Skip non-method objects. 102 if not isinstance(obj_base, types.MethodType): 103 continue 104 105 # Get the args and their default values. 106 args_base, varargs_base, varkw_base, defaults_base = getargspec(obj_base) 107 args, varargs, varkw, defaults = getargspec(obj) 108 109 # Check the args. 110 if args_base != args or varargs_base != varargs or varkw_base != varkw: 111 # Get string representations of the methods. 112 doc_base = self.__format_method(name, args_base, varargs_base, varkw_base, defaults_base) 113 doc = self.__format_method(name, args, varargs, varkw, defaults) 114 print(doc_base) 115 116 # Fail. 117 self.fail('The args of the method:\n\t' + doc + '\ndo not match those of the API method:\n\t' + doc_base)
118 119
120 - def __check_objects(self, analysis_obj):
121 """Check the args of all API methods. 122 123 @param analysis_obj: The specific analysis object. 124 @type analysis_obj: instance 125 """ 126 127 # The base object. 128 base = API_base() 129 130 # The objects in the base class. 131 base_names = dir(base) 132 133 # Loop over the objects of the specific analysis. 134 for name in dir(analysis_obj): 135 # Skip anything starting with '_'. 136 if search('^_', name): 137 continue 138 139 # Get the object in the derived class. 140 obj = getattr(analysis_obj, name) 141 142 # Not present. 143 if name not in base_names: 144 self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + ' cannot be found in the API base class.')
145 146
148 """The consistency tests object public method args check.""" 149 150 # Check. 151 self.__check_method_args(Consistency_tests())
152 153
155 """The consistency tests object public objects check.""" 156 157 # Check. 158 self.__check_objects(Consistency_tests())
159 160
162 """The frame order object public method args check.""" 163 164 # Check. 165 self.__check_method_args(Frame_order())
166 167
168 - def test_frame_order_objects(self):
169 """The frame order object public objects check.""" 170 171 # Check. 172 self.__check_objects(Frame_order())
173 174
175 - def test_hybrid_method_args(self):
176 """The hybrid object public method args check.""" 177 178 # Check. 179 self.__check_method_args(Hybrid())
180 181
182 - def test_hybrid_objects(self):
183 """The hybrid object public objects check.""" 184 185 # Check. 186 self.__check_objects(Hybrid())
187 188
190 """The reduced spectral density mapping object public method args check.""" 191 192 # Check. 193 self.__check_method_args(Jw_mapping())
194 195
196 - def test_jw_mapping_objects(self):
197 """The reduced spectral density mapping object public objects check.""" 198 199 # Check. 200 self.__check_objects(Jw_mapping())
201 202
204 """The model-free object public method args check.""" 205 206 # Check. 207 self.__check_method_args(Model_free())
208 209
210 - def test_model_free_objects(self):
211 """The model-free object public objects check.""" 212 213 # Check. 214 self.__check_objects(Model_free())
215 216
218 """The N-state model object public method args check.""" 219 220 # Check. 221 self.__check_method_args(N_state_model())
222 223
225 """The N-state model object public objects check.""" 226 227 # Check. 228 self.__check_objects(N_state_model())
229 230
231 - def test_noe_method_args(self):
232 """The NOE object public method args check.""" 233 234 # Check. 235 self.__check_method_args(Noe())
236 237
238 - def test_noe_objects(self):
239 """The NOE object public objects check.""" 240 241 # Check. 242 self.__check_objects(Noe())
243 244
246 """The relaxation curve fitting object public method args check.""" 247 248 # Check. 249 self.__check_method_args(Relax_fit())
250 251
252 - def test_relax_fit_objects(self):
253 """The relaxation curve fitting object public objects check.""" 254 255 # Check. 256 self.__check_objects(Relax_fit())
257 258
260 """The relaxation dispersion curve fitting object public method args check.""" 261 262 # Check. 263 self.__check_method_args(Relax_disp())
264 265
266 - def test_relax_disp_objects(self):
267 """The relaxation dispersion curve fitting object public objects check.""" 268 269 # Check. 270 self.__check_objects(Relax_disp())
271