Changeset daa56d0 in sasview for DataLoader/test


Ignore:
Timestamp:
Sep 3, 2008 11:47:12 AM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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
Message:

Mostly completed DataLoader?. Reimplemented using REFL registry as base class. Added writing capability and dynamic loading of readers (need zip file support for future py2exe use). All tests pass.

Location:
DataLoader/test
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/test/error_conditions.py

    rf9474b5 rdaa56d0  
    99        """ 
    1010            self.s.load('blah.mat') on an unknown type 
    11             should raise a runtime exception 
     11            should raise a ValueError exception (thrown by data_util.registry) 
    1212        """ 
    13         self.assertRaises(RuntimeError, self.s.load, 'angles_flat.mat') 
     13        self.assertRaises(ValueError, self.s.load, 'angles_flat.mat') 
    1414         
    1515    def test_corrupt(self): 
  • DataLoader/test/sequence_tests.py

    rb99ac227 rdaa56d0  
    2929    single_igor() 
    3030    single_abs() 
     31    print "Test passed" 
  • DataLoader/test/testLoad.py

    rb99ac227 rdaa56d0  
    1616import DataLoader 
    1717from DataLoader.loader import  Loader 
    18   
     18 
     19# Check whether we should test image loading on this system  
     20HAS_IMAGE = False 
     21try: 
     22    import Image 
     23    HAS_IMAGE = True 
     24except: 
     25    print "IMAGE TESTS WILL NOT BE PERFORMED: MISSING PIL MODULE" 
     26     
    1927import os.path 
    2028 
     
    2432        self.loader = Loader() 
    2533         
    26          
    2734    def test_singleton(self): 
    2835        """ 
    2936            Testing whether Loader is truly a singleton 
    3037        """ 
    31         # Set a new data member 
    32         self.loader._test_data_member = 1.45 
    33          
    3438        # Create a 'new' Loader 
    3539        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()) 
    3942 
    4043class testLoader(unittest.TestCase): 
     
    5356    def testLoad0(self): 
    5457        """test reading empty file""" 
    55         self.assertEqual(self.L.load('empty.txt'),None) 
     58        self.assertRaises(RuntimeError, self.L.load, 'empty.txt') 
    5659         
    5760    def testLoad1(self): 
     
    8790            self.assertEqual(output.dy[i],dy[i]) 
    8891        
     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        
    89107     
    90108    def testload3(self): 
     
    92110        #tested good file.asc 
    93111        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')  
    94127        self.assertEqual(output.xmin,-0.018558945804750416) 
    95128        self.assertEqual(output.xmax, 0.016234058202440633,) 
     
    118151    def testload5(self): 
    119152        """ 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) 
    122156         
    123157    def testload6(self): 
    124158        """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') 
    129160         
    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         
    135164         
    136165    def testload7(self): 
    137166        """ test file containing an image but as extension .txt""" 
    138         self.assertEqual(self.L.load('angles_flat.txt'),None) 
     167        self.assertRaises(RuntimeError, self.L.load, 'angles_flat.txt') 
    139168 
    140169if __name__ == '__main__': 
  • DataLoader/test/testplugings.py

    r4c00964 rdaa56d0  
    44 
    55import 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') 
     6from DataLoader.loader import  Loader, Registry 
    187class testLoader(unittest.TestCase): 
    198     
    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             
    2313    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.) 
    2520         
    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)) 
     21class 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')) 
    4835         
    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... 
    5436if __name__ == '__main__': 
    5537    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.