source: flex_extract.git/python/pythontest/TestTools.py @ 2ad8ea5

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

added a test for function get_cmdline_arguments

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import os
5import sys
6#import unittest
7import pytest
8
9sys.path.append('../')
10import _config
11from tools import (init128, to_param_id, my_error, read_ecenv,
12                   get_cmdline_arguments)
13
14
15class TestTools():
16    '''
17    '''
18
19    def setUp(self):
20        pass
21
22    def test_get_cmdline_arguments(self):
23        '''
24        '''
25        cmd_dict_control = {'start_date':'20180101',
26                            'end_date':'20180101',
27                            'date_chunk':'3',
28                            'basetime':'12',
29                            'step':'1',
30                            'levelist':'1/to/10',
31                            'area':'50/10/60/20',
32                            'inputdir':'../work',
33                            'outputdir':'../work',
34                            'flexpart_root_scripts':'../',
35                            'ppid':'1234',
36                            'job_template':'job.sh',
37                            'queue':'ecgate',
38                            'controlfile':'CONTROL.WORK',
39                            'debug':'1'}
40
41        sys.argv = ['dummy.py',
42                    '--start_date=20180101',
43                    '--end_date=20180101',
44                    '--date_chunk=3',
45                    '--basetime=12',
46                    '--step=1',
47                    '--levelist=1/to/10',
48                    '--area=50/10/60/20',
49                    '--inputdir=../work',
50                    '--outputdir=../work',
51                    '--flexpart_root_scripts=../',
52                    '--ppid=1234',
53                    '--job_template=job.sh',
54                    '--queue=ecgate',
55                    '--controlfile=CONTROL.WORK',
56                    '--debug=1']
57
58        results = get_cmdline_arguments()
59
60        assert cmd_dict_control == vars(results)
61
62    def test_init128(self):
63        '''
64        '''
65        table128 = init128(_config.PATH_GRIBTABLE)
66        expected = {'078': 'TCLW', '130': 'T', '034': 'SST'}
67        # check a sample of parameters which must have been read in
68        result = all((k in table128 and table128[k]==v) for k,v in expected.iteritems())
69        assert result == True
70
71    def test_to_param_id(self):
72        '''
73        '''
74        table128 = init128(_config.PATH_GRIBTABLE)
75        pars = to_param_id("T/SP/LSP/SSHF", table128)
76        for par in pars:
77            assert par in [130, 134, 142, 146]
78
79    def test_error_notifcation(self):
80        '''
81        '''
82        with pytest.raises(SystemExit) as pytest_wrapped_e:
83            my_error(['${USER}', 'anne.philipp@univie.ac.at'], 'Failed!')
84        assert pytest_wrapped_e.type == SystemExit
85        assert pytest_wrapped_e.value.code == 1
86
87    def test_read_ecenv(self):
88        '''
89        '''
90        envs_ref = {'ECUID': 'km4a',
91                    'ECGID': 'at',
92                    'GATEWAY': 'srvx8.img.univie.ac.at',
93                    'DESTINATION': 'annep@genericSftp'
94                   }
95        envs = read_ecenv(os.getcwd() + '/TestData/ECMWF_ENV')
96
97        assert envs_ref == envs
98
99    def test_clean_up(self):
100        assert True
101
102    def test_normal_exit(self):
103        assert True
104
105    def test_product(self):
106        assert True
107
108    def test_silent_remove(self):
109        assert True
110
111
112    def test_get_list_as_string(self):
113        assert True
114
115    def test_make_dir(self):
116        assert True
117
118    def test_put_file_to_ecserver(self):
119        assert True
120
121    def submit_job_to_ecserver(self):
122        assert True
123
124if __name__ == "__main__":
125    unittest.main()
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG