1 | """ |
---|
2 | Unit tests for DataLoader module |
---|
3 | """ |
---|
4 | |
---|
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') |
---|
18 | class testLoader(unittest.TestCase): |
---|
19 | |
---|
20 | try:L=Loader() |
---|
21 | except AttributeError,msg: |
---|
22 | logging.warning(msg) |
---|
23 | def testplugin(self): |
---|
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) |
---|
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)) |
---|
48 | |
---|
49 | for i in range(len(x)): |
---|
50 | self.assertEqual(output.x[i],x[i]) |
---|
51 | self.assertEqual(output.y[i],y[i]) |
---|