Package test_suite :: Module test_suite
[hide private]
[frames] | no frames]

Source Code for Module test_suite.test_suite

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006 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  # Import statements. 
 24  import traceback 
 25  import sys 
 26   
 27   
 28  # Import the tests. 
 29  from angles import Angles 
 30  from consistency_tests import Consistent 
 31  from diffusion_tensor import Diffusion_tensor 
 32  from generic import Generic 
 33  from jw_mapping import Jw 
 34  from model_free import Mf 
 35  from model_selection import Modsel 
 36  from relax_fit import Relax_fit 
 37  from run_create import Run_create 
 38  from sequence import Sequence 
 39   
 40   
41 -class Test_suite:
42 - def __init__(self, relax):
43 """The relax test suite. 44 45 This class runs a number of tests to determine if any changes to relax have caused 46 breakages. 47 """ 48 49 self.relax = relax 50 51 52 # Introduction. 53 ############### 54 55 # Heading. 56 self.heading("The relax test suite") 57 58 59 # Run tests. 60 ############ 61 62 # Heading. 63 self.heading("The run tests") 64 65 # Initialise the array containing each test element. 66 self.run_test_array = [] 67 68 # User function run.create() test. 69 self.run_test_array.append(Run_create(self.relax)) 70 71 # Execute the tests. 72 self.exec_tests(self.run_test_array) 73 74 75 # Sequence tests. 76 ################# 77 78 # Heading. 79 self.heading("The sequence tests") 80 81 # Initialise the array containing each test element. 82 self.seq_test_array = [] 83 84 # User function sequence.read() test. 85 self.seq_test_array.append(Sequence(self.relax, 'read')) 86 87 # Loading the sequence from a PDB file. 88 self.seq_test_array.append(Sequence(self.relax, 'pdb')) 89 90 # Execute the tests. 91 self.exec_tests(self.seq_test_array) 92 93 94 # Diffusion tensor tests. 95 ######################### 96 97 # Heading. 98 self.heading("The diffusion tensor tests") 99 100 # Initialise the array containing each test element. 101 self.diff_tensor_test_array = [] 102 103 # User function tests. 104 self.diff_tensor_test_array.append(Diffusion_tensor(self.relax, 'init')) 105 self.diff_tensor_test_array.append(Diffusion_tensor(self.relax, 'delete')) 106 self.diff_tensor_test_array.append(Diffusion_tensor(self.relax, 'display')) 107 self.diff_tensor_test_array.append(Diffusion_tensor(self.relax, 'copy')) 108 109 # Execute the tests. 110 self.exec_tests(self.diff_tensor_test_array) 111 112 113 # Angle calculation tests. 114 ########################## 115 116 # Heading. 117 self.heading("Angle calculation tests") 118 119 # Initialise the array containing each test element. 120 self.angles_test_array = [] 121 122 # User function tests. 123 self.angles_test_array.append(Angles(self.relax)) 124 125 # Execute the tests. 126 self.exec_tests(self.angles_test_array) 127 128 129 # Relaxation curve-fitting tests. 130 ################################# 131 132 # Heading. 133 self.heading("The relaxation curve-fitting tests") 134 135 # Initialise the array containing each test element. 136 self.relax_fit_test_array = [] 137 138 # Loading Sparky peak heights. 139 self.relax_fit_test_array.append(Relax_fit(self.relax, 'read_sparky')) 140 141 # Execute the tests. 142 self.exec_tests(self.relax_fit_test_array) 143 144 145 # Model-free tests. 146 ################### 147 148 # Heading. 149 self.heading("The model-free tests") 150 151 # Initialise the array containing each test element. 152 self.mf_test_array = [] 153 154 # User function results.read() test. 155 self.mf_test_array.append(Mf(self.relax, 'read relaxation data')) 156 self.mf_test_array.append(Mf(self.relax, 'set csa')) 157 self.mf_test_array.append(Mf(self.relax, 'set bond length')) 158 self.mf_test_array.append(Mf(self.relax, 'set csa and bond length')) 159 self.mf_test_array.append(Mf(self.relax, 'select m4')) 160 self.mf_test_array.append(Mf(self.relax, 'create m4')) 161 self.mf_test_array.append(Mf(self.relax, 'read results')) 162 self.mf_test_array.append(Mf(self.relax, 'opendx {S2, te, Rex} map')) 163 self.mf_test_array.append(Mf(self.relax, 'opendx {theta, phi, Da} map')) 164 self.mf_test_array.append(Mf(self.relax, 'opendx {local_tm, S2, te} map')) 165 self.mf_test_array.append(Mf(self.relax, 'Constrained grid search {S2=0.970, te=2048, Rex=0.149}')) 166 self.mf_test_array.append(Mf(self.relax, 'Constrained SD, backtracking opt {S2=0.970, te=2048, Rex=0.149}')) 167 self.mf_test_array.append(Mf(self.relax, 'Constrained SD, MT opt {S2=0.970, te=2048, Rex=0.149}')) 168 self.mf_test_array.append(Mf(self.relax, 'Constrained CD, backtracking opt {S2=0.970, te=2048, Rex=0.149}')) 169 self.mf_test_array.append(Mf(self.relax, 'Constrained CD, MT opt {S2=0.970, te=2048, Rex=0.149}')) 170 self.mf_test_array.append(Mf(self.relax, 'Constrained BFGS, backtracking opt {S2=0.970, te=2048, Rex=0.149}')) 171 self.mf_test_array.append(Mf(self.relax, 'Constrained BFGS, backtracking opt {S2=0.970, te=2048, Rex=0.149}')) 172 self.mf_test_array.append(Mf(self.relax, 'Constrained Newton, GMW, backtracking opt {S2=0.970, te=2048, Rex=0.149}')) 173 self.mf_test_array.append(Mf(self.relax, 'Constrained Newton, GMW, MT opt {S2=0.970, te=2048, Rex=0.149}')) 174 175 # Execute the tests. 176 self.exec_tests(self.mf_test_array) 177 178 179 # Reduced spectral density mapping tests. 180 ######################################### 181 182 # Heading. 183 self.heading("The reduced spectral density mapping tests") 184 185 # Initialise the array containing each test element. 186 self.jw_test_array = [] 187 188 # User function value.set() test. 189 self.jw_test_array.append(Jw(self.relax, 'set')) 190 self.jw_test_array.append(Jw(self.relax, 'calc')) 191 192 # Execute the tests. 193 self.exec_tests(self.jw_test_array) 194 195 196 # Consistency tests tests. 197 ########################## 198 199 # Heading 200 self.heading("The consistency tests tests") 201 202 # Initialise the array containing each test element. 203 self.consistent_test_array = [] 204 205 # User function value.set() test. 206 self.consistent_test_array.append(Consistent(self.relax, 'set')) 207 self.consistent_test_array.append(Consistent(self.relax, 'calc')) 208 209 # Execute the tests. 210 self.exec_tests(self.consistent_test_array) 211 212 213 # Model selection tests. 214 ######################## 215 216 # Heading. 217 self.heading("The model selection tests") 218 219 # Initialise the array containing each test element. 220 self.modsel_test_array = [] 221 222 # The tests. 223 self.modsel_test_array.append(Modsel(self.relax, 'diff tensor')) 224 225 # Execute the tests. 226 self.exec_tests(self.modsel_test_array) 227 228 229 # Generic tests. 230 ################ 231 232 # Heading. 233 self.heading("The generic tests") 234 235 # Initialise the array containing each test element. 236 self.generic_test_array = [] 237 238 # The tests. 239 self.generic_test_array.append(Generic(self.relax, 'value_diff')) 240 241 # Execute the tests. 242 self.exec_tests(self.generic_test_array) 243 244 245 # Summary. 246 ########## 247 248 self.summary()
249 250 251
252 - def heading(self, text):
253 """Function for printing the headings.""" 254 255 # Spacing. 256 sys.stdout.write("\n\n\n\n") 257 258 # Top bar. 259 for i in xrange(len(text) + 4): 260 sys.stdout.write("#") 261 sys.stdout.write("\n") 262 263 # Text. 264 sys.stdout.write("# " + text + " #\n") 265 266 # Bottom bar. 267 for i in xrange(len(text) + 4): 268 sys.stdout.write("#") 269 sys.stdout.write("\n\n\n")
270 271
272 - def exec_tests(self, test_array):
273 """Function for running the tests.""" 274 275 # Loop over the tests. 276 for i in xrange(len(test_array)): 277 # Print out. 278 string = "# Executing the test of " + test_array[i].name + '.' 279 sys.stdout.write(string + '\n') 280 for j in range(len(string)): 281 sys.stdout.write('#') 282 sys.stdout.write("\n\n") 283 284 # Reinitialise all data. 285 self.relax.interpreter._Init_data.init() 286 287 # The run name. 288 self.run = 'test' 289 290 # Flag indicating whether the test passed or failed. 291 test_array[i].passed = 0 292 293 # Execute the test. 294 try: 295 test_array[i].passed = test_array[i].test(self.run) 296 297 # The test failed. 298 except: 299 traceback.print_exc() 300 301 # Print out. 302 sys.stdout.write("\n\n\n\n\n\n\n") 303 304 # Debugging. 305 if not test_array[i].passed and Debug: 306 sys.exit()
307 308
309 - def summary(self):
310 """Function for printing out a summary of all tests.""" 311 312 # Heading. 313 sys.stdout.write("\n\n\n") 314 self.heading("Results of the test suite") 315 316 # Synopsis. 317 global_pass = 1 318 319 320 # Run tests. 321 ############ 322 323 # Heading. 324 sys.stdout.write("\nThe run tests:\n") 325 326 # Loop over the tests. 327 for test in self.run_test_array: 328 # Synopsis. 329 global_pass = global_pass and test.passed 330 331 # Print the summary line. 332 self.summary_line(test) 333 334 335 # Sequence tests. 336 ################# 337 338 # Heading. 339 sys.stdout.write("\nThe sequence tests:\n") 340 341 # Loop over the tests. 342 for test in self.seq_test_array: 343 # Synopsis. 344 global_pass = global_pass and test.passed 345 346 # Print the summary line. 347 self.summary_line(test) 348 349 350 # Diffusion tensor tests. 351 ######################### 352 353 # Heading. 354 sys.stdout.write("\nThe diffusion tensor tests:\n") 355 356 # Loop over the tests. 357 for test in self.diff_tensor_test_array: 358 # Synopsis. 359 global_pass = global_pass and test.passed 360 361 # Print the summary line. 362 self.summary_line(test) 363 364 365 # Angle calculation tests. 366 ########################## 367 368 # Heading. 369 sys.stdout.write("\nAngle calculation tests:\n") 370 371 # Loop over the tests. 372 for test in self.angles_test_array: 373 # Synopsis. 374 global_pass = global_pass and test.passed 375 376 # Print the summary line. 377 self.summary_line(test) 378 379 380 # Relaxation curve-fitting tests. 381 ################################# 382 383 # Heading. 384 sys.stdout.write("\nThe relaxation curve-fitting tests:\n") 385 386 # Loop over the tests. 387 for test in self.relax_fit_test_array: 388 # Synopsis. 389 global_pass = global_pass and test.passed 390 391 # Print the summary line. 392 self.summary_line(test) 393 394 395 # Model-free tests. 396 ################### 397 398 # Heading. 399 sys.stdout.write("\nThe model-free tests:\n") 400 401 # Loop over the tests. 402 for test in self.mf_test_array: 403 # Synopsis. 404 global_pass = global_pass and test.passed 405 406 # Print the summary line. 407 self.summary_line(test) 408 409 410 # Reduced spectral density Mapping tests. 411 ######################################### 412 413 # Heading. 414 sys.stdout.write("\nThe reduced spectral density tests:\n") 415 416 # Loop over the tests. 417 for test in self.jw_test_array: 418 # Synopsis. 419 global_pass = global_pass and test.passed 420 421 # Print the summary line. 422 self.summary_line(test) 423 424 425 # Consistentcy tests test. 426 ########################## 427 428 # Heading. 429 sys.stdout.write("\nThe consistency tests tests:\n") 430 431 # Loop over the tests. 432 for test in self.consistent_test_array: 433 # Synopsis. 434 global_pass = global_pass and test.passed 435 436 # Print the summary line. 437 self.summary_line(test) 438 439 440 # Model selection tests. 441 ######################## 442 443 # Heading. 444 sys.stdout.write("\nThe model selection tests:\n") 445 446 # Loop over the tests. 447 for test in self.modsel_test_array: 448 # Synopsis. 449 global_pass = global_pass and test.passed 450 451 # Print the summary line. 452 self.summary_line(test) 453 454 455 # Generic tests. 456 ################ 457 458 # Heading. 459 sys.stdout.write("\nThe generic tests:\n") 460 461 # Loop over the tests. 462 for test in self.generic_test_array: 463 # Synopsis. 464 global_pass = global_pass and test.passed 465 466 # Print the summary line. 467 self.summary_line(test) 468 469 470 # Synposis. 471 ########### 472 473 # Global pass print out. 474 sys.stdout.write("\n\n\nSynopsis ") 475 476 # Dots. 477 for j in xrange(88 - len("Synopsis")): 478 sys.stdout.write(".") 479 480 # Global pass. 481 if global_pass: 482 sys.stdout.write(" %-10s\n" % "[ OK ]") 483 484 # Global fail. 485 else: 486 sys.stdout.write(" %-10s\n" % "[ Failed ]") 487 sys.stdout.write("\n\n")
488 489
490 - def summary_line(self, test):
491 """Function for printing the summary lines.""" 492 493 # Name. 494 sys.stdout.write(" " + test.name + " ") 495 496 # Dots. 497 for j in xrange(84 - len(test.name)): 498 sys.stdout.write(".") 499 500 # Passed. 501 if test.passed: 502 sys.stdout.write(" %-10s\n" % "[ OK ]") 503 504 # Failed. 505 else: 506 sys.stdout.write(" %-10s\n" % "[ Failed ]") 507 self.global_pass = 0
508