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

Source Code for Module test_suite.system_tests.grace

  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 os import sep 
 25  from re import search 
 26  from string import split 
 27  from tempfile import mktemp 
 28   
 29  # relax module imports. 
 30  from base_classes import SystemTestCase 
 31  from status import Status; status = Status() 
 32   
 33   
34 -class Grace(SystemTestCase):
35 """Class for testing the creation of grace plots.""" 36
37 - def setUp(self):
38 """Common set up for these system tests.""" 39 40 # Create a temporary grace file name. 41 self.tmpfile = mktemp()
42 43
44 - def test_cam_kkalpha_plot1(self):
45 """Test the plotting of the 15N data from the CaM-KKalpha save state.""" 46 47 # Load the state. 48 self.interpreter.state.load('state_cam_kkalpha', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states') 49 50 # Create the plot. 51 self.interpreter.grace.write('spin', 's2', file=self.tmpfile, spin_id='@N', dir=None) 52 53 # Read the file data. 54 file = open(self.tmpfile) 55 lines = file.readlines() 56 file.close() 57 58 # Init the data. 59 spin = [] 60 value = [] 61 error = [] 62 63 # Check the data. 64 in_data = False 65 for i in range(len(lines)): 66 # Start of the first plot. 67 if search('G0.S0', lines[i]): 68 in_data=True 69 continue 70 71 # No in the data range. 72 if not in_data: 73 continue 74 75 # Skip the first @ line. 76 if search('^@', lines[i]): 77 continue 78 79 # The end. 80 if search('^&', lines[i]): 81 break 82 83 # Split up the data. 84 row = split(lines[i]) 85 86 # Store the data. 87 spin.append(float(row[0])) 88 value.append(float(row[1])) 89 error.append(float(row[2])) 90 91 # The real data. 92 real_data = [ 93 [2, 0.693, 0.005], 94 [3, 0.400, 0.000], 95 [4, 0.882, 0.008], 96 [5, 0.901, 0.001], 97 [6, 0.953, 0.014], 98 [7, 0.905, 0.000], 99 [8, 0.939, 0.007], 100 [9, 0.948, 0.003], 101 [10, 0.957, 0.004] 102 ] 103 104 # Check the data length. 105 self.assertEqual(len(real_data), len(spin)) 106 107 # Check the data. 108 for i in range(len(real_data)): 109 self.assertEqual(float(real_data[i][0]), spin[i]) 110 self.assertAlmostEqual(real_data[i][1], value[i]) 111 self.assertAlmostEqual(real_data[i][2], error[i])
112