[067a0c3] | 1 | #!/usr/bin/env python |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | |
---|
| 4 | import os |
---|
[2f4cc73] | 5 | import sys |
---|
| 6 | #import unittest |
---|
| 7 | import pytest |
---|
| 8 | |
---|
| 9 | sys.path.append('../') |
---|
| 10 | import _config |
---|
[2ad8ea5] | 11 | from tools import (init128, to_param_id, my_error, read_ecenv, |
---|
[451bb19] | 12 | get_cmdline_arguments, submit_job_to_ecserver) |
---|
[067a0c3] | 13 | |
---|
| 14 | |
---|
[2f4cc73] | 15 | class TestTools(): |
---|
[067a0c3] | 16 | ''' |
---|
| 17 | ''' |
---|
| 18 | |
---|
| 19 | def setUp(self): |
---|
| 20 | pass |
---|
| 21 | |
---|
[2f4cc73] | 22 | def test_get_cmdline_arguments(self): |
---|
[2ad8ea5] | 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) |
---|
[2f4cc73] | 61 | |
---|
[067a0c3] | 62 | def test_init128(self): |
---|
| 63 | ''' |
---|
| 64 | ''' |
---|
[2f4cc73] | 65 | table128 = init128(_config.PATH_GRIBTABLE) |
---|
[067a0c3] | 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()) |
---|
[2f4cc73] | 69 | assert result == True |
---|
[067a0c3] | 70 | |
---|
| 71 | def test_to_param_id(self): |
---|
| 72 | ''' |
---|
| 73 | ''' |
---|
[2f4cc73] | 74 | table128 = init128(_config.PATH_GRIBTABLE) |
---|
[067a0c3] | 75 | pars = to_param_id("T/SP/LSP/SSHF", table128) |
---|
| 76 | for par in pars: |
---|
[2f4cc73] | 77 | assert par in [130, 134, 142, 146] |
---|
[067a0c3] | 78 | |
---|
[451bb19] | 79 | def test_my_error(self): |
---|
[067a0c3] | 80 | ''' |
---|
| 81 | ''' |
---|
[2f4cc73] | 82 | with pytest.raises(SystemExit) as pytest_wrapped_e: |
---|
[067a0c3] | 83 | my_error(['${USER}', 'anne.philipp@univie.ac.at'], 'Failed!') |
---|
[2f4cc73] | 84 | assert pytest_wrapped_e.type == SystemExit |
---|
| 85 | assert pytest_wrapped_e.value.code == 1 |
---|
[067a0c3] | 86 | |
---|
| 87 | def test_read_ecenv(self): |
---|
[2f4cc73] | 88 | ''' |
---|
| 89 | ''' |
---|
[067a0c3] | 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 | |
---|
[2f4cc73] | 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 | def test_get_list_as_string(self): |
---|
| 112 | assert True |
---|
[067a0c3] | 113 | |
---|
[2f4cc73] | 114 | def test_make_dir(self): |
---|
| 115 | assert True |
---|
[067a0c3] | 116 | |
---|
[2f4cc73] | 117 | def test_put_file_to_ecserver(self): |
---|
| 118 | assert True |
---|
[451bb19] | 119 | #assert subprocess.call(['ssh', host, 'test -e ' + pipes.quote(path)]) == 0 |
---|
| 120 | |
---|
| 121 | def test_fail_submit_job_to_ecserver(self): |
---|
| 122 | with pytest.raises(SystemExit) as pytest_wrapped_e: |
---|
| 123 | submit_job_to_ecserver('${HOME}', 'ecgate', 'job.ksh') |
---|
| 124 | assert pytest_wrapped_e.type == SystemExit |
---|
| 125 | assert pytest_wrapped_e.value.code == '... ECACCESS-JOB-SUBMIT FAILED!' |
---|
| 126 | |
---|
| 127 | def test_success_submit_job_to_ecserver(self): |
---|
| 128 | |
---|
| 129 | result = submit_job_to_ecserver('TestData/testfile.txt', |
---|
| 130 | 'ecgate', 'TestData/testfile.txt') |
---|
| 131 | assert result == 0 |
---|
| 132 | |
---|
[067a0c3] | 133 | |
---|
| 134 | |
---|
| 135 | if __name__ == "__main__": |
---|
[2f4cc73] | 136 | unittest.main() |
---|