source: sasview/DataLoader/test/testLoad.py @ d22da51

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d22da51 was d22da51, checked in by Gervaise Alina <gervyh@…>, 16 years ago

clean and more testing added

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[aa749ac]1"""
2    Unit tests for DataLoader module
[d22da51]3    log file "test_log.txt" contains all errors when running loader
4    It is create in the folder where test is runned
[aa749ac]5"""
[d22da51]6import logging
7logging.basicConfig(level=logging.DEBUG,
8                    format='%(asctime)s %(levelname)s %(message)s',
9                    filename='test_log.txt',
10                    filemode='w')
11
12
13#logger.info('oops I did it again')
[aa749ac]14
15import unittest
16import math
17import DataLoader
[1b0b3ca]18from DataLoader.loader import  Loader
[aa749ac]19from DataLoader.readers import TXT3_Reader,TXT2_Reader
[c125e0c]20from DataLoader.readers import IgorReader,danse_reader,tiff_reader
[96510c8]21import os.path
[aa749ac]22class testLoader(unittest.TestCase):
[1b0b3ca]23   
24       
[aa749ac]25    """ test fitting """
[c125e0c]26    #Creating a loader
[1b0b3ca]27    L=Loader()
[c125e0c]28   
29    #creating readers
30    read1=TXT2_Reader.Reader()
31    read2=TXT3_Reader.Reader()
32    read3=IgorReader.Reader()
33    read4=danse_reader.Reader()
34    read5=tiff_reader.Reader()
35    #for each readers set an extensions inside the loader
36    L.__setitem__('.txt',read2)
37    L.__setitem__('.txt',read1)
38    L.__setitem__('.dat',read1)
39   
40    L.__setitem__('.dat',read2)
41    L.__setitem__('.ASC',read3)
42    L.__setitem__('.sans',read4)
43    L.__setitem__('.tif',read5)
44    L.__setitem__('.jpg',read5)
45    L.__setitem__('.png',read5)
46    L.__setitem__('.jpeg',read5)
47    L.__setitem__('.gif',read5)
48    L.__setitem__('.bmp',read5)
49       
[d22da51]50    def testLoad0(self):
51        """test reading empty file"""
[c125e0c]52        self.assertEqual(self.L.load('empty.txt'),None)
[d22da51]53       
54    def testLoad1(self):
55        """test reading 2 columns"""
56       
[c125e0c]57        #Testing loading a txt file of 2 columns, the only reader should be read1
58        xload,yload,dyload=self.L.load('test_2_columns.txt') 
59        x=[2.83954,0.204082,0.408163,0.612245,0.816327,1.02041,1.22449,1.42857,1.63265]
[aa749ac]60        y=[0.6,3.44938, 5.82026,5.27591,5.2781,5.22531,7.47487,7.85852,10.2278]
61        dx=[]
62        dy=[]
63        self.assertEqual(len(xload),len(x))
64        self.assertEqual(len(yload),len(y))
[c125e0c]65        self.assertEqual(len(dyload),0)
66        for i in range(len(x)):
67            self.assertEqual(xload[i],x[i])
68            self.assertEqual(yload[i],y[i])
[d22da51]69       
[c125e0c]70   
71    def testLoad2(self):
[d22da51]72        """Testing loading a txt file of 3 columns"""
[c125e0c]73        xload,yload,dyload= self.L.load('test_3_columns.txt') 
74        x=[0,0.204082,0.408163,0.612245,0.816327,1.02041,1.22449]   
75        y=[2.83954,3.44938,5.82026,5.27591,5.2781,5.22531,7.47487]
76        dx=[]
77        dy=[0.6,0.676531,0.753061,0.829592,0.906122,0.982653,1.05918]
78        self.assertEqual(len(xload),len(x))
79        self.assertEqual(len(yload),len(y))
80        self.assertEqual(len(dyload),len(dy))
81        for i in range(len(x)):
82            self.assertEqual(xload[i],x[i])
83            self.assertEqual(yload[i],y[i])
84            self.assertEqual(dyload[i],dy[i])
[d22da51]85       
[c125e0c]86   
87    def testload3(self):
88        """ Testing loading Igor data"""
89        #tested good file.asc
90        Z,xmin, xmax, ymin, ymax= self.L.load('MAR07232_rest.ASC') 
91        self.assertEqual(xmin,-0.018558945804750416)
92        self.assertEqual(xmax, 0.016234058202440633,)
93        self.assertEqual(ymin,-0.01684257151702391)
94        self.assertEqual(ymax,0.017950440578015116)
[d22da51]95       
[c125e0c]96        #tested corrupted file.asc
[d22da51]97        try:self.L.load('AR07232_rest.ASC')
98        except ValueError,msg:
99           #logging.log(10,str(msg))
100           logging.error(str(msg))
[c125e0c]101    def testload4(self):
102        """ Testing loading danse file"""
103        #tested good file.sans
104        data=self.L.load('MP_New.sans')
[aa749ac]105       
[c125e0c]106        self.assertEqual(data.__class__,danse_reader.ReaderInfo)
[d22da51]107       
[c125e0c]108        #tested corrupted file.sans
[d22da51]109        try: self.L.load('P_New.sans')
110        except ValueError,msg:
111           #logging.log(40,str(msg))
112           logging.error(str(msg))
113        #else: raise ValueError,"No error raised for missing extension"
[c125e0c]114    def testload5(self):
115        """ Testing loading image file"""
116        data=self.L.load('angles_flat.png')
117        self.assertEqual(data.__class__,tiff_reader.ReaderInfo)
[d22da51]118       
119    def testload6(self):
120        """test file with unknown extension"""
121        try:self.L.load('hello.missing')
122        except ValueError,msg:
123           self.assertEqual( str(msg),"Unknown file type '.missing'")
124        else: raise ValueError,"No error raised for missing extension"
125       
126        #self.L.lookup('hello.missing')
127        try: self.L.lookup('hello.missing')
128        except ValueError,msg:
129           self.assertEqual( str(msg),"Unknown file type '.missing'")
130        else: raise ValueError,"No error raised for missing extension"
131       
132    def testload7(self):
133        """ test file containing an image but as extension .txt"""
134        self.assertEqual(self.L.load('angles_flat.txt'),None)
[1b0b3ca]135   
Note: See TracBrowser for help on using the repository browser.