1 | """ |
---|
2 | Unit tests for DataLoader module |
---|
3 | """ |
---|
4 | |
---|
5 | import unittest |
---|
6 | from sans.dataloader.loader import Loader, Registry |
---|
7 | class testLoader(unittest.TestCase): |
---|
8 | |
---|
9 | def setUp(self): |
---|
10 | self.L=Loader() |
---|
11 | self.L.find_plugins('../plugins') |
---|
12 | |
---|
13 | def testplugin(self): |
---|
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.) |
---|
20 | |
---|
21 | class 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')) |
---|
35 | |
---|
36 | class testZip(unittest.TestCase): |
---|
37 | |
---|
38 | def setUp(self): |
---|
39 | self.L=Registry() |
---|
40 | |
---|
41 | # Create module |
---|
42 | import zipfile |
---|
43 | z = zipfile.PyZipFile("plugins.zip", 'w') |
---|
44 | z.writepy("../plugins", "") |
---|
45 | z.close() |
---|
46 | |
---|
47 | def testplugin_checksetup(self): |
---|
48 | """ |
---|
49 | Check that the test is valid by confirming |
---|
50 | that the file can't be loaded without the |
---|
51 | plugins |
---|
52 | """ |
---|
53 | self.assertRaises(ValueError, self.L.load, 'test_data.test') |
---|
54 | |
---|
55 | def testplugin(self): |
---|
56 | """ |
---|
57 | test loading with a test reader only |
---|
58 | found in the plugins directory |
---|
59 | """ |
---|
60 | self.L.find_plugins('.') |
---|
61 | output = self.L.load('test_data.test') |
---|
62 | self.assertEqual(output.x[0], 1234.) |
---|
63 | self.assertTrue(self.L.loaders.has_key('.test')) |
---|
64 | |
---|
65 | |
---|
66 | if __name__ == '__main__': |
---|
67 | unittest.main() |
---|