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

Source Code for Module test_suite.unit_tests._specific_fns.test_api

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2011 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from inspect import getargspec 
 25  from re import search 
 26  import types 
 27  from unittest import TestCase 
 28   
 29  # relax module imports. 
 30  from specific_fns.api_base import API_base 
 31  from specific_fns.consistency_tests import Consistency_tests 
 32  from specific_fns.frame_order import Frame_order 
 33  from specific_fns.hybrid import Hybrid 
 34  from specific_fns.jw_mapping import Jw_mapping 
 35  from specific_fns.model_free import Model_free 
 36  from specific_fns.n_state_model import N_state_model 
 37  from specific_fns.noe import Noe 
 38  from specific_fns.relax_fit import Relax_fit 
 39   
 40   
41 -class Test_api(TestCase):
42 """Unit tests for the specific_fns 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