1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | import unittest |
---|
5 | import os |
---|
6 | import sys |
---|
7 | sys.path.append('../python') |
---|
8 | import UioFiles |
---|
9 | |
---|
10 | |
---|
11 | class TestUioFiles(unittest.TestCase): |
---|
12 | ''' |
---|
13 | Test class to test the UIOFiles methods. |
---|
14 | ''' |
---|
15 | |
---|
16 | def setUp(self): |
---|
17 | ''' |
---|
18 | @Description: |
---|
19 | Prepare test case. Initialize comparing filelist and |
---|
20 | the test path. |
---|
21 | |
---|
22 | @Input: |
---|
23 | self: instance of TestUIOFiles |
---|
24 | Class to test the UIOFiles methods. |
---|
25 | |
---|
26 | @Return: |
---|
27 | <nothing> |
---|
28 | ''' |
---|
29 | self.testpath = os.path.join(os.path.dirname(__file__), 'TestDir') |
---|
30 | self.expected = ['FCGG__SL.20160410.40429.16424.grb', |
---|
31 | 'FCOG__ML.20160410.40429.16424.grb', |
---|
32 | 'FCSH__ML.20160410.40429.16424.grb', |
---|
33 | 'OG_OROLSM__SL.20160410.40429.16424.grb', |
---|
34 | 'FCOG_acc_SL.20160409.40429.16424.grb', |
---|
35 | 'FCOG__SL.20160410.40429.16424.grb', |
---|
36 | 'FCSH__SL.20160410.40429.16424.grb'] |
---|
37 | |
---|
38 | return |
---|
39 | |
---|
40 | def test_listFiles(self): |
---|
41 | ''' |
---|
42 | @Description: |
---|
43 | Test the listFiles method from class UIOFiles. |
---|
44 | |
---|
45 | @Input: |
---|
46 | self: instance of TestClass |
---|
47 | Class to test the UIOFiles methods. |
---|
48 | |
---|
49 | @Return: |
---|
50 | <nothing> |
---|
51 | ''' |
---|
52 | |
---|
53 | # Initialise and collect filenames |
---|
54 | files = UioFiles.UioFiles(['.grb']) |
---|
55 | files.list_files(self.testpath, '*') |
---|
56 | # get the basename to just check for equality of filenames |
---|
57 | filelist = [os.path.basename(f) for f in files.files] |
---|
58 | # comparison of expected filenames against the collected ones |
---|
59 | self.assertItemsEqual(self.expected, filelist) |
---|
60 | |
---|
61 | return |
---|
62 | |
---|
63 | if __name__ == "__main__": |
---|
64 | unittest.main() |
---|