1 | """ |
---|
2 | Unit tests for DataLoader module |
---|
3 | """ |
---|
4 | |
---|
5 | import os |
---|
6 | import unittest |
---|
7 | from sas.sascalc.dataloader.loader import Loader, Registry |
---|
8 | class testLoader(unittest.TestCase): |
---|
9 | |
---|
10 | def setUp(self): |
---|
11 | self.L=Loader() |
---|
12 | self.L.find_plugins('../plugins') |
---|
13 | |
---|
14 | def testplugin(self): |
---|
15 | """ |
---|
16 | test loading with a test reader only |
---|
17 | found in the plugins directory |
---|
18 | """ |
---|
19 | output = self.L.load('test_data.test') |
---|
20 | self.assertEqual(output.x[0], 1234.) |
---|
21 | |
---|
22 | class testRegistry(unittest.TestCase): |
---|
23 | |
---|
24 | def setUp(self): |
---|
25 | self.L=Registry() |
---|
26 | self.L.find_plugins('../plugins') |
---|
27 | |
---|
28 | def testplugin(self): |
---|
29 | """ |
---|
30 | test loading with a test reader only |
---|
31 | found in the plugins directory |
---|
32 | """ |
---|
33 | output = self.L.load('test_data.test') |
---|
34 | self.assertEqual(output.x[0], 1234.) |
---|
35 | self.assertTrue('.test' in self.L.loaders) |
---|
36 | |
---|
37 | class testZip(unittest.TestCase): |
---|
38 | |
---|
39 | def setUp(self): |
---|
40 | self.L=Registry() |
---|
41 | |
---|
42 | # Create module |
---|
43 | import zipfile |
---|
44 | f_name = "plugins.zip" |
---|
45 | z = zipfile.PyZipFile(f_name, 'w') |
---|
46 | z.writepy("../plugins", "") |
---|
47 | z.close() |
---|
48 | if os.path.isfile(f_name): |
---|
49 | os.remove(f_name) |
---|
50 | |
---|
51 | def testplugin_checksetup(self): |
---|
52 | """ |
---|
53 | Check that the test is valid by confirming |
---|
54 | that the file can't be loaded without the |
---|
55 | plugins |
---|
56 | """ |
---|
57 | self.assertRaises(ValueError, self.L.load, 'test_data.test') |
---|
58 | |
---|
59 | def testplugin(self): |
---|
60 | """ |
---|
61 | test loading with a test reader only |
---|
62 | found in the plugins directory |
---|
63 | """ |
---|
64 | self.L.find_plugins('.') |
---|
65 | output = self.L.load('test_data.test') |
---|
66 | self.assertEqual(output.x[0], 1234.) |
---|
67 | self.assertTrue('.test' in self.L.loaders) |
---|
68 | |
---|
69 | |
---|
70 | if __name__ == '__main__': |
---|
71 | unittest.main() |
---|