From 222aa11adf53657adfc8efd6a35ab83b1efb0688 Mon Sep 17 00:00:00 2001
From: Anne Philipp <anne.philipp@univie.ac.at>
Date: Mon, 10 Sep 2018 10:54:42 +0200
Subject: [PATCH] added pathes in config file and according testcases

---
 .../ecmwf_grib1_table_128                     |  0
 python/COMMANDS                               | 16 +++++++
 python/CONTROL.test                           |  8 ++--
 python/_config.py                             | 20 +++++++--
 python/install.py                             |  2 +-
 python/job.ksh                                | 12 ++---
 python/pythontest/.cache/v/cache/lastfailed   |  2 -
 python/pythontest/.coverage                   |  1 +
 python/pythontest/TestInput.py                |  1 +
 python/pythontest/TestPathes.py               | 18 ++++++++
 python/pythontest/TestTools.py                | 44 ++++++++++---------
 python/submit.py                              |  2 +-
 12 files changed, 87 insertions(+), 39 deletions(-)
 rename {python/templates => _templates}/ecmwf_grib1_table_128 (100%)
 create mode 100644 python/COMMANDS
 create mode 100644 python/pythontest/.coverage

diff --git a/python/templates/ecmwf_grib1_table_128 b/_templates/ecmwf_grib1_table_128
similarity index 100%
rename from python/templates/ecmwf_grib1_table_128
rename to _templates/ecmwf_grib1_table_128
diff --git a/python/COMMANDS b/python/COMMANDS
new file mode 100644
index 0000000..f53f812
--- /dev/null
+++ b/python/COMMANDS
@@ -0,0 +1,16 @@
+./install.py --target=ecgate --ecuid=km4a --ecgid=at --gateway=srvx8.img.univie.ac.at --destination=annep@genericSftp 
+
+./submit.py --queue=ecgate --start_date=20160809 --debug=True
+
+firefox  SphinxDoc/_build/html/index.html  &
+
+./plot_retrieved.py --start_date=2016080906 --inputdir=../work2/ --paramIds=131 --end_date=2016080909 --prefix=EI --levelist=59/60
+
+./prepareFLEXPART.py --start_date=20010809 --debug=1 --controlfile=CONTROL_CERA.test --ppid=1411 --inputdir=../work2/
+
+find ./ -name \*.py -exec sed -i 's/Disagg/disaggregation/g' {} \;
+
+
+pyreserve *.py # on s1
+dot -Tpng packages.dot -O #on s8
+dot -Tpng classes.dot -O #on s8
diff --git a/python/CONTROL.test b/python/CONTROL.test
index 6a9ce87..b693ee4 100644
--- a/python/CONTROL.test
+++ b/python/CONTROL.test
@@ -6,11 +6,11 @@ CLASS EI
 STREAM OPER
 EXPVER 1
 GRID 5000  
-LEFT -15000
+LEFT -10000
 LOWER 30000
-UPPER 75000
-RIGHT 45000
-LEVELIST 55/to/60
+UPPER 40000
+RIGHT 10000
+LEVELIST 59/to/60
 RESOL 63
 GAUSS 1
 ADDPAR 186/187/188/235/139/39
diff --git a/python/_config.py b/python/_config.py
index 239e97a..4389b23 100644
--- a/python/_config.py
+++ b/python/_config.py
@@ -28,11 +28,23 @@ import inspect
 _VERSION_STR = '7.1'
 
 # add path to pythonpath
-LOCAL_PYTHON_PATH = os.path.dirname(os.path.abspath(
+PATH_LOCAL_PYTHON = os.path.dirname(os.path.abspath(
     inspect.getfile(inspect.currentframe())))
-if LOCAL_PYTHON_PATH not in sys.path:
-    sys.path.append(LOCAL_PYTHON_PATH)
+if PATH_LOCAL_PYTHON not in sys.path:
+    sys.path.append(PATH_LOCAL_PYTHON)
+
+PATH_FLEXEXTRACT_DIR = os.path.normpath(os.path.dirname(os.path.abspath(
+    inspect.getfile(inspect.currentframe()))) + '/../')
+
+PATH_TEMPLATES = os.path.join(PATH_FLEXEXTRACT_DIR + os.path.sep +
+                              '_templates')
 
 # path to gribtable
-PATH_GRIBTABLE = LOCAL_PYTHON_PATH + '/templates/ecmwf_grib1_table_128'
+PATH_GRIBTABLE = os.path.join(PATH_TEMPLATES + os.path.sep +
+                              'ecmwf_grib1_table_128')
+
+PATH_RUN_DIR = os.path.join(PATH_FLEXEXTRACT_DIR + os.path.sep +
+                                'run')
 
+PATH_CONTROLFILES = os.path.join(PATH_RUN_DIR + os.path.sep +
+                                'control')
diff --git a/python/install.py b/python/install.py
index a1864ba..80d87be 100755
--- a/python/install.py
+++ b/python/install.py
@@ -262,7 +262,7 @@ def mk_tarball(ecd, tarname):
                                ecd + 'python/*ksh ' +
                                ecd + 'python/*temp* ' +
                                ecd + 'python/ECMWF_ENV ' +
-                               ecd + 'grib_templates ' +
+                               ecd + '_templates ' +
                                ecd + 'src/*.f ' +
                                ecd + 'src/*.f90 ' +
                                ecd + 'src/*.h ' +
diff --git a/python/job.ksh b/python/job.ksh
index 8cbc1d8..ae3bec5 100644
--- a/python/job.ksh
+++ b/python/job.ksh
@@ -67,7 +67,7 @@ ecgid at
 ecstorage 0
 ectrans 1
 ecuid km4a
-end_date 20000101
+end_date 20100606
 eta 0
 etadiff 0
 etapar 77
@@ -80,9 +80,9 @@ grid 5000
 inputdir ../work
 install_target None
 job_template job.temp
-left -15000
+left -10000
 level 60
-levelist 55/to/60
+levelist 59/to/60
 lower 30000
 mailfail ${USER} 
 mailops ${USER} 
@@ -96,14 +96,14 @@ outputdir ../work
 prefix EItest_
 queue ecgate
 resol 63
-right 45000
+right 10000
 smooth 0
-start_date 20000101
+start_date 20100606
 step 00 01 02 03 04 05 00 07 08 09 10 11 00 01 02 03 04 05 00 07 08 09 10 11 
 stream OPER
 time 00 00 00 00 00 00 06 00 00 00 00 00 12 12 12 12 12 12 18 12 12 12 12 12 
 type AN FC FC FC FC FC AN FC FC FC FC FC AN FC FC FC FC FC AN FC FC FC FC FC 
-upper 75000
+upper 40000
 wrf 0
 EOF
 
diff --git a/python/pythontest/.cache/v/cache/lastfailed b/python/pythontest/.cache/v/cache/lastfailed
index c9e4567..628a749 100644
--- a/python/pythontest/.cache/v/cache/lastfailed
+++ b/python/pythontest/.cache/v/cache/lastfailed
@@ -1,6 +1,4 @@
 {
-  "TestTools.py::TestTools::()": true, 
-  "TestTools.py::TestTools::()::test_failany_silent_remove": true, 
   "TestTools.py::TestTools::test_init128": true, 
   "TestTools.py::TestTools::test_to_param_id": true
 }
\ No newline at end of file
diff --git a/python/pythontest/.coverage b/python/pythontest/.coverage
new file mode 100644
index 0000000..47caf6b
--- /dev/null
+++ b/python/pythontest/.coverage
@@ -0,0 +1 @@
+!coverage.py: This is a private format, don't read it directly!{"lines":{"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/test_suite.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/_config.py":[32,33,37,24,25,26,28,31],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/MarsRetrieval.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/install.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/get_mars_data.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/testecmwfapi.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/EcFlexpart.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/profiling.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/pythontest/TestInput.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/plot_retrieved.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/ControlFile.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/submit.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/pythontest/__init__.py":[13],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/pythontest/TestTools.py":[4,5,6,7,8,10,11,12,18,20,22,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,59,61,63,64,65,67,68,70,71,72,73,74,76,77,78,79,80,82,83,84,85,86,88,90,92,94,96,97,99,100,102,103,104,105,106,107,108,110,111,112,113,114,115,117,126,127,128,129,131,139,140,141,142,143,145,146,147,148,149,151,152,153,154,155,157,158,159,160,161,162,163,164,166,167,168,169,170,171,173,175,176,177,178,182,183,184,185,186,188,189,190,193],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/disaggregation.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/pythontest/TestPathes.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/GribTools.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/prepare_flexpart.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/tools.py":[517,518,519,520,521,522,523,524,526,527,529,50,51,52,53,54,55,56,62,76,77,78,81,82,83,84,85,86,89,90,91,92,93,94,95,96,99,100,101,102,103,104,107,110,112,115,116,117,118,120,121,122,123,124,125,127,129,131,144,145,146,147,148,149,151,153,191,210,213,214,215,216,217,218,219,220,221,222,223,224,229,230,232,237,279,315,328,329,330,331,335,338,353,354,355,356,357,358,360,363,386,387,388,389,390,391,392,396,398,416,418,420,433,434,435,436,438,440,442,444,476,477,478,481,482,483,484,485,486,488,489,491,493],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/pythontest/TestEcFlexpart.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/pythontest/TestUIOFiles.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/pythontest/TestInstall.py":[],"/raid60/nas/tmc/Anne/Interpolation/flexextract/flexextract/python/UioFiles.py":[]}}
\ No newline at end of file
diff --git a/python/pythontest/TestInput.py b/python/pythontest/TestInput.py
index 97fd488..61bede1 100644
--- a/python/pythontest/TestInput.py
+++ b/python/pythontest/TestInput.py
@@ -4,6 +4,7 @@
 import unittest
 import os
 import sys
+
 sys.path.append('../python')
 from ControlFile import ControlFile
 import tools
diff --git a/python/pythontest/TestPathes.py b/python/pythontest/TestPathes.py
index b74932f..542b4ee 100644
--- a/python/pythontest/TestPathes.py
+++ b/python/pythontest/TestPathes.py
@@ -8,6 +8,19 @@ import pytest
 sys.path.append("../")
 import _config
 
+def test_path_localpython():
+    assert os.path.exists(_config.PATH_LOCAL_PYTHON) == 1
+
+def test_path_flexextract():
+    assert os.path.exists(_config.PATH_FLEXEXTRACT_DIR) == 1
+
+def test_path_flexextract_name():
+    version = _config._VERSION_STR
+    flexextract_name = 'flex_extract_v' + version
+    assert os.path.basename(_config.PATH_FLEXEXTRACT_DIR) == flexextract_name
+
+def test_path_templates():
+    assert os.path.exists(_config.PATH_TEMPLATES) == 1
 
 def test_path_vtable():
     assert os.path.exists(_config.PATH_GRIBTABLE) == 1
@@ -15,3 +28,8 @@ def test_path_vtable():
 def test_file_vtable():
     assert os.path.isfile(_config.PATH_GRIBTABLE) == 1
 
+def test_path_run():
+    assert os.path.exists(_config.PATH_RUN_DIR) == 1
+
+def test_path_control():
+    assert os.path.exists(_config.PATH_CONTROLFILES) == 1
diff --git a/python/pythontest/TestTools.py b/python/pythontest/TestTools.py
index 039f362..f55ebf9 100644
--- a/python/pythontest/TestTools.py
+++ b/python/pythontest/TestTools.py
@@ -23,8 +23,6 @@ class TestTools():
         pass
 
     def test_get_cmdline_arguments(self):
-        '''
-        '''
         cmd_dict_control = {'start_date':'20180101',
                             'end_date':'20180101',
                             'date_chunk':'3',
@@ -63,8 +61,6 @@ class TestTools():
         assert cmd_dict_control == vars(results)
 
     def test_init128(self):
-        '''
-        '''
         table128 = init128(_config.PATH_GRIBTABLE)
         expected = {'078': 'TCLW', '130': 'T', '034': 'SST'}
         # check a sample of parameters which must have been read in
@@ -72,24 +68,18 @@ class TestTools():
         assert result == True
 
     def test_to_param_id(self):
-        '''
-        '''
         table128 = init128(_config.PATH_GRIBTABLE)
         pars = to_param_id("T/SP/LSP/SSHF", table128)
         for par in pars:
             assert par in [130, 134, 142, 146]
 
     def test_my_error(self):
-        '''
-        '''
         with pytest.raises(SystemExit) as pytest_wrapped_e:
             my_error(['${USER}', 'anne.philipp@univie.ac.at'], 'Failed!')
         assert pytest_wrapped_e.type == SystemExit
         assert pytest_wrapped_e.value.code == 1
 
     def test_read_ecenv(self):
-        '''
-        '''
         envs_ref = {'ECUID': 'km4a',
                     'ECGID': 'at',
                     'GATEWAY': 'srvx8.img.univie.ac.at',
@@ -100,6 +90,7 @@ class TestTools():
         assert envs_ref == envs
 
     def test_clean_up(self):
+
         assert True
 
     def test_normal_exit(self):
@@ -122,17 +113,28 @@ class TestTools():
         out, err = capfd.readouterr()
         assert os.path.isfile(testfile) == False
         assert out == ''
-#
-#    def test_failany_silent_remove(self):
-#        testfile = 'testfileany.test'
-#        with pytest.raises(OSError) as pytest_wrapped_e:
-#            silent_remove(testfile)
-#        #out, err = capfd.readouterr()
-#        #assert os.path.isfile(testfile) == False
-#        #assert out == ''
-
-    def test_get_list_as_string(self):
-        assert True
+
+    @pytest.mark.skip(reason="no way of currently testing this")
+    def test_failany_silent_remove(self):
+        testfile = 'testfileany.test'
+        with pytest.raises(OSError) as pytest_wrapped_e:
+            silent_remove(testfile)
+        #out, err = capfd.readouterr()
+        #assert os.path.isfile(testfile) == False
+        #assert out == ''
+
+    def test_success_get_list_as_string(self):
+        list_object =  [1, 2, 3, '...', 'testlist']
+        list_as_string = '1, 2, 3, ..., testlist'
+        assert list_as_string == get_list_as_string(list_object)
+
+    @pytest.mark.skip(reason="no way of currently testing this")
+    def test_fail_get_list_as_string(self):
+        list_object =  [1, 2, 3, '...', 'testlist']
+        list_as_string = '1, 2, 3, ..., testlist'
+        with pytest.raises(Exception) as pytest_wrapped_e:
+            result = get_list_as_string(list_object)
+        assert result == list_as_string
 
     def test_warningexist_make_dir(self, capfd):
         testdir = 'TestData'
diff --git a/python/submit.py b/python/submit.py
index 91114a1..a041ded 100755
--- a/python/submit.py
+++ b/python/submit.py
@@ -80,7 +80,7 @@ def main():
         c = ControlFile(args.controlfile)
     except IOError:
         try:
-            c = ControlFile(LOCAL_PYTHON_PATH + args.controlfile)
+            c = ControlFile(_config.PATH_LOCAL_PYTHON + args.controlfile)
         except IOError:
             print 'Could not read CONTROL file "' + args.controlfile + '"'
             print 'Either it does not exist or its syntax is wrong.'
-- 
GitLab