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

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 4102709 was 1b0b3ca, checked in by Gervaise Alina <gervyh@…>, 16 years ago

not cleaned yet but working using guiframe

  • Property mode set to 100644
File size: 3.9 KB
Line 
1"""
2    Unit tests for DataLoader module
3"""
4
5import unittest
6import math
7import DataLoader
8from DataLoader.loader import  Loader
9from DataLoader.readers import TXT3_Reader,TXT2_Reader
10from DataLoader.readers import IgorReader,danse_reader,tiff_reader
11import os.path
12class testLoader(unittest.TestCase):
13   
14       
15    """ test fitting """
16    #Creating a loader
17    L=Loader()
18   
19    #creating readers
20    read1=TXT2_Reader.Reader()
21    read2=TXT3_Reader.Reader()
22    read3=IgorReader.Reader()
23    read4=danse_reader.Reader()
24    read5=tiff_reader.Reader()
25    #for each readers set an extensions inside the loader
26    L.__setitem__('.txt',read2)
27    L.__setitem__('.txt',read1)
28    L.__setitem__('.dat',read1)
29   
30    L.__setitem__('.dat',read2)
31    L.__setitem__('.ASC',read3)
32    L.__setitem__('.sans',read4)
33    L.__setitem__('.tif',read5)
34    L.__setitem__('.jpg',read5)
35    L.__setitem__('.png',read5)
36    L.__setitem__('.jpeg',read5)
37    L.__setitem__('.gif',read5)
38    L.__setitem__('.bmp',read5)
39       
40    def testLoad1(self):
41        """test reading empty file, no file can read it"""
42        self.assertEqual(self.L.load('empty.txt'),None)
43        self.assertEqual( self.L.getAcTReader('empty.txt'),None)
44         
45        #Testing loading a txt file of 2 columns, the only reader should be read1
46        xload,yload,dyload=self.L.load('test_2_columns.txt') 
47        x=[2.83954,0.204082,0.408163,0.612245,0.816327,1.02041,1.22449,1.42857,1.63265]
48        y=[0.6,3.44938, 5.82026,5.27591,5.2781,5.22531,7.47487,7.85852,10.2278]
49        dx=[]
50        dy=[]
51        self.assertEqual(len(xload),len(x))
52        self.assertEqual(len(yload),len(y))
53        self.assertEqual(len(dyload),0)
54        for i in range(len(x)):
55            self.assertEqual(xload[i],x[i])
56            self.assertEqual(yload[i],y[i])
57        self.assertEqual( self.L.getAcTReader('test_2_columns.txt'),self.read1.__class__)
58   
59    def testLoad2(self):
60        """Testing loading a txt file of 3 columns, the only reader should be read2"""
61        xload,yload,dyload= self.L.load('test_3_columns.txt') 
62        x=[0,0.204082,0.408163,0.612245,0.816327,1.02041,1.22449]   
63        y=[2.83954,3.44938,5.82026,5.27591,5.2781,5.22531,7.47487]
64        dx=[]
65        dy=[0.6,0.676531,0.753061,0.829592,0.906122,0.982653,1.05918]
66        self.assertEqual(len(xload),len(x))
67        self.assertEqual(len(yload),len(y))
68        self.assertEqual(len(dyload),len(dy))
69        for i in range(len(x)):
70            self.assertEqual(xload[i],x[i])
71            self.assertEqual(yload[i],y[i])
72            self.assertEqual(dyload[i],dy[i])
73        self.assertEqual(self.L.getAcTReader('test_3_columns.txt'),self.read2.__class__)
74   
75    def testload3(self):
76        """ Testing loading Igor data"""
77        #tested good file.asc
78        Z,xmin, xmax, ymin, ymax= self.L.load('MAR07232_rest.ASC') 
79        self.assertEqual(xmin,-0.018558945804750416)
80        self.assertEqual(xmax, 0.016234058202440633,)
81        self.assertEqual(ymin,-0.01684257151702391)
82        self.assertEqual(ymax,0.017950440578015116)
83        self.assertEqual(self.L.getAcTReader('MAR07232_rest.ASC'),self.read3.__class__)
84        #tested corrupted file.asc
85        self.assertEqual(self.L.load('AR07232_rest.ASC') ,None)
86   
87    def testload4(self):
88        """ Testing loading danse file"""
89        #tested good file.sans
90        data=self.L.load('MP_New.sans')
91       
92        self.assertEqual(data.__class__,danse_reader.ReaderInfo)
93        self.assertEqual(self.L.getAcTReader('MP_New.sans'),self.read4.__class__)
94        #tested corrupted file.sans
95        self.assertEqual(self.L.load('P_New.sans'),None)
96   
97    def testload5(self):
98        """ Testing loading image file"""
99        data=self.L.load('angles_flat.png')
100        self.assertEqual(data.__class__,tiff_reader.ReaderInfo)
101        self.assertEqual(self.L.getAcTReader('angles_flat.png'),self.read5.__class__)
102   
103   
Note: See TracBrowser for help on using the repository browser.