1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | import unittest |
---|
5 | import sys |
---|
6 | import os |
---|
7 | sys.path.append('../python') |
---|
8 | from tools import init128, to_param_id, my_error, read_ecenv |
---|
9 | |
---|
10 | |
---|
11 | class TestTools(unittest.TestCase): |
---|
12 | ''' |
---|
13 | ''' |
---|
14 | |
---|
15 | def setUp(self): |
---|
16 | pass |
---|
17 | |
---|
18 | def test_init128(self): |
---|
19 | ''' |
---|
20 | ''' |
---|
21 | table128 = init128('../grib_templates/ecmwf_grib1_table_128') |
---|
22 | expected = {'078': 'TCLW', '130': 'T', '034': 'SST'} |
---|
23 | # check a sample of parameters which must have been read in |
---|
24 | result = all((k in table128 and table128[k]==v) for k,v in expected.iteritems()) |
---|
25 | self.assertEqual(result, True) |
---|
26 | |
---|
27 | |
---|
28 | def test_to_param_id(self): |
---|
29 | ''' |
---|
30 | ''' |
---|
31 | table128 = init128('../grib_templates/ecmwf_grib1_table_128') |
---|
32 | pars = to_param_id("T/SP/LSP/SSHF", table128) |
---|
33 | for par in pars: |
---|
34 | self.assertIn(par, [130, 134, 142, 146]) |
---|
35 | |
---|
36 | def test_error_notifcation(self): |
---|
37 | ''' |
---|
38 | ''' |
---|
39 | with self.assertRaises(SystemExit) as re: |
---|
40 | my_error(['${USER}', 'anne.philipp@univie.ac.at'], 'Failed!') |
---|
41 | self.assertEqual(re.exception.code, 1) |
---|
42 | |
---|
43 | def test_read_ecenv(self): |
---|
44 | |
---|
45 | envs_ref = {'ECUID': 'km4a', |
---|
46 | 'ECGID': 'at', |
---|
47 | 'GATEWAY': 'srvx8.img.univie.ac.at', |
---|
48 | 'DESTINATION': 'annep@genericSftp' |
---|
49 | } |
---|
50 | envs = read_ecenv(os.getcwd() + '/TestData/ECMWF_ENV') |
---|
51 | |
---|
52 | self.assertDictEqual(envs_ref, envs) |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | if __name__ == "__main__": |
---|
59 | unittest.main() |
---|