[1b0b3ca] | 1 | """ |
---|
| 2 | Unit tests for DataLoader module |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | import unittest |
---|
| 6 | import math |
---|
| 7 | import DataLoader |
---|
[d22da51] | 8 | from DataLoader.loader import Loader |
---|
[1b0b3ca] | 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 |
---|
[d3619421] | 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') |
---|
[1b0b3ca] | 18 | class testLoader(unittest.TestCase): |
---|
[d3619421] | 19 | |
---|
| 20 | try:L=Loader() |
---|
| 21 | except AttributeError,msg: |
---|
| 22 | logging.warning(msg) |
---|
[1b0b3ca] | 23 | def testplugin(self): |
---|
[2fd516b] | 24 | """ test loading with readers""" |
---|
| 25 | |
---|
| 26 | self.assertEqual(self.L.__contains__('.tiff'),True) |
---|
| 27 | self.assertEqual(self.L.__contains__('.png'),True) |
---|
| 28 | self.assertEqual(self.L.__contains__('.txt'),True) |
---|
[d3619421] | 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)) |
---|
[2fd516b] | 34 | def testplugin1(self): |
---|
[1b0b3ca] | 35 | """ test loading with plugging""" |
---|
[2fd516b] | 36 | self.L.__setitem__(dir='plugins') |
---|
[94daf8a] | 37 | read3=IgorReader.Reader() |
---|
| 38 | self.L.__setitem__('plugins','.ASC',read3) |
---|
| 39 | self.assertEqual(self.L.__contains__('.ASC'),True) |
---|
[2fd516b] | 40 | #Testing loading a txt file of 2 columns, the only reader should be read1 |
---|
[16d8e5f] | 41 | output=self.L.load('test_2_columns.txt') |
---|
[2fd516b] | 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=[] |
---|
[16d8e5f] | 46 | self.assertEqual(len(output.x),len(x)) |
---|
| 47 | self.assertEqual(len(output.y),len(y)) |
---|
| 48 | |
---|
[2fd516b] | 49 | for i in range(len(x)): |
---|
[16d8e5f] | 50 | self.assertEqual(output.x[i],x[i]) |
---|
| 51 | self.assertEqual(output.y[i],y[i]) |
---|