source: flex_extract.git/python/pythontest/TestTools.py @ 067a0c3

ctbtodev
Last change on this file since 067a0c3 was 067a0c3, checked in by Anne Philipp <anne.philipp@…>, 6 years ago

renamed documentation dir; moved pythontest to python dir

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[067a0c3]1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import unittest
5import sys
6import os
7sys.path.append('../python')
8from tools import init128, to_param_id, my_error, read_ecenv
9
10
11class 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
58if __name__ == "__main__":
59    unittest.main()
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG