Skip to content

Commit 8662bd9

Browse files
committed
Merge remote-tracking branch 'upstream/development' into cam_sima_dme
2 parents beed3fc + 4ca1f31 commit 8662bd9

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

test/unit/python/sample_files/reg_good_simple.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
units="count" type="integer" access="protected">
88
<long_name>Number of horizontal columns</long_name>
99
<initial_value>0</initial_value>
10-
<initial_value dyn="SE,FV">1</initial_value>
10+
<initial_value dyn="SE">1</initial_value>
1111
</variable>
1212
<variable local_name="latitude" standard_name="latitude"
1313
units="radians" type="real" kind="kind_phys"

test/unit/python/test_registry.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def setUpClass(cls):
8585
def test_good_simple_registry(self):
8686
"""Test that a good registry with only variables validates.
8787
Check that generate_registry_data.py generates good
88-
Fortran and metadata files"""
88+
Fortran and metadata files. Expectation is that the initial
89+
value for ncol will be set to the default of 0 because there is no
90+
dycore match"""
8991
# Setup test
9092
filename = os.path.join(_SAMPLE_FILES_DIR, "reg_good_simple.xml")
9193
out_source_name = "physics_types_simple"
@@ -607,6 +609,56 @@ def test_bad_registry_version(self):
607609
self.assertFalse(os.path.exists(out_meta))
608610
self.assertFalse(os.path.exists(out_source))
609611

612+
def test_registry_no_clear_initial_value(self):
613+
"""
614+
Check that generate_registry_data.py throws the correct
615+
error message when there is no clear "winner"
616+
between the initial_value entries
617+
"""
618+
619+
# Setup test
620+
infilename = os.path.join(_SAMPLE_FILES_DIR, "reg_good_simple.xml")
621+
tree, root = read_xml_file(infilename)
622+
623+
# Open base XML file:
624+
base_tree = ET.parse(infilename)
625+
base_root = base_tree.getroot()
626+
627+
# Write new namelist entry with "bad" value:
628+
initial_value_tie_string = \
629+
"""
630+
<variable local_name="myvar" standard_name="variable_with_unclear_initial_value"
631+
units="count" type="integer" access="protected">
632+
<long_name>Number of horizontal columns</long_name>
633+
<initial_value>2</initial_value>
634+
<initial_value dyn="SE">0</initial_value>
635+
<initial_value dyn="SE">1</initial_value>
636+
</variable>
637+
"""
638+
639+
initial_value_tie_entry = ET.fromstring(initial_value_tie_string)
640+
641+
# Add new namelist entry back to original namelist XML tree:
642+
base_root[0].append(initial_value_tie_entry)
643+
644+
# Write out new, temporary XML namelist file for testing:
645+
xml_test_fil = os.path.join(_TMP_DIR, "test_registry_initial_value_tie.xml")
646+
base_tree.write(xml_test_fil, encoding="utf-8", xml_declaration=True)
647+
filename = os.path.join(_TMP_DIR, "test_registry_initial_value_tie.xml")
648+
649+
# Attempt to generate registry:
650+
with self.assertRaises(CCPPError) as cerr:
651+
retcode, files, _ = gen_registry(filename, 'se', _TMP_DIR, 2,
652+
_SRC_MOD_DIR, _CAM_ROOT,
653+
loglevel=logging.ERROR,
654+
error_on_no_validate=True)
655+
656+
# Check exception message
657+
emsg = "Unclear which initial_value to use for myvar. "
658+
emsg += "There are at least two configurations with 1 matching attributes"
659+
660+
self.assertEqual(emsg, str(cerr.exception))
661+
610662
def test_missing_standard_name(self):
611663
"""Test a registry with a missing standard name.
612664
Check that it does not validate and does not generate any

0 commit comments

Comments
 (0)