diff --git a/cime_config/testdefs/testlist_clm.xml b/cime_config/testdefs/testlist_clm.xml index 490ab6ba19..95b4c09089 100644 --- a/cime_config/testdefs/testlist_clm.xml +++ b/cime_config/testdefs/testlist_clm.xml @@ -867,7 +867,6 @@ - @@ -2960,7 +2959,6 @@ - @@ -2970,7 +2968,6 @@ - @@ -2980,7 +2977,6 @@ - diff --git a/tmp/move_izumi_tests.py b/tmp/move_izumi_tests.py new file mode 100644 index 0000000000..4f7edc29d4 --- /dev/null +++ b/tmp/move_izumi_tests.py @@ -0,0 +1,98 @@ +# %% +import xml.etree.ElementTree as ET +from xml.dom import minidom + +# Read the input file and preserve the stuff at the top +def get_front_matter(input_file): + with open(input_file, 'r', encoding='utf-8') as f: + lines = f.readlines() + front_matter = [] + for line in lines: + front_matter.append(line) + if line.strip().startswith("-->"): + break + return front_matter + +# Parse the input XML file and preserve comments +def parse_xml(input_file): + parser = ET.XMLParser(target=ET.TreeBuilder(insert_comments=True)) + tree = ET.parse(input_file, parser=parser) + return tree + +# Write the preserved comments and parsed XML tree to the output file +def write_xml(tree, f): + rough_string = ET.tostring(tree.getroot(), 'utf-8') + reparsed = minidom.parseString(rough_string) + pretty_xml = reparsed.toprettyxml(indent="", newl="") + # Replace " with " + pretty_xml = pretty_xml.replace(""", '"') + # Replace this weirdness + pretty_xml = pretty_xml.replace('', '') + # Fix indentation difference introduced by removal of duplicates + pretty_xml = pretty_xml.replace(" ", " ") + f.write(pretty_xml) + +# Print all the information associated with one test request +def print_test_info(test): + print("Tests:") + for machine in test.find('machines').findall('machine'): + this_str = " " + " ".join([machine.get('name'), machine.get('compiler'), machine.get('category')]) + print(this_str) + +# Print all the information associated with each test +def print_tests_info(tree): + root = tree.getroot() + for test in root.findall('test'): + print(f"Test name: {test.get('name')}") + print(f"Grid: {test.get('grid')}") + print(f"Compset: {test.get('compset')}") + print(f"Testmods: {test.get('testmods')}") + print_test_info(test) + print("Options:") + if test.find('options') is None: + continue + for option in test.find('options').findall('option'): + print(f" {option.get('name')}: {option.text}") + print() + return + +# Identify and remove duplicate machines +def remove_duplicate_machines(tree): + root = tree.getroot() + for test in root.findall('test'): + machines = test.find('machines') + seen = set() + duplicates = [] + for machine in machines.findall('machine'): + machine_tuple = (machine.get('name'), machine.get('compiler'), machine.get('category')) + if machine_tuple in seen: + duplicates.append(machine) + else: + seen.add(machine_tuple) + for duplicate in duplicates: + machines.remove(duplicate) + + return tree + +# Define the input and output file paths +input_file = "cime_config/testdefs/testlist_clm.xml" +# output_file = "test.xml" +output_file = input_file + +# Read the input file and preserve the stuff at the top +front_matter = get_front_matter(input_file) + +# Parse the input XML file +tree = parse_xml(input_file) + +# Remove duplicate machines +tree = remove_duplicate_machines(tree) + +# # Print all the information associated with each test +# print_tests_info(tree) + +# Write +with open(output_file, 'w', encoding='utf-8') as f: + f.writelines(front_matter) +with open(output_file, 'a', encoding='utf-8') as f: + write_xml(tree, f) \ No newline at end of file