def test_invalid_dummy_arg(self): """Test that invalid dummy argument statements are correctly detected """ #Setup scheme_files = [ os.path.join(self._sample_files_dir, "invalid_dummy_arg.meta") ] #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, self._run_env) #Verify correct error message returned self.assertTrue( "Invalid dummy argument, 'woohoo', at" in str(context.exception))
def test_missing_fortran_header(self): """Test that a missing fortran header is corretly detected """ #Setup scheme_files = [ os.path.join(self._sample_files_dir, "missing_fort_header.meta") ] #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, self._run_env) #Verify correct error message returned emsg = "No matching Fortran routine found for missing_fort_header_run in" self.assertTrue(emsg in str(context.exception))
def test_missing_metadata_header(self): """Test that a missing metadata header (aka arg table) is corretly detected """ #Setup scheme_files = [ os.path.join(self._sample_files_dir, "missing_arg_table.meta") ] #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, self._run_env) #Verify correct error message returned emsg = "No matching metadata header found for missing_arg_table_run in" self.assertTrue(emsg in str(context.exception))
def test_invalid_subr_stmnt(self): """Test that invalid Fortran subroutine statements are correctly detected """ #Setup scheme_files = [ os.path.join(self._sample_files_dir, "invalid_subr_stmnt.meta") ] preproc_defs = {} #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, preproc_defs, self._logger) #Verify correct error message returned self.assertTrue( "Invalid dummy argument, 'errmsg', at" in str(context.exception))
def test_CCPPeq1_var_missing_in_meta(self): """Test correct detection of a variable that IS PRESENT the subroutine argument list (due to a pre-processor directive: #ifdef CCPP), and IS NOT PRESENT in meta file""" #Setup scheme_files = [ os.path.join(self._sample_files_dir, "CCPPeq1_var_missing_in_meta.meta") ] #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, self._run_env_ccpp) #Verify 3 correct error messages returned self.assertTrue( 'Variable mismatch in CCPPeq1_var_missing_in_meta_finalize, variables missing from metadata header.' in str(context.exception)) self.assertTrue( 'Out of order argument, errmsg in CCPPeq1_var_missing_in_meta_finalize' in str(context.exception)) self.assertTrue( 'Out of order argument, errflg in CCPPeq1_var_missing_in_meta_finalize' in str(context.exception)) self.assertTrue('3 errors found comparing' in str(context.exception))
def test_CCPPgt1_var_in_fort_meta2(self): """Test correct detection of a variable that IS NOT PRESENT the subroutine argument list (due to a pre-processor directive: #if CCPP > 1), but IS PRESENT in meta file""" #Setup scheme_files = [ os.path.join(self._sample_files_dir, "CCPPgt1_var_in_fort_meta.meta") ] #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, self._run_env_ccpp) #Verify 3 correct error messages returned self.assertTrue( 'Variable mismatch in CCPPgt1_var_in_fort_meta_init, variables missing from Fortran scheme.' in str(context.exception)) self.assertTrue( 'Variable mismatch in CCPPgt1_var_in_fort_meta_init, no Fortran variable bar.' in str(context.exception)) self.assertTrue( 'Out of order argument, errmsg in CCPPgt1_var_in_fort_meta_init' in str(context.exception)) self.assertTrue('3 errors found comparing' in str(context.exception))
def test_CCPPeq1_var_missing_in_fort(self): """Test for correct detection of a variable that IS REMOVED the subroutine argument list (due to a pre-processor directive: #ifndef CCPP), but IS PRESENT in meta file""" #Setup scheme_files = [ os.path.join(self._sample_files_dir, "CCPPeq1_var_missing_in_fort.meta") ] preproc_defs = {'CCPP': 1} # Set CCPP directive #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, preproc_defs, self._logger) #Verify 3 correct error messages returned self.assertTrue( 'Variable mismatch in CCPPeq1_var_missing_in_fort_run, variables missing from Fortran scheme.' in str(context.exception)) self.assertTrue( 'Variable mismatch in CCPPeq1_var_missing_in_fort_run, no Fortran variable bar.' in str(context.exception)) self.assertTrue( 'Out of order argument, errmsg in CCPPeq1_var_missing_in_fort_run' in str(context.exception)) self.assertTrue('3 errors found comparing' in str(context.exception))
def test_CCPPnotset_var_missing_in_meta(self): """Test for correct detection of a variable that REMAINS in the subroutine argument list (due to an undefined pre-processor directive: #ifndef CCPP), BUT IS NOT PRESENT in meta file""" #Setup scheme_files = [ os.path.join(self._sample_files_dir, "CCPPnotset_var_missing_in_meta.meta") ] preproc_defs = {} # CCPP directive is not set #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, preproc_defs, self._logger) #Verify 3 correct error messages returned self.assertTrue( 'Variable mismatch in CCPPnotset_var_missing_in_meta_run, variables missing from metadata header.' in str(context.exception)) self.assertTrue( 'Out of order argument, errmsg in CCPPnotset_var_missing_in_meta_run' in str(context.exception)) self.assertTrue( 'Out of order argument, errflg in CCPPnotset_var_missing_in_meta_run' in str(context.exception)) self.assertTrue('3 errors found comparing' in str(context.exception))
def test_mismatch_intent(self): """Test that differing intent, kind, rank, and type between metadata and fortran is corretly detected """ #Setup scheme_files = [ os.path.join(self._sample_files_dir, "mismatch_intent.meta") ] #Exercise with self.assertRaises(Exception) as context: parse_scheme_files(scheme_files, self._run_env) #Verify 4 correct error messages returned self.assertTrue( 'intent mismatch (in != inout) in mismatch_intent_run, at' in str( context.exception)) self.assertTrue( 'kind mismatch (kind_fizz != kind_phys) in mismatch_intent_run, at' in str(context.exception)) self.assertTrue( 'rank mismatch in mismatch_intent_run/potential_temperature (0 != 1), at' in str(context.exception)) self.assertTrue( 'type mismatch (integer != real) in mismatch_intent_run, at' in str(context.exception)) self.assertTrue('4 errors found comparing' in str(context.exception))
def test_reordered_scheme_file(self): """Test that metadata file matches the Fortran when the routines are not in the same order """ #Setup scheme_files = [os.path.join(self._sample_files_dir, "reorder.meta")] #Exercise scheme_headers, table_dict = parse_scheme_files( scheme_files, self._run_env) #Verify size of returned list equals number of scheme headers in the test file # and that header (subroutine) names are 'reorder_[init,run,finalize]' self.assertEqual(len(scheme_headers), 3) #Verify header titles titles = [elem.title for elem in scheme_headers] self.assertTrue('reorder_init' in titles) self.assertTrue('reorder_run' in titles) self.assertTrue('reorder_finalize' in titles) #Verify size and name of table_dict matches scheme name self.assertEqual(len(table_dict), 1) self.assertTrue('reorder' in table_dict)
def test_good_scheme_file(self): """Test that good metadata file matches the Fortran, with routines in the same order """ #Setup scheme_files = [ os.path.join(self._sample_files_dir, "temp_adjust.meta") ] preproc_defs = {} #Exercise scheme_headers, table_dict = parse_scheme_files( scheme_files, preproc_defs, self._logger) #Verify size of returned list equals number of scheme headers in the test file # and that header (subroutine) names are 'temp_adjust_[init,run,finalize]' self.assertEqual(len(scheme_headers), 3) #Verify header titles titles = [elem.title for elem in scheme_headers] self.assertTrue('temp_adjust_init' in titles) self.assertTrue('temp_adjust_run' in titles) self.assertTrue('temp_adjust_finalize' in titles) #Verify size and name of table_dict matches scheme name self.assertEqual(len(table_dict), 1) self.assertTrue('temp_adjust' in table_dict)
def test_CCPPeq1_var_in_fort_meta(self): """Test positive case of a variable that IS PRESENT the subroutine argument list (due to a pre-processor directive: #ifdef CCPP), and IS PRESENT in meta file""" #Setup scheme_files = [ os.path.join(self._sample_files_dir, "CCPPeq1_var_in_fort_meta.meta") ] #Exercise scheme_headers, table_dict = parse_scheme_files( scheme_files, self._run_env_ccpp) #Verify size of returned list equals number of scheme headers in the test file (1) # and that header (subroutine) name is 'CCPPeq1_var_in_fort_meta_run' self.assertEqual(len(scheme_headers), 1) #Verify header titles titles = [elem.title for elem in scheme_headers] self.assertTrue('CCPPeq1_var_in_fort_meta_run' in titles) #Verify size and name of table_dict matches scheme name self.assertEqual(len(table_dict), 1) self.assertTrue('CCPPeq1_var_in_fort_meta' in table_dict)