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