From 5148e3c03089279302e142436c71912801e15881 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Mon, 4 Nov 2024 14:33:37 -0700 Subject: [PATCH] add xmllint test; flipflop order in phys_register --- src/physics/utils/phys_comp.F90 | 9 +- test/unit/sample_files/reg_bad_xml.xml | 110 +++++++++++++++++++++++++ test/unit/test_registry.py | 20 +++++ 3 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 test/unit/sample_files/reg_bad_xml.xml diff --git a/src/physics/utils/phys_comp.F90 b/src/physics/utils/phys_comp.F90 index 7fa4dba4..e01f6a1a 100644 --- a/src/physics/utils/phys_comp.F90 +++ b/src/physics/utils/phys_comp.F90 @@ -138,10 +138,6 @@ subroutine phys_register() ! Local variables integer :: i_group - call cam_ccpp_physics_register(phys_suite_name) - if (errcode /= 0) then - call endrun('cam_ccpp_physics_register: '//trim(errmsg)) - end if call ccpp_physics_suite_part_list(phys_suite_name, suite_parts, & errmsg, errcode) if (errcode /= 0) then @@ -156,6 +152,11 @@ subroutine phys_register() call endrun(errmsg) end if end do + ! Call CCPP register phase + call cam_ccpp_physics_register(phys_suite_name) + if (errcode /= 0) then + call endrun('cam_ccpp_physics_register: '//trim(errmsg)) + end if end subroutine phys_register diff --git a/test/unit/sample_files/reg_bad_xml.xml b/test/unit/sample_files/reg_bad_xml.xml new file mode 100644 index 00000000..da2d45a9 --- /dev/null +++ b/test/unit/sample_files/reg_bad_xml.xml @@ -0,0 +1,110 @@ + + + + + + + + + Number of horizontal columns + 0 + + + Number of vertical layers + 0 + + + 1 + + + 2 + + + horizontal_dimension + lat + + + horizontal_dimension + lon + + + horizontal_dimension vertical_layer_dimension + u_wind + + + horizontal_dimension vertical_layer_dimension + v_wind + + + 42 + + + stand_var + + + Composition-dependent ratio of dry air gas constant to specific heat at constant pressure + horizontal_dimension vertical_layer_dimension + 1 + rair/cpair - rair * 2 + + + horizontal_dimension vertical_layer_dimension + number_of_constituents + + Q Q_snapshot + + + CLDLIQ CLDLIQ_snapshot + + + + horizontal_dimension + vertical_layer_dimension + + + x_wind + y_wind + + + + latitude + longitude + model_wind + constituent_mixing_ratio + + + Physics state variables updated by dynamical core + + + $SRCROOT/test/unit/sample_files/ref_pres.meta + diff --git a/test/unit/test_registry.py b/test/unit/test_registry.py index 98d0a232..0b6bb6c6 100644 --- a/test/unit/test_registry.py +++ b/test/unit/test_registry.py @@ -42,6 +42,7 @@ from generate_registry_data import gen_registry from generate_registry_data import metadata_file_to_files, TypeRegistry from framework_env import CCPPFrameworkEnv +from parse_source import CCPPError # pylint: enable=wrong-import-position ############################################################################### @@ -116,6 +117,25 @@ def test_good_simple_registry(self): self.assertTrue(filecmp.cmp(out_source, in_source, shallow=False), msg=amsg) + def test_bad_registry_xml(self): + """Test that the full error messages from xmllint is returned""" + # Setup test + filename = os.path.join(_SAMPLE_FILES_DIR, "reg_bad_xml.xml") + out_name = "physics_types_bad" + # Try to generate the registry + with self.assertRaises(CCPPError) as cerr: + retcode, files, _ = gen_registry(filename, 'se', _TMP_DIR, 2, + _SRC_MOD_DIR, _CAM_ROOT, + loglevel=logging.ERROR, + error_on_no_validate=True) + # end with + expected_error = "reg_bad_xml.xml:32: element ic_file_input_name: Schemas validity error : Element 'ic_file_input_name': This element is not expected. Expected is one of ( initial_value, ic_file_input_names )." + split_exception = str(cerr.exception).split('\n') + amsg = f"Test failure: exception raised is {len(split_exception)} lines long and is expected to be 4" + self.assertEqual(len(split_exception), 4, msg=amsg) + # Check that the full xmllint message was returned + self.assertTrue(split_exception[2].endswith(expected_error)) + def test_good_ddt_registry(self): """Test code and metadata generation from a good registry with a DDT. Check that generate_registry_data.py generates good