Changeset daa56d0 in sasview for DataLoader/test
- Timestamp:
- Sep 3, 2008 11:47:12 AM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d831626
- Parents:
- e390933
- Location:
- DataLoader/test
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/test/error_conditions.py
rf9474b5 rdaa56d0 9 9 """ 10 10 self.s.load('blah.mat') on an unknown type 11 should raise a runtime exception11 should raise a ValueError exception (thrown by data_util.registry) 12 12 """ 13 self.assertRaises( RuntimeError, self.s.load, 'angles_flat.mat')13 self.assertRaises(ValueError, self.s.load, 'angles_flat.mat') 14 14 15 15 def test_corrupt(self): -
DataLoader/test/sequence_tests.py
rb99ac227 rdaa56d0 29 29 single_igor() 30 30 single_abs() 31 print "Test passed" -
DataLoader/test/testLoad.py
rb99ac227 rdaa56d0 16 16 import DataLoader 17 17 from DataLoader.loader import Loader 18 18 19 # Check whether we should test image loading on this system 20 HAS_IMAGE = False 21 try: 22 import Image 23 HAS_IMAGE = True 24 except: 25 print "IMAGE TESTS WILL NOT BE PERFORMED: MISSING PIL MODULE" 26 19 27 import os.path 20 28 … … 24 32 self.loader = Loader() 25 33 26 27 34 def test_singleton(self): 28 35 """ 29 36 Testing whether Loader is truly a singleton 30 37 """ 31 # Set a new data member32 self.loader._test_data_member = 1.4533 34 38 # Create a 'new' Loader 35 39 b = Loader() 36 37 # Test that the new loader has the new data member 38 self.assertEqual(b._test_data_member, self.loader._test_data_member) 40 self.assertEqual(self.loader._get_registry_creation_time(), 41 b._get_registry_creation_time()) 39 42 40 43 class testLoader(unittest.TestCase): … … 53 56 def testLoad0(self): 54 57 """test reading empty file""" 55 self.assert Equal(self.L.load('empty.txt'),None)58 self.assertRaises(RuntimeError, self.L.load, 'empty.txt') 56 59 57 60 def testLoad1(self): … … 87 90 self.assertEqual(output.dy[i],dy[i]) 88 91 92 def testLoad2_uppercase(self): 93 """Testing loading a txt file of 3 columns""" 94 output= self.L.load('test_3_columns.TXT') 95 x=[0,0.204082,0.408163,0.612245,0.816327,1.02041,1.22449] 96 y=[2.83954,3.44938,5.82026,5.27591,5.2781,5.22531,7.47487] 97 dx=[] 98 dy=[0.6,0.676531,0.753061,0.829592,0.906122,0.982653,1.05918] 99 self.assertEqual(len(output.x),len(x)) 100 self.assertEqual(len(output.y),len(y)) 101 self.assertEqual(len(output.dy),len(dy)) 102 for i in range(len(x)): 103 self.assertEqual(output.x[i],x[i]) 104 self.assertEqual(output.y[i],y[i]) 105 self.assertEqual(output.dy[i],dy[i]) 106 89 107 90 108 def testload3(self): … … 92 110 #tested good file.asc 93 111 output= self.L.load('MAR07232_rest.ASC') 112 self.assertEqual(output.xmin,-0.018558945804750416) 113 self.assertEqual(output.xmax, 0.016234058202440633,) 114 self.assertEqual(output.ymin,-0.01684257151702391) 115 self.assertEqual(output.ymax,0.017950440578015116) 116 117 #tested corrupted file.asc 118 try:self.L.load('AR07232_rest.ASC') 119 except ValueError,msg: 120 #logging.log(10,str(msg)) 121 logging.error(str(msg)) 122 123 def testload3_lowercase(self): 124 """ Testing loading Igor data""" 125 #tested good file.asc 126 output= self.L.load('MAR07232_rest.asc') 94 127 self.assertEqual(output.xmin,-0.018558945804750416) 95 128 self.assertEqual(output.xmax, 0.016234058202440633,) … … 118 151 def testload5(self): 119 152 """ Testing loading image file""" 120 output=self.L.load('angles_flat.png') 121 self.assertEqual(output.xbins ,200) 153 if HAS_IMAGE: 154 output=self.L.load('angles_flat.png') 155 self.assertEqual(output.xbins ,200) 122 156 123 157 def testload6(self): 124 158 """test file with unknown extension""" 125 try:self.L.load('hello.missing') 126 except RuntimeError,msg: 127 self.assertEqual( str(msg),"Unknown file type '.missing'") 128 else: raise ValueError,"No error raised for missing extension" 159 self.assertRaises(ValueError, self.L.load, 'hello.missing') 129 160 130 #self.L.lookup('hello.missing') 131 try: self.L.lookup('hello.missing') 132 except RuntimeError,msg: 133 self.assertEqual( str(msg),"Unknown file type '.missing'") 134 else: raise ValueError,"No error raised for missing extension" 161 # Lookup is not supported as a public method 162 #self.assertRaises(ValueError, self.L.lookup, 'hello.missing') 163 135 164 136 165 def testload7(self): 137 166 """ test file containing an image but as extension .txt""" 138 self.assert Equal(self.L.load('angles_flat.txt'),None)167 self.assertRaises(RuntimeError, self.L.load, 'angles_flat.txt') 139 168 140 169 if __name__ == '__main__': -
DataLoader/test/testplugings.py
r4c00964 rdaa56d0 4 4 5 5 import unittest 6 import math 7 import DataLoader 8 from DataLoader.loader import Loader 9 from DataLoader.readers import TXT3_Reader,TXT2_Reader 10 from DataLoader.readers import IgorReader,danse_reader,tiff_reader 11 import os.path 12 import os 13 import logging 14 logging.basicConfig(level=logging.DEBUG, 15 format='%(asctime)s %(levelname)s %(message)s', 16 filename='test_log.txt', 17 filemode='w') 6 from DataLoader.loader import Loader, Registry 18 7 class testLoader(unittest.TestCase): 19 8 20 try:L=Loader() 21 except AttributeError,msg: 22 logging.warning(msg) 9 def setUp(self): 10 self.L=Loader() 11 self.L.find_plugins('../plugins') 12 23 13 def testplugin(self): 24 """ test loading with readers""" 14 """ 15 test loading with a test reader only 16 found in the plugins directory 17 """ 18 output = self.L.load('test_data.test') 19 self.assertEqual(output.x[0], 1234.) 25 20 26 self.assertEqual(self.L.__contains__('.tiff'),True) 27 self.assertEqual(self.L.__contains__('.png'),True) 28 self.assertEqual(self.L.__contains__('.txt'),True) 29 #tested corrupted file.asc 30 try:self.L.load('MAR07232_rest.ASC') 31 except AttributeError,msg: 32 #logging.log(10,str(msg)) 33 logging.warning(str(msg)) 34 def testplugin1(self): 35 """ test loading with plugging""" 36 self.L.__setitem__(dir='plugins') 37 read3=IgorReader.Reader() 38 self.L.__setitem__('plugins','.ASC',read3) 39 self.assertEqual(self.L.__contains__('.ASC'),True) 40 #Testing loading a txt file of 2 columns, the only reader should be read1 41 output=self.L.load('test_2_columns.txt') 42 x=[2.83954,0.204082,0.408163,0.612245,0.816327,1.02041,1.22449,1.42857,1.63265] 43 y=[0.6,3.44938, 5.82026,5.27591,5.2781,5.22531,7.47487,7.85852,10.2278] 44 dx=[] 45 dy=[] 46 self.assertEqual(len(output.x),len(x)) 47 self.assertEqual(len(output.y),len(y)) 21 class testRegistry(unittest.TestCase): 22 23 def setUp(self): 24 self.L=Registry() 25 self.L.find_plugins('../plugins') 26 27 def testplugin(self): 28 """ 29 test loading with a test reader only 30 found in the plugins directory 31 """ 32 output = self.L.load('test_data.test') 33 self.assertEqual(output.x[0], 1234.) 34 self.assertTrue(self.L.loaders.has_key('.test')) 48 35 49 for i in range(len(x)):50 self.assertEqual(output.x[i],x[i])51 self.assertEqual(output.y[i],y[i])52 53 # How about actually executing the tests...54 36 if __name__ == '__main__': 55 37 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.