Skip to content

Commit

Permalink
Remove duplicate tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Feb 27, 2025
1 parent 4541355 commit 3aeb79e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 4 deletions.
4 changes: 0 additions & 4 deletions cime_config/testdefs/testlist_clm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@
<test name="ERS_Ld396" grid="f10_f10_mg37" compset="I1850Clm60Bgc" testmods="clm/monthly_matrixcn_fast_spinup">
<machines>
<machine name="derecho" compiler="intel" category="aux_clm"/>
<machine name="derecho" compiler="intel" category="aux_clm"/>
</machines>
<options>
<option name="wallclock">01:20:00</option>
Expand Down Expand Up @@ -2960,7 +2959,6 @@
<test name="SMS_Ld5" grid="f10_f10_mg37" compset="I2000Clm45Fates" testmods="clm/FatesCold">
<machines>
<machine name="derecho" compiler="intel" category="aux_clm"/>
<machine name="derecho" compiler="intel" category="aux_clm"/>
</machines>
<options>
<option name="wallclock">00:40:00</option>
Expand All @@ -2970,7 +2968,6 @@
<test name="ERS_Ld30" grid="f45_f45_mg37" compset="I2000Clm50FatesRs" testmods="clm/FatesColdFixedBiogeo">
<machines>
<machine name="derecho" compiler="intel" category="aux_clm"/>
<machine name="derecho" compiler="intel" category="aux_clm"/>
</machines>
<options>
<option name="wallclock">00:40:00</option>
Expand All @@ -2980,7 +2977,6 @@
<test name="SMS_Ld5" grid="f10_f10_mg37" compset="I2000Clm50FatesRs" testmods="clm/FatesCold">
<machines>
<machine name="derecho" compiler="intel" category="aux_clm"/>
<machine name="derecho" compiler="intel" category="aux_clm"/>
</machines>
<options>
<option name="wallclock">00:40:00</option>
Expand Down
98 changes: 98 additions & 0 deletions tmp/move_izumi_tests.py
Original file line number Diff line number Diff line change
@@ -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 &quot; with "
pretty_xml = pretty_xml.replace("&quot;", '"')
# Replace this weirdness
pretty_xml = pretty_xml.replace('<?xml version="1.0" ?>', '')
# Fix indentation difference introduced by removal of duplicates
pretty_xml = pretty_xml.replace(" </machines>", " </machines>")
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)

0 comments on commit 3aeb79e

Please sign in to comment.