@@ -85,7 +85,9 @@ def setUpClass(cls):
85
85
def test_good_simple_registry (self ):
86
86
"""Test that a good registry with only variables validates.
87
87
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"""
89
91
# Setup test
90
92
filename = os .path .join (_SAMPLE_FILES_DIR , "reg_good_simple.xml" )
91
93
out_source_name = "physics_types_simple"
@@ -607,6 +609,56 @@ def test_bad_registry_version(self):
607
609
self .assertFalse (os .path .exists (out_meta ))
608
610
self .assertFalse (os .path .exists (out_source ))
609
611
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
+
610
662
def test_missing_standard_name (self ):
611
663
"""Test a registry with a missing standard name.
612
664
Check that it does not validate and does not generate any
0 commit comments