Skip to content

Commit

Permalink
add xmllint test; flipflop order in phys_register
Browse files Browse the repository at this point in the history
  • Loading branch information
peverwhee committed Nov 4, 2024
1 parent ea4a886 commit 5148e3c
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/physics/utils/phys_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
110 changes: 110 additions & 0 deletions test/unit/sample_files/reg_bad_xml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>

<registry name="cam_registry" version="1.0">
<file name="physics_types_complete" type="module">
<use module="ccpp_kinds" reference="kind_phys"/>
<use module="physconst" reference="rair"/>
<use module="physconst" reference="cpair"/>
<variable local_name="ncol" standard_name="horizontal_dimension"
units="count" type="integer" access="protected">
<long_name>Number of horizontal columns</long_name>
<initial_value>0</initial_value>
</variable>
<variable local_name="pver" standard_name="vertical_layer_dimension"
units="count" type="integer" access="protected">
<long_name>Number of vertical layers</long_name>
<initial_value>0</initial_value>
</variable>
<variable local_name="ix_qv"
standard_name="index_of_water_vapor_specific_humidity"
units="count" type="integer">
<initial_value>1</initial_value>
</variable>
<variable local_name="ix_cld_liq"
standard_name="index_of_cloud_liquid_water_mixing_ratio_of_moist_air"
units="count" type="integer">
<initial_value>2</initial_value>
</variable>
<variable local_name="latitude" standard_name="latitude"
units="radians" type="real" kind="kind_phys"
allocatable="pointer" access="protected">
<dimensions>horizontal_dimension</dimensions>
<ic_file_input_name>lat</ic_file_input_name>
</variable>
<variable local_name="longitude" standard_name="longitude"
units="radians" type="real" kind="kind_phys"
allocatable="pointer" access="protected">
<dimensions>horizontal_dimension</dimensions>
<ic_file_input_names>lon</ic_file_input_names>
</variable>
<variable local_name="u" standard_name="x_wind"
units="m s-1" type="real" kind="kind_phys"
allocatable="pointer" access="protected">
<dimensions>horizontal_dimension vertical_layer_dimension</dimensions>
<ic_file_input_names>u_wind</ic_file_input_names>
</variable>
<variable local_name="v" standard_name="y_wind"
units="m s-1" type="real" kind="kind_phys"
allocatable="pointer" access="protected">
<dimensions>horizontal_dimension vertical_layer_dimension</dimensions>
<ic_file_input_names>v_wind</ic_file_input_names>
</variable>
<variable local_name="param_val_var"
standard_name="made_up_param_variable"
units="count" type="integer" allocatable="parameter">
<initial_value>42</initial_value>
</variable>
<variable local_name="standard_var"
standard_name="standard_non_ddt_variable"
units="K" type="real" phys_timestep_init_zero="true">
<ic_file_input_names>stand_var</ic_file_input_names>
</variable>
<variable local_name="cappav"
standard_name="composition_dependent_ratio_of_dry_air_gas_constant_to_specific_heat_at_constant_pressure"
units="1" type="real" kind="kind_phys"
allocatable="allocatable">
<long_name>Composition-dependent ratio of dry air gas constant to specific heat at constant pressure</long_name>
<dimensions>horizontal_dimension vertical_layer_dimension</dimensions>
<initial_value>1 + rair/cpair - rair * 2</initial_value>
</variable>
<array local_name="q" standard_name="constituent_mixing_ratio"
units="kg kg-1"
type="real" kind="kind_phys"
allocatable="pointer">
<dimensions>horizontal_dimension vertical_layer_dimension
number_of_constituents</dimensions>
<element standard_name="water_vapor_specific_humidity"
index_name="index_of_water_vapor_specific_humidity"
index_pos="number_of_constituents">
<ic_file_input_names>Q Q_snapshot</ic_file_input_names>
</element>
<element standard_name="cloud_liquid_water_mixing_ratio_of_moist_air"
index_name="index_of_cloud_liquid_water_mixing_ratio_of_moist_air"
index_pos="number_of_constituents">
<ic_file_input_names>CLDLIQ CLDLIQ_snapshot</ic_file_input_names>
</element>
</array>
<ddt type="physics_base" bindC="true">
<data>horizontal_dimension</data>
<data>vertical_layer_dimension</data>
</ddt>
<ddt type="model_wind">
<data>x_wind</data>
<data>y_wind</data>
</ddt>
<variable local_name="wind" standard_name="model_wind"
units="None" type="model_wind" />
<ddt type="physics_state" extends="physics_base">
<data>latitude</data>
<data>longitude</data>
<data>model_wind</data>
<data>constituent_mixing_ratio</data>
</ddt>
<variable local_name="phys_state"
standard_name="physics_state_due_to_dynamics"
units="None" type="physics_state" phys_timestep_init_zero="true">
<long_name>Physics state variables updated by dynamical core</long_name>
</variable>
</file>
<metadata_file>$SRCROOT/test/unit/sample_files/ref_pres.meta</metadata_file>
</registry>
20 changes: 20 additions & 0 deletions test/unit/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

###############################################################################
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5148e3c

Please sign in to comment.