From fce30abff4c5000081621a43ce0fc2408e4697c7 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Fri, 3 Aug 2018 10:16:51 -0700 Subject: [PATCH 1/4] should fix #385 --- Lib/__init__.py | 2 +- Lib/pywrapper.py | 10 ++++++ Src/_cmormodule.c | 25 +++++++++++++ Src/cmor.c | 33 ++++++++++++++--- Src/cmor_cfortran_interface.c | 20 +++++++++++ Src/cmor_fortran_interface.f90 | 20 +++++++++++ Test/test_python_CMIP6_CV_terminate_signal.py | 36 +++++++++++++++++++ include/cmor.h | 1 + include/cmor_func_def.h | 4 +++ 9 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 Test/test_python_CMIP6_CV_terminate_signal.py diff --git a/Lib/__init__.py b/Lib/__init__.py index 9903232b..18e5d4b2 100644 --- a/Lib/__init__.py +++ b/Lib/__init__.py @@ -12,7 +12,7 @@ set_cur_dataset_attribute, get_cur_dataset_attribute, has_cur_dataset_attribute, set_variable_attribute, get_variable_attribute, has_variable_attribute, get_final_filename, set_deflate, set_furtherinfourl, - set_climatology, get_climatology) + set_climatology, get_climatology, set_terminate_signal, get_terminate_signal) try: from check_CMOR_compliant import checkCMOR diff --git a/Lib/pywrapper.py b/Lib/pywrapper.py index 0800285c..9a534b60 100644 --- a/Lib/pywrapper.py +++ b/Lib/pywrapper.py @@ -33,6 +33,16 @@ except BaseException: has_oldma = False +def get_terminate_signal(): + """ Return the integer code currently used by CMOR for system signal when issuing an error + -999 means not set yet, once cmor_setup is called -999 is turned to SIGTERM""" + return _cmor.get_terminate_signal() + +def set_terminate_signal(signal): + """Sets the signal code to be used by CMOR when issuing an error + int has to match whateve rint the C uses""" + _cmor.set_terminate_signal(signal) + def time_varying_grid_coordinate( grid_id, table_entry, units, type='f', missing_value=None): diff --git a/Src/_cmormodule.c b/Src/_cmormodule.c index 20fed57c..e497c64d 100644 --- a/Src/_cmormodule.c +++ b/Src/_cmormodule.c @@ -394,6 +394,29 @@ static PyObject *PyCMOR_dataset_json(PyObject * self, PyObject * args) return (Py_BuildValue("i", ierr)); } +/************************************************************************/ +/* PyCMOR_get_terminate_signal() */ +/************************************************************************/ + +static PyObject *PyCMOR_get_terminate_signal(PyObject * self, PyObject * args) +{ + return Py_BuildValue("i", cmor_get_terminate_signal()); +} +/************************************************************************/ +/* PyCMOR_set_terminate_signal() */ +/************************************************************************/ + +static PyObject *PyCMOR_set_terminate_signal(PyObject * self, PyObject * args) +{ + int signal; + if (!PyArg_ParseTuple(args, "i", &signal)) + return NULL; + + cmor_set_terminate_signal(signal); + + Py_INCREF(Py_None); + return (Py_None); +} /************************************************************************/ /* PyCMOR_load_table() */ /************************************************************************/ @@ -1064,6 +1087,8 @@ static PyMethodDef MyExtractMethods[] = { {"set_furtherinfourl", PyCMOR_set_furtherinfourl, METH_VARARGS}, {"get_final_filename", PyCMOR_getFinalFilename, METH_VARARGS}, {"set_deflate", PyCMOR_set_deflate, METH_VARARGS}, + {"set_terminate_signal", PyCMOR_set_terminate_signal, METH_VARARGS}, + {"get_terminate_signal", PyCMOR_get_terminate_signal, METH_VARARGS}, {NULL, NULL} /*sentinel */ }; diff --git a/Src/cmor.c b/Src/cmor.c index 4ca04d29..135202f0 100644 --- a/Src/cmor.c +++ b/Src/cmor.c @@ -74,6 +74,7 @@ const char CMOR_VALID_CALENDARS[CMOR_N_VALID_CALS][CMOR_MAX_STRING] = }; int CMOR_HAS_BEEN_SETUP = 0; +int CMOR_TERMINATE_SIGNAL = -999; /* not set by default */ int CV_ERROR = 0; ut_system *ut_read = NULL; FILE *output_logfile; @@ -111,12 +112,27 @@ int bAppendMode = FALSE; volatile sig_atomic_t stop = 0; +/**************************************************************************/ +/* reset signal code +/**************************************************************************/ +int cmor_get_terminate_signal() { + return CMOR_TERMINATE_SIGNAL; +} +void cmor_set_terminate_signal_to_sigint() { + CMOR_TERMINATE_SIGNAL = SIGINT; +} +void cmor_set_terminate_signal_to_sigterm() { + CMOR_TERMINATE_SIGNAL = SIGTERM; +} +void cmor_set_terminate_signal( int code) { + CMOR_TERMINATE_SIGNAL = code; +} /**************************************************************************/ /* cmor_mkdir() */ /**************************************************************************/ void terminate(int signal) { - if (signal == SIGTERM) { + if (signal == CMOR_TERMINATE_SIGNAL) { stop = 1; } } @@ -624,7 +640,7 @@ void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level) if ((CMOR_MODE == CMOR_EXIT_ON_WARNING) || (level == CMOR_CRITICAL)) { fflush(stdout); fflush(output_logfile); - kill(getpid(), SIGINT); + kill(getpid(), SIGTERM); } fflush(output_logfile); } @@ -756,11 +772,20 @@ int cmor_setup(char *path, struct tm *ptr; extern FILE *output_logfile; extern int did_history; - struct sigaction action; + + + /*********************************************************/ + /* set the default signal */ + /*********************************************************/ + + if (CMOR_TERMINATE_SIGNAL == -999) { + CMOR_TERMINATE_SIGNAL = SIGTERM; + } + memset(&action, 0, sizeof(struct sigaction)); action.sa_handler = terminate; - sigaction(SIGTERM, &action, NULL); + sigaction(CMOR_TERMINATE_SIGNAL, &action, NULL); strcpy(cmor_traceback_info, ""); cmor_add_traceback("cmor_setup"); diff --git a/Src/cmor_cfortran_interface.c b/Src/cmor_cfortran_interface.c index 5227e296..d30c43e3 100644 --- a/Src/cmor_cfortran_interface.c +++ b/Src/cmor_cfortran_interface.c @@ -373,12 +373,29 @@ void cmor_handle_error_cff_(char error_msg[CMOR_MAX_STRING], int *level) cmor_handle_error(error_msg, *level); } +/************************************************************************/ +/* cmor_get_terminate_signal_cff_() */ +/************************************************************************/ +int cmor_get_terminate_signal_cff_() { + return cmor_get_terminate_signal(signal); +} + +/************************************************************************/ +/* cmor_set_terminate_signal_cff() */ +/************************************************************************/ +void cmor_set_terminate_signal_cff_(int signal) { + cmor_set_terminate_signal(signal); +} + /************************************************************************/ /* cmor_setup_cff_nolog_() */ /************************************************************************/ int cmor_setup_cff_nolog_(char *path, int *netcdf, int *verbosity, int *mode, int *crsub) { + if (cmor_get_terminate_signal() == -999) { + cmor_set_terminate_signal_to_sigint(); + }; return (cmor_setup(path, netcdf, verbosity, mode, NULL, crsub)); } @@ -388,6 +405,9 @@ int cmor_setup_cff_nolog_(char *path, int *netcdf, int *verbosity, int cmor_setup_cff_(char *path, int *netcdf, int *verbosity, int *mode, char *logfile, int *crsub) { + if (cmor_get_terminate_signal() == -999) { + cmor_set_terminate_signal_to_sigint(); + }; return (cmor_setup(path, netcdf, verbosity, mode, logfile, crsub)); } diff --git a/Src/cmor_fortran_interface.f90 b/Src/cmor_fortran_interface.f90 index 4488a521..52ebaf6c 100644 --- a/Src/cmor_fortran_interface.f90 +++ b/Src/cmor_fortran_interface.f90 @@ -1,4 +1,14 @@ module cmor_users_functions + interface + function cmor_get_terminate_signal_cff() result (signal) + integer signal + end function + end interface + interface + subroutine cmor_set_terminate_signal_cff(signal) + integer signal + end subroutine + end interface interface function cmor_set_cur_dset_attribute_cff(name, value, optional) result (ierr) character(*) name @@ -6555,6 +6565,16 @@ end function cmor_zfactor_int_0dvalues !!$ end if !!$ end function cmor_zfactor_long_0dvalues + subroutine cmor_set_terminate_signal(signal) + integer signal + call cmor_set_terminate_signal_cff(signal) + end subroutine cmor_set_terminate_signal + + function cmor_get_terminate_signal() result(signal) + integer signal + signal = cmor_get_terminate_signal_cff() + end function + subroutine cmor_set_table(table_id) integer table_id call cmor_set_table_cff(table_id) diff --git a/Test/test_python_CMIP6_CV_terminate_signal.py b/Test/test_python_CMIP6_CV_terminate_signal.py new file mode 100644 index 00000000..f636f9b2 --- /dev/null +++ b/Test/test_python_CMIP6_CV_terminate_signal.py @@ -0,0 +1,36 @@ +# If this example is not executed from the directory containing the +# CMOR code, please first complete the following steps: +# +# 1. In any directory, create 'Tables/', 'Test/' and 'CMIP6/' directories. +# +# 2. Download +# https://github.com/PCMDI/cmor/blob/master/TestTables/CMIP6_Omon.json +# and https://github.com/PCMDI/cmor/blob/master/TestTables/CMIP6_CV.json +# to the 'Tables/' directory. +# +# 3. Download +# https://github.com/PCMDI/cmor/blob/master/Test/.json +# to the 'Test/' directory. + +import cmor +import unittest +import signal + +# ============================== +# main thread +# ============================== +def run(): + unittest.main() + + +class TestCase(unittest.TestCase): + + def testTerminateSignal(self): + self.assertEqual(cmor.get_terminate_signal(), -999) + cmor.setup() + self.assertEqual(cmor.get_terminate_signal(), signal.SIGTERM) + cmor.set_terminate_signal(signal.SIGINT) + self.assertEqual(cmor.get_terminate_signal(), signal.SIGINT) + +if __name__ == '__main__': + run() \ No newline at end of file diff --git a/include/cmor.h b/include/cmor.h index 1d29645f..c0faa701 100644 --- a/include/cmor.h +++ b/include/cmor.h @@ -265,6 +265,7 @@ //#define EXTERNAL_VARIABLE_REGEX "([[:alpha:]]+):[[:blank:]]*([[:alpha:]]+)[[:blank:]]*([[:alpha:]]+:[[:blank:]]*([[:alpha:]]+))*" #define EXTERNAL_VARIABLE_REGEX "[[:alpha:]]+:[[:blank:]]*([[:alpha:]]+)([[:blank:]]*[[:alpha:]]+:[[:blank:]]*([[:alpha:]]+))*" +extern int CMOR_TERMINATE_SIGNAL; extern int USE_NETCDF_4; extern int CMOR_MODE; extern int CMOR_TABLE; diff --git a/include/cmor_func_def.h b/include/cmor_func_def.h index 799302d3..dfb2632b 100644 --- a/include/cmor_func_def.h +++ b/include/cmor_func_def.h @@ -12,6 +12,10 @@ extern void cmor_md5( FILE * inputfile, unsigned char checksum[16] ); +extern void cmor_set_terminate_signal_to_sigint(); +extern void cmor_set_terminate_signal_to_sigterm(); +extern void cmor_set_terminate_signal( int ); +extern int cmor_get_terminate_signal(); extern void cmor_is_setup( void ); extern void cmor_add_traceback( char *name ); extern void cmor_pop_traceback( void ); From fda41b769fddbe5d87ee9e86e2282c2c646d607e Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Fri, 3 Aug 2018 10:35:10 -0700 Subject: [PATCH 2/4] cleanup test suite --- Test/base_CMIP6_CV.py | 28 ++---- Test/test_python_CMIP6_CV_HISTORY.py | 48 +++++----- Test/test_python_CMIP6_CV_bad_data_specs.py | 9 +- Test/test_python_CMIP6_CV_baddirectory.py | 2 - Test/test_python_CMIP6_CV_badgridgr.py | 2 - Test/test_python_CMIP6_CV_badgridlabel.py | 2 - .../test_python_CMIP6_CV_badgridresolution.py | 2 - Test/test_python_CMIP6_CV_badinstitution.py | 2 - Test/test_python_CMIP6_CV_badinstitutionID.py | 3 - ..._python_CMIP6_CV_badinstitutionIDNotSet.py | 2 - Test/test_python_CMIP6_CV_badsource.py | 3 - Test/test_python_CMIP6_CV_badsourceid.py | 2 - Test/test_python_CMIP6_CV_badsourcetype.py | 2 - ...st_python_CMIP6_CV_badsourcetypeCHEMAER.py | 3 - ...t_python_CMIP6_CV_badsourcetypeRequired.py | 3 - Test/test_python_CMIP6_CV_badvariant.py | 3 +- .../test_python_CMIP6_CV_externalvariables.py | 84 +++++++++--------- ...est_python_CMIP6_CV_forcemultipleparent.py | 2 - Test/test_python_CMIP6_CV_forceparent.py | 2 - Test/test_python_CMIP6_CV_furtherinfourl.py | 47 +++++----- Test/test_python_CMIP6_CV_fxtable.py | 87 +++++++++---------- Test/test_python_CMIP6_CV_hierarchicalattr.py | 47 +++++----- Test/test_python_CMIP6_CV_invalidsourceid.py | 2 - ...st_python_CMIP6_CV_longrealizationindex.py | 5 +- Test/test_python_CMIP6_CV_nomipera.py | 3 - Test/test_python_CMIP6_CV_parentsourceid.py | 2 - Test/test_python_CMIP6_CV_parenttimeunits.py | 2 - ...test_python_CMIP6_CV_parentvariantlabel.py | 2 - ...est_python_CMIP6_CV_sub_experimentIDbad.py | 2 - .../test_python_CMIP6_CV_sub_experiment_id.py | 2 - .../test_python_CMIP6_CV_sub_experimentbad.py | 2 - ...st_python_CMIP6_CV_sub_experimentnotset.py | 2 - Test/test_python_CMIP6_CV_trackingNoprefix.py | 54 +++++------- Test/test_python_CMIP6_CV_trackingprefix.py | 50 +++++------ 34 files changed, 205 insertions(+), 308 deletions(-) diff --git a/Test/base_CMIP6_CV.py b/Test/base_CMIP6_CV.py index 8c2c2acd..f13bd20e 100644 --- a/Test/base_CMIP6_CV.py +++ b/Test/base_CMIP6_CV.py @@ -1,17 +1,13 @@ from __future__ import print_function -import cmor import unittest -import sys import os import tempfile -import signal import glob debug = False -class BaseCVsTest(unittest.TestCase): - +class BaseCVsTest(unittest.TestCase): def remove_file_and_directories(self, filename): os.remove(filename) filename = os.path.dirname(filename) @@ -19,26 +15,18 @@ def remove_file_and_directories(self, filename): os.rmdir(filename) filename = os.path.dirname(filename) - def signal_handler(self, sig, frame): - if debug: print("Code received SIGINT") - return - def setUp(self, *args, **kwargs): - - # -------------- - # Create sigint handler - # -------------- - signal.signal(signal.SIGINT, self.signal_handler) # -------------- # Create tmpfile # -------------- self.tmpfile = tempfile.mkstemp()[1] - if debug: print("TEMP:",self.tmpfile) + if debug: + print("TEMP:", self.tmpfile) self.delete_files = [] def tearDown(self): - if debug: - print("would be unlinking:",self.tmpfile) + if debug: + print("would be unlinking:", self.tmpfile) return os.unlink(self.tmpfile) for filename in self.delete_files: @@ -47,7 +35,8 @@ def tearDown(self): def assertCV(self, text_to_find, line_trigger='Error:', number_of_lines_to_scan=1): line_to_scan = "" - if debug: print("LINE TRIGGER:", line_trigger) + if debug: + print("LINE TRIGGER:", line_trigger) with open(self.tmpfile) as f: lines = f.readlines() for i, line in enumerate(lines): @@ -56,5 +45,6 @@ def assertCV(self, text_to_find, line_trigger='Error:', number_of_lines_to_scan= if line_trigger in line: line_to_scan = scan break - if debug: print("SCANNED:",line_to_scan) + if debug: + print("SCANNED:", line_to_scan) self.assertIn(text_to_find, line_to_scan) \ No newline at end of file diff --git a/Test/test_python_CMIP6_CV_HISTORY.py b/Test/test_python_CMIP6_CV_HISTORY.py index 02da5f59..d348a8d0 100644 --- a/Test/test_python_CMIP6_CV_HISTORY.py +++ b/Test/test_python_CMIP6_CV_HISTORY.py @@ -33,35 +33,31 @@ class TestCase(base_CMIP6_CV.BaseCVsTest): def testCMIP6(self): ''' ''' - try: + # ------------------------------------------- + # Try to call cmor with a bad institution_ID + # ------------------------------------------- + cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) + cmor.dataset_json("Test/common_user_input.json") + cmor.load_table("CMIP6_Omon.json") - # ------------------------------------------- - # Try to call cmor with a bad institution_ID - # ------------------------------------------- - cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) - cmor.dataset_json("Test/common_user_input.json") - cmor.load_table("CMIP6_Omon.json") + cmor.set_cur_dataset_attribute("history", "set for CMIP6 unittest") - cmor.set_cur_dataset_attribute("history", "set for CMIP6 unittest") + # ------------------------------------------ + # load Omon table and create masso variable + # ------------------------------------------ + cmor.load_table("CMIP6_Omon.json") + itime = cmor.axis(table_entry="time", units='months since 2010', + coord_vals=numpy.array([0, 1, 2, 3, 4.]), + cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) + ivar = cmor.variable(table_entry="masso", axis_ids=[itime], units='kg') - # ------------------------------------------ - # load Omon table and create masso variable - # ------------------------------------------ - cmor.load_table("CMIP6_Omon.json") - itime = cmor.axis(table_entry="time", units='months since 2010', - coord_vals=numpy.array([0, 1, 2, 3, 4.]), - cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) - ivar = cmor.variable(table_entry="masso", axis_ids=[itime], units='kg') - - data = numpy.random.random(5) - for i in range(0, 5): - cmor.write(ivar, data[i:i]) - self.delete_files += [cmor.close(ivar, True)] - f = cdms2.open(cmor.get_final_filename(), "r") - a = f.getglobal("history") - self.assertIn("set for CMIP6 unittest", a) - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") + data = numpy.random.random(5) + for i in range(0, 5): + cmor.write(ivar, data[i:i]) + self.delete_files += [cmor.close(ivar, True)] + f = cdms2.open(cmor.get_final_filename(), "r") + a = f.getglobal("history") + self.assertIn("set for CMIP6 unittest", a) diff --git a/Test/test_python_CMIP6_CV_bad_data_specs.py b/Test/test_python_CMIP6_CV_bad_data_specs.py index bd1946c3..d9be4b7f 100644 --- a/Test/test_python_CMIP6_CV_bad_data_specs.py +++ b/Test/test_python_CMIP6_CV_bad_data_specs.py @@ -46,16 +46,11 @@ def testCMIP6(self): data = numpy.random.random(75) reshaped_data = data.reshape((5, 5, 3, 1)) - # This works: - cmor.write(ua_var_id, reshaped_data) - # This doesn't: - #cmor.write(ta_var_id, reshaped_data) - #cmor.write(ua_var_id, reshaped_data) + cmor.write(ta_var_id, reshaped_data) + cmor.write(ua_var_id, reshaped_data) #cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected error") except BaseException: pass diff --git a/Test/test_python_CMIP6_CV_baddirectory.py b/Test/test_python_CMIP6_CV_baddirectory.py index 0733952c..4d674905 100644 --- a/Test/test_python_CMIP6_CV_baddirectory.py +++ b/Test/test_python_CMIP6_CV_baddirectory.py @@ -32,8 +32,6 @@ def test_Directory(self): cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) try: cmor.dataset_json("Test/baddirectory.json") - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV("unable to create this directory") diff --git a/Test/test_python_CMIP6_CV_badgridgr.py b/Test/test_python_CMIP6_CV_badgridgr.py index 9a07ea5e..30d9dc40 100644 --- a/Test/test_python_CMIP6_CV_badgridgr.py +++ b/Test/test_python_CMIP6_CV_badgridgr.py @@ -56,8 +56,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass # ------------------------------------------ diff --git a/Test/test_python_CMIP6_CV_badgridlabel.py b/Test/test_python_CMIP6_CV_badgridlabel.py index e5d5db85..d6e90102 100644 --- a/Test/test_python_CMIP6_CV_badgridlabel.py +++ b/Test/test_python_CMIP6_CV_badgridlabel.py @@ -65,8 +65,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass # ------------------------------------------ diff --git a/Test/test_python_CMIP6_CV_badgridresolution.py b/Test/test_python_CMIP6_CV_badgridresolution.py index 76634db1..6dcade37 100644 --- a/Test/test_python_CMIP6_CV_badgridresolution.py +++ b/Test/test_python_CMIP6_CV_badgridresolution.py @@ -56,8 +56,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, file_name=True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV("\"335 km\"", "The current input") diff --git a/Test/test_python_CMIP6_CV_badinstitution.py b/Test/test_python_CMIP6_CV_badinstitution.py index 50058e4d..4bc52414 100644 --- a/Test/test_python_CMIP6_CV_badinstitution.py +++ b/Test/test_python_CMIP6_CV_badinstitution.py @@ -48,8 +48,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('NCC2" will be replaced with', 'Your input attribute') diff --git a/Test/test_python_CMIP6_CV_badinstitutionID.py b/Test/test_python_CMIP6_CV_badinstitutionID.py index 8f4bca3f..dc4d45f7 100644 --- a/Test/test_python_CMIP6_CV_badinstitutionID.py +++ b/Test/test_python_CMIP6_CV_badinstitutionID.py @@ -52,9 +52,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV("ddPCMDI") diff --git a/Test/test_python_CMIP6_CV_badinstitutionIDNotSet.py b/Test/test_python_CMIP6_CV_badinstitutionIDNotSet.py index 23ee7976..07705f31 100644 --- a/Test/test_python_CMIP6_CV_badinstitutionIDNotSet.py +++ b/Test/test_python_CMIP6_CV_badinstitutionIDNotSet.py @@ -50,8 +50,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV("Control Vocabulary file") diff --git a/Test/test_python_CMIP6_CV_badsource.py b/Test/test_python_CMIP6_CV_badsource.py index af5d3c69..e0c62c81 100644 --- a/Test/test_python_CMIP6_CV_badsource.py +++ b/Test/test_python_CMIP6_CV_badsource.py @@ -49,11 +49,8 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: raise - self.assertCV('"bad_source" will be replaced with value', 'Your input attribute "source"', 2) diff --git a/Test/test_python_CMIP6_CV_badsourceid.py b/Test/test_python_CMIP6_CV_badsourceid.py index 981a92bb..34fe46db 100644 --- a/Test/test_python_CMIP6_CV_badsourceid.py +++ b/Test/test_python_CMIP6_CV_badsourceid.py @@ -52,8 +52,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV("bad_sourceid") diff --git a/Test/test_python_CMIP6_CV_badsourcetype.py b/Test/test_python_CMIP6_CV_badsourcetype.py index a33b8c5d..fa52fdd5 100644 --- a/Test/test_python_CMIP6_CV_badsourcetype.py +++ b/Test/test_python_CMIP6_CV_badsourcetype.py @@ -52,8 +52,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV("source type") diff --git a/Test/test_python_CMIP6_CV_badsourcetypeCHEMAER.py b/Test/test_python_CMIP6_CV_badsourcetypeCHEMAER.py index fc05b73b..bf590906 100644 --- a/Test/test_python_CMIP6_CV_badsourcetypeCHEMAER.py +++ b/Test/test_python_CMIP6_CV_badsourcetypeCHEMAER.py @@ -52,9 +52,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass diff --git a/Test/test_python_CMIP6_CV_badsourcetypeRequired.py b/Test/test_python_CMIP6_CV_badsourcetypeRequired.py index 8b1a0849..ae1a3014 100644 --- a/Test/test_python_CMIP6_CV_badsourcetypeRequired.py +++ b/Test/test_python_CMIP6_CV_badsourcetypeRequired.py @@ -56,9 +56,6 @@ def testCMIP6(self): a = cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass # ------------------------------------------ diff --git a/Test/test_python_CMIP6_CV_badvariant.py b/Test/test_python_CMIP6_CV_badvariant.py index 34e001c8..74df1a7d 100644 --- a/Test/test_python_CMIP6_CV_badvariant.py +++ b/Test/test_python_CMIP6_CV_badvariant.py @@ -58,8 +58,7 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - - except (KeyboardInterrupt, BaseException): + except BaseException: pass # ------------------------------------------ # Check error after signal handler is back diff --git a/Test/test_python_CMIP6_CV_externalvariables.py b/Test/test_python_CMIP6_CV_externalvariables.py index 0240d546..b0f0e11a 100644 --- a/Test/test_python_CMIP6_CV_externalvariables.py +++ b/Test/test_python_CMIP6_CV_externalvariables.py @@ -85,50 +85,46 @@ def tstCMIP6(self): def testCMIP6_ExternaVariablesError(self): - try: - print "CMIP6 External Error" - cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) - error_flag = cmor.dataset_json('Test/common_user_input.json') - table_id = cmor.load_table('CMIP6_6hrLev.json') - time = cmor.axis(table_entry='time1', units='days since 2000-01-01', - coord_vals=numpy.array(range(1)), - cell_bounds=numpy.array(range(2))) - latitude = cmor.axis(table_entry='latitude', units='degrees_north', - coord_vals=numpy.array(range(5)), - cell_bounds=numpy.array(range(6))) - longitude = cmor.axis(table_entry='longitude', units='degrees_east', - coord_vals=numpy.array(range(5)), - cell_bounds=numpy.array(range(6))) - plev3 = cmor.axis(table_entry='plev3', units='Pa', - coord_vals=numpy.array([85000., 50000., 25000.])) - axis_ids = [longitude, latitude, plev3, time] - ua_var_id = cmor.variable(table_entry='ua', axis_ids=axis_ids, - units='m s-1') - ta_var_id = cmor.variable(table_entry='ta', axis_ids=axis_ids, - units='K') - data = numpy.random.random(75) - reshaped_data = data.reshape((5, 5, 3, 1)) - - # This doesn't: - cmor.write(ta_var_id, reshaped_data) - cmor.write(ua_var_id, reshaped_data) - fname_ta = cmor.close(ta_var_id, file_name=True) - fname_ua = cmor.close(ua_var_id, file_name=True) - self.delete_files += [cmor.close(ta_var_id, True)] - self.delete_files += [cmor.close(ua_var_id, True)] - cmor.close() - - f = cdms2.open(fname_ta, "r") - a = f.getglobal("external_variables") - self.assertEqual("areacella", a) - f.close() - f = cdms2.open(fname_ua, "r") - a = f.getglobal("external_variables") - self.assertEqual(None, a) - f.close() - - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") + print "CMIP6 External Error" + cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) + error_flag = cmor.dataset_json('Test/common_user_input.json') + table_id = cmor.load_table('CMIP6_6hrLev.json') + time = cmor.axis(table_entry='time1', units='days since 2000-01-01', + coord_vals=numpy.array(range(1)), + cell_bounds=numpy.array(range(2))) + latitude = cmor.axis(table_entry='latitude', units='degrees_north', + coord_vals=numpy.array(range(5)), + cell_bounds=numpy.array(range(6))) + longitude = cmor.axis(table_entry='longitude', units='degrees_east', + coord_vals=numpy.array(range(5)), + cell_bounds=numpy.array(range(6))) + plev3 = cmor.axis(table_entry='plev3', units='Pa', + coord_vals=numpy.array([85000., 50000., 25000.])) + axis_ids = [longitude, latitude, plev3, time] + ua_var_id = cmor.variable(table_entry='ua', axis_ids=axis_ids, + units='m s-1') + ta_var_id = cmor.variable(table_entry='ta', axis_ids=axis_ids, + units='K') + data = numpy.random.random(75) + reshaped_data = data.reshape((5, 5, 3, 1)) + + # This doesn't: + cmor.write(ta_var_id, reshaped_data) + cmor.write(ua_var_id, reshaped_data) + fname_ta = cmor.close(ta_var_id, file_name=True) + fname_ua = cmor.close(ua_var_id, file_name=True) + self.delete_files += [cmor.close(ta_var_id, True)] + self.delete_files += [cmor.close(ua_var_id, True)] + cmor.close() + + f = cdms2.open(fname_ta, "r") + a = f.getglobal("external_variables") + self.assertEqual("areacella", a) + f.close() + f = cdms2.open(fname_ua, "r") + a = f.getglobal("external_variables") + self.assertEqual(None, a) + f.close() if __name__ == '__main__': diff --git a/Test/test_python_CMIP6_CV_forcemultipleparent.py b/Test/test_python_CMIP6_CV_forcemultipleparent.py index 46055829..1581b2f3 100644 --- a/Test/test_python_CMIP6_CV_forcemultipleparent.py +++ b/Test/test_python_CMIP6_CV_forcemultipleparent.py @@ -94,8 +94,6 @@ def testParentExperimentID(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('parent_experiment_id') diff --git a/Test/test_python_CMIP6_CV_forceparent.py b/Test/test_python_CMIP6_CV_forceparent.py index 7cdc56e0..3d4bd0d9 100644 --- a/Test/test_python_CMIP6_CV_forceparent.py +++ b/Test/test_python_CMIP6_CV_forceparent.py @@ -64,8 +64,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('child') diff --git a/Test/test_python_CMIP6_CV_furtherinfourl.py b/Test/test_python_CMIP6_CV_furtherinfourl.py index bb4d61c0..65b9242d 100644 --- a/Test/test_python_CMIP6_CV_furtherinfourl.py +++ b/Test/test_python_CMIP6_CV_furtherinfourl.py @@ -31,34 +31,29 @@ def run(): class TestCase(base_CMIP6_CV.BaseCVsTest): def testCMIP6(self): - try: - # ------------------------------------------- - # Try to call cmor with a bad institution_ID - # ------------------------------------------- - cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) - cmor.dataset_json("Test/common_user_input.json") + # ------------------------------------------- + # Try to call cmor with a bad institution_ID + # ------------------------------------------- + cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) + cmor.dataset_json("Test/common_user_input.json") - # ------------------------------------------ - # load Omon table and create masso variable - # ------------------------------------------ - cmor.load_table("CMIP6_Omon.json") - itime = cmor.axis(table_entry="time", units='months since 2000', - coord_vals=numpy.array([0, 1, 2, 3, 4.]), - cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) - ivar = cmor.variable( - table_entry="masso", - axis_ids=[itime], - units='kg') + # ------------------------------------------ + # load Omon table and create masso variable + # ------------------------------------------ + cmor.load_table("CMIP6_Omon.json") + itime = cmor.axis(table_entry="time", units='months since 2000', + coord_vals=numpy.array([0, 1, 2, 3, 4.]), + cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) + ivar = cmor.variable( + table_entry="masso", + axis_ids=[itime], + units='kg') - data = numpy.random.random(5) - for i in range(0, 5): - cmor.write(ivar, data[i:i]) - self.delete_files += [cmor.close(ivar, True)] - cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") - except BaseException: - raise + data = numpy.random.random(5) + for i in range(0, 5): + cmor.write(ivar, data[i:i]) + self.delete_files += [cmor.close(ivar, True)] + cmor.close() f = cdms2.open(cmor.get_final_filename(), "r") a = f.getglobal("further_info_url") diff --git a/Test/test_python_CMIP6_CV_fxtable.py b/Test/test_python_CMIP6_CV_fxtable.py index 82242e84..37c141c9 100644 --- a/Test/test_python_CMIP6_CV_fxtable.py +++ b/Test/test_python_CMIP6_CV_fxtable.py @@ -34,51 +34,48 @@ class TestCase(base_CMIP6_CV.BaseCVsTest): def testCMIP6(self): - try: - # ------------------------------------------- - # Try to call cmor with a bad institution_ID - # ------------------------------------------- - nlat = 10 - dlat = 180. / nlat - nlon = 20 - dlon = 360. / nlon - - cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) - cmor.dataset_json("Test/common_user_input.json") - cmor.load_table("CMIP6_fx.json") - - lats = numpy.arange(90 - dlat / 2., -90, -dlat) - blats = numpy.arange(90, -90 - dlat, -dlat) - lons = numpy.arange(0 + dlon / 2., 360., dlon) - blons = numpy.arange(0, 360. + dlon, dlon) - - data = lats[:, numpy.newaxis] * lons[numpy.newaxis, :] - - data = (data + 1e10) / 750. + 233.2 - - ilat = cmor.axis( - table_entry='latitude', - coord_vals=lats, - cell_bounds=blats, - units='degrees_north') - ilon = cmor.axis( - table_entry='longitude', - coord_vals=lons, - cell_bounds=blons, - units='degrees_east') - - # ------------------------------------------ - # load Omon table and create masso variable - # ------------------------------------------ - ivar = cmor.variable( - table_entry="areacella", axis_ids=[ - ilat, ilon], units='m2') - - cmor.write(ivar, data) - self.delete_files += [cmor.close(ivar, True)] - cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") + # ------------------------------------------- + # Try to call cmor with a bad institution_ID + # ------------------------------------------- + nlat = 10 + dlat = 180. / nlat + nlon = 20 + dlon = 360. / nlon + + cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) + cmor.dataset_json("Test/common_user_input.json") + cmor.load_table("CMIP6_fx.json") + + lats = numpy.arange(90 - dlat / 2., -90, -dlat) + blats = numpy.arange(90, -90 - dlat, -dlat) + lons = numpy.arange(0 + dlon / 2., 360., dlon) + blons = numpy.arange(0, 360. + dlon, dlon) + + data = lats[:, numpy.newaxis] * lons[numpy.newaxis, :] + + data = (data + 1e10) / 750. + 233.2 + + ilat = cmor.axis( + table_entry='latitude', + coord_vals=lats, + cell_bounds=blats, + units='degrees_north') + ilon = cmor.axis( + table_entry='longitude', + coord_vals=lons, + cell_bounds=blons, + units='degrees_east') + + # ------------------------------------------ + # load Omon table and create masso variable + # ------------------------------------------ + ivar = cmor.variable( + table_entry="areacella", axis_ids=[ + ilat, ilon], units='m2') + + cmor.write(ivar, data) + self.delete_files += [cmor.close(ivar, True)] + cmor.close() if __name__ == '__main__': diff --git a/Test/test_python_CMIP6_CV_hierarchicalattr.py b/Test/test_python_CMIP6_CV_hierarchicalattr.py index 8a12fdf2..a488c3fa 100644 --- a/Test/test_python_CMIP6_CV_hierarchicalattr.py +++ b/Test/test_python_CMIP6_CV_hierarchicalattr.py @@ -34,34 +34,31 @@ def run(): class TestCase(base_CMIP6_CV.BaseCVsTest): def testCMIP6(self): - try: - cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) - cmor.dataset_json("Test/common_user_input_hier.json") + cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) + cmor.dataset_json("Test/common_user_input_hier.json") - cmor.load_table("CMIP6_Omon.json") - itime = cmor.axis(table_entry="time", units='months since 2010', coord_vals=numpy.array( - [0, 1, 2, 3, 4.]), cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) - ivar = cmor.variable( - table_entry="masso", - axis_ids=[itime], - units='kg') + cmor.load_table("CMIP6_Omon.json") + itime = cmor.axis(table_entry="time", units='months since 2010', coord_vals=numpy.array( + [0, 1, 2, 3, 4.]), cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) + ivar = cmor.variable( + table_entry="masso", + axis_ids=[itime], + units='kg') - data = numpy.random.random(5) - for i in range(0, 5): - # ,time_vals=numpy.array([i,]),time_bnds=numpy.array([i,i+1])) - cmor.write(ivar, data[i:i]) - self.delete_files += [cmor.close(ivar, True)] - cmor.close() + data = numpy.random.random(5) + for i in range(0, 5): + # ,time_vals=numpy.array([i,]),time_bnds=numpy.array([i,i+1])) + cmor.write(ivar, data[i:i]) + self.delete_files += [cmor.close(ivar, True)] + cmor.close() - f = cdms2.open(cmor.get_final_filename() , 'r') - self.assertEqual(f.coder, "Denis Nadeau") - self.assertEqual(f.hierarchical_attr_setting, "information") - self.assertEqual(f.creator, "PCMDI") - self.assertEqual(f.model, "Ocean Model") - self.assertEqual(f.country, "USA") - f.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") + f = cdms2.open(cmor.get_final_filename() , 'r') + self.assertEqual(f.coder, "Denis Nadeau") + self.assertEqual(f.hierarchical_attr_setting, "information") + self.assertEqual(f.creator, "PCMDI") + self.assertEqual(f.model, "Ocean Model") + self.assertEqual(f.country, "USA") + f.close() if __name__ == '__main__': run() diff --git a/Test/test_python_CMIP6_CV_invalidsourceid.py b/Test/test_python_CMIP6_CV_invalidsourceid.py index a9017a7c..beba3323 100644 --- a/Test/test_python_CMIP6_CV_invalidsourceid.py +++ b/Test/test_python_CMIP6_CV_invalidsourceid.py @@ -53,8 +53,6 @@ def testCMIP6(self): for i in range(0, 5): cmor.write(ivar, data[i:i]) cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV("invalid") diff --git a/Test/test_python_CMIP6_CV_longrealizationindex.py b/Test/test_python_CMIP6_CV_longrealizationindex.py index df735ed4..b9a5466e 100644 --- a/Test/test_python_CMIP6_CV_longrealizationindex.py +++ b/Test/test_python_CMIP6_CV_longrealizationindex.py @@ -55,10 +55,7 @@ def testCMIP6(self): for i in range(0, 1): cmor.write(ivar, data[i:i]) cmor.close() - - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") - except (KeyboardInterrupt, BaseException): + except BaseException: pass # ------------------------------------------ # Check error after signal handler is back diff --git a/Test/test_python_CMIP6_CV_nomipera.py b/Test/test_python_CMIP6_CV_nomipera.py index 5389eb76..1bd6471b 100644 --- a/Test/test_python_CMIP6_CV_nomipera.py +++ b/Test/test_python_CMIP6_CV_nomipera.py @@ -59,11 +59,8 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected error") except BaseException: pass - print("Assert") self.assertCV("mip_era") if __name__ == '__main__': diff --git a/Test/test_python_CMIP6_CV_parentsourceid.py b/Test/test_python_CMIP6_CV_parentsourceid.py index 7a676dec..aaff99ad 100644 --- a/Test/test_python_CMIP6_CV_parentsourceid.py +++ b/Test/test_python_CMIP6_CV_parentsourceid.py @@ -60,8 +60,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('OLD') diff --git a/Test/test_python_CMIP6_CV_parenttimeunits.py b/Test/test_python_CMIP6_CV_parenttimeunits.py index a1514e0b..63c2c58f 100644 --- a/Test/test_python_CMIP6_CV_parenttimeunits.py +++ b/Test/test_python_CMIP6_CV_parenttimeunits.py @@ -63,8 +63,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: raise self.assertCV('1980-01') diff --git a/Test/test_python_CMIP6_CV_parentvariantlabel.py b/Test/test_python_CMIP6_CV_parentvariantlabel.py index d41a942a..7d4d9cd7 100644 --- a/Test/test_python_CMIP6_CV_parentvariantlabel.py +++ b/Test/test_python_CMIP6_CV_parentvariantlabel.py @@ -61,8 +61,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('r11i123p4556') diff --git a/Test/test_python_CMIP6_CV_sub_experimentIDbad.py b/Test/test_python_CMIP6_CV_sub_experimentIDbad.py index 512d6837..e23572f6 100644 --- a/Test/test_python_CMIP6_CV_sub_experimentIDbad.py +++ b/Test/test_python_CMIP6_CV_sub_experimentIDbad.py @@ -61,8 +61,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('sub_experiment_id') diff --git a/Test/test_python_CMIP6_CV_sub_experiment_id.py b/Test/test_python_CMIP6_CV_sub_experiment_id.py index 0bb0a6a8..30428cc1 100644 --- a/Test/test_python_CMIP6_CV_sub_experiment_id.py +++ b/Test/test_python_CMIP6_CV_sub_experiment_id.py @@ -61,8 +61,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('sub_experiment_id') diff --git a/Test/test_python_CMIP6_CV_sub_experimentbad.py b/Test/test_python_CMIP6_CV_sub_experimentbad.py index cb98f905..2faa3a41 100644 --- a/Test/test_python_CMIP6_CV_sub_experimentbad.py +++ b/Test/test_python_CMIP6_CV_sub_experimentbad.py @@ -60,8 +60,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('iasdf', 'sub_experiment') diff --git a/Test/test_python_CMIP6_CV_sub_experimentnotset.py b/Test/test_python_CMIP6_CV_sub_experimentnotset.py index 79092788..9c31380c 100644 --- a/Test/test_python_CMIP6_CV_sub_experimentnotset.py +++ b/Test/test_python_CMIP6_CV_sub_experimentnotset.py @@ -62,8 +62,6 @@ def testCMIP6(self): cmor.write(ivar, data[i:i]) self.delete_files += [cmor.close(ivar, True)] cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") except BaseException: pass self.assertCV('none', 'sub_experiment') diff --git a/Test/test_python_CMIP6_CV_trackingNoprefix.py b/Test/test_python_CMIP6_CV_trackingNoprefix.py index b4ac3f22..704507a4 100644 --- a/Test/test_python_CMIP6_CV_trackingNoprefix.py +++ b/Test/test_python_CMIP6_CV_trackingNoprefix.py @@ -32,38 +32,32 @@ def run(): class TestCase(base_CMIP6_CV.BaseCVsTest): def testCMIP6(self): + # ------------------------------------------- + # Try to call cmor with a bad institution_ID + # ------------------------------------------- + cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) + cmor.dataset_json("Test/common_user_input.json") - try: - # ------------------------------------------- - # Try to call cmor with a bad institution_ID - # ------------------------------------------- - cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) - cmor.dataset_json("Test/common_user_input.json") + # ------------------------------------------ + # load Omon table and create masso variable + # ------------------------------------------ + cmor.load_table("CMIP6_Omon.json") + itime = cmor.axis(table_entry="time", units='months since 2010', + coord_vals=numpy.array([0, 1, 2, 3, 4.]), + cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) + ivar = cmor.variable( + table_entry="masso", + axis_ids=[itime], + units='kg') - # ------------------------------------------ - # load Omon table and create masso variable - # ------------------------------------------ - cmor.load_table("CMIP6_Omon.json") - itime = cmor.axis(table_entry="time", units='months since 2010', - coord_vals=numpy.array([0, 1, 2, 3, 4.]), - cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) - ivar = cmor.variable( - table_entry="masso", - axis_ids=[itime], - units='kg') - - data = numpy.random.random(5) - for i in range(0, 5): - cmor.write(ivar, data[i:i]) - self.delete_files += [cmor.close(ivar, True)] - filen = cmor.close() - f = cdms2.open(cmor.get_final_filename(), "r") - a = f.getglobal("tracking_id").split('/')[0] - self.assertNotIn("hdl:21.14100/", a) - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") - except BaseException: - raise + data = numpy.random.random(5) + for i in range(0, 5): + cmor.write(ivar, data[i:i]) + self.delete_files += [cmor.close(ivar, True)] + filen = cmor.close() + f = cdms2.open(cmor.get_final_filename(), "r") + a = f.getglobal("tracking_id").split('/')[0] + self.assertNotIn("hdl:21.14100/", a) if __name__ == '__main__': diff --git a/Test/test_python_CMIP6_CV_trackingprefix.py b/Test/test_python_CMIP6_CV_trackingprefix.py index e02e6815..4e2b44a5 100644 --- a/Test/test_python_CMIP6_CV_trackingprefix.py +++ b/Test/test_python_CMIP6_CV_trackingprefix.py @@ -32,35 +32,27 @@ def run(): class TestCase(base_CMIP6_CV.BaseCVsTest): def testCMIP6(self): - try: - # ------------------------------------------- - # Try to call cmor with a bad institution_ID - # ------------------------------------------- - cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) - cmor.dataset_json("Test/common_user_input.json") - cmor.set_cur_dataset_attribute("tracking_prefix", "hdl:21.14100") - - # ------------------------------------------ - # load Omon table and create masso variable - # ------------------------------------------ - cmor.load_table("CMIP6_Omon.json") - itime = cmor.axis(table_entry="time", units='months since 2011', - coord_vals=numpy.array([0, 1, 2, 3, 4.]), - cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) - ivar = cmor.variable( - table_entry="masso", - axis_ids=[itime], - units='kg') - - data = numpy.random.random(5) - for i in range(0, 5): - a = cmor.write(ivar, data[i:i]) - self.delete_files += [cmor.close(ivar, True)] - cmor.close() - except KeyboardInterrupt: - raise RuntimeError("Unexpected Error") - except BaseException: - raise + cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE, logfile=self.tmpfile) + cmor.dataset_json("Test/common_user_input.json") + cmor.set_cur_dataset_attribute("tracking_prefix", "hdl:21.14100") + + # ------------------------------------------ + # load Omon table and create masso variable + # ------------------------------------------ + cmor.load_table("CMIP6_Omon.json") + itime = cmor.axis(table_entry="time", units='months since 2011', + coord_vals=numpy.array([0, 1, 2, 3, 4.]), + cell_bounds=numpy.array([0, 1, 2, 3, 4, 5.])) + ivar = cmor.variable( + table_entry="masso", + axis_ids=[itime], + units='kg') + + data = numpy.random.random(5) + for i in range(0, 5): + a = cmor.write(ivar, data[i:i]) + self.delete_files += [cmor.close(ivar, True)] + cmor.close() f = cdms2.open(cmor.get_final_filename(), "r") a = f.getglobal("tracking_id").split('/')[0] self.assertIn("hdl:21.14100", a) From 0e1088a55fe61083bd654ef7b958061e3f4824b0 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Fri, 3 Aug 2018 11:05:17 -0700 Subject: [PATCH 3/4] get func takes no argument --- Src/cmor_cfortran_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/cmor_cfortran_interface.c b/Src/cmor_cfortran_interface.c index d30c43e3..923e1e81 100644 --- a/Src/cmor_cfortran_interface.c +++ b/Src/cmor_cfortran_interface.c @@ -377,7 +377,7 @@ void cmor_handle_error_cff_(char error_msg[CMOR_MAX_STRING], int *level) /* cmor_get_terminate_signal_cff_() */ /************************************************************************/ int cmor_get_terminate_signal_cff_() { - return cmor_get_terminate_signal(signal); + return cmor_get_terminate_signal(); } /************************************************************************/ From 449414d7b9c6d100f28ad0b4e1a010fc7b38a2fa Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Fri, 3 Aug 2018 12:14:28 -0700 Subject: [PATCH 4/4] correct types passed from fortran --- Src/cmor_cfortran_interface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/cmor_cfortran_interface.c b/Src/cmor_cfortran_interface.c index 923e1e81..c150729f 100644 --- a/Src/cmor_cfortran_interface.c +++ b/Src/cmor_cfortran_interface.c @@ -383,8 +383,8 @@ int cmor_get_terminate_signal_cff_() { /************************************************************************/ /* cmor_set_terminate_signal_cff() */ /************************************************************************/ -void cmor_set_terminate_signal_cff_(int signal) { - cmor_set_terminate_signal(signal); +void cmor_set_terminate_signal_cff_(int *signal) { + cmor_set_terminate_signal(*signal); } /************************************************************************/