Skip to content

Commit

Permalink
Merge pull request #4718 from jedwards4b/skip_evv4esm_tests
Browse files Browse the repository at this point in the history
skip tests using evv4esm if not available
  • Loading branch information
jedwards4b authored Dec 16, 2024
2 parents 7c0ca7d + 67f2e08 commit 3967c7f
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 151 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ jobs:
timeout-minutes: 2
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
- name: Runs pre-commit
run: |
pip install pre-commit
pre-commit run -a
# Runs unit testing under different python versions.
Expand All @@ -98,11 +97,12 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ["3.8", "3.10", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run tests
shell: bash
env:
Expand Down
38 changes: 18 additions & 20 deletions CIME/compare_namelists.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os, re, logging

from collections import OrderedDict
from CIME.utils import expect, CIMEError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -73,11 +71,11 @@ def _interpret_value(value_str, filename):
>>> _interpret_value("3*1.0", "foo")
['1.0', '1.0', '1.0']
>>> _interpret_value("'DMS -> value.nc'", "foo")
OrderedDict([('DMS', 'value.nc')])
{'DMS': 'value.nc'}
>>> _interpret_value("'DMS -> 1.0 * value.nc'", "foo")
OrderedDict([('DMS', '1.0*value.nc')])
{'DMS': '1.0*value.nc'}
>>> _interpret_value("'DMS -> 1.0* value.nc'", "foo")
OrderedDict([('DMS', '1.0*value.nc')])
{'DMS': '1.0*value.nc'}
"""
comma_re = re.compile(r"\s*,\s*")
dict_re = re.compile(r"^'(\S+)\s*->\s*(\S+|(?:\S+\s*\*\s*\S+))\s*'")
Expand All @@ -87,7 +85,7 @@ def _interpret_value(value_str, filename):
tokens = [item.strip() for item in comma_re.split(value_str) if item.strip() != ""]
if "->" in value_str:
# dict
rv = OrderedDict()
rv = {}
for token in tokens:
m = dict_re.match(token)
expect(
Expand Down Expand Up @@ -151,15 +149,15 @@ def _parse_namelists(namelist_lines, filename):
... /
... '''
>>> _parse_namelists(teststr.splitlines(), 'foo')
OrderedDict([('nml', OrderedDict([('val', "'foo'"), ('aval', ["'one'", "'two'", "'three'"]), ('maval', ["'one'", "'two'", "'three'", "'four'"]), ('dval', OrderedDict([('one', 'two'), ('three', 'four')])), ('mdval', OrderedDict([('one', 'two'), ('three', 'four'), ('five', 'six')])), ('nval', '1850')])), ('nml2', OrderedDict([('val2', '.false.')]))])
{'nml': {'val': "'foo'", 'aval': ["'one'", "'two'", "'three'"], 'maval': ["'one'", "'two'", "'three'", "'four'"], 'dval': {'one': 'two', 'three': 'four'}, 'mdval': {'one': 'two', 'three': 'four', 'five': 'six'}, 'nval': '1850'}, 'nml2': {'val2': '.false.'}}
>>> teststr = '''&fire_emis_nl
... fire_emis_factors_file = 'fire_emis_factors_c140116.nc'
... fire_emis_specifier = 'bc_a1 = BC', 'pom_a1 = 1.4*OC', 'pom_a2 = A*B*C', 'SO2 = SO2'
... /
... '''
>>> _parse_namelists(teststr.splitlines(), 'foo')
OrderedDict([('fire_emis_nl', OrderedDict([('fire_emis_factors_file', "'fire_emis_factors_c140116.nc'"), ('fire_emis_specifier', ["'bc_a1 = BC'", "'pom_a1 = 1.4*OC'", "'pom_a2 = A*B*C'", "'SO2 = SO2'"])]))])
{'fire_emis_nl': {'fire_emis_factors_file': "'fire_emis_factors_c140116.nc'", 'fire_emis_specifier': ["'bc_a1 = BC'", "'pom_a1 = 1.4*OC'", "'pom_a2 = A*B*C'", "'SO2 = SO2'"]}}
>>> _parse_namelists('blah', 'foo') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
Expand Down Expand Up @@ -196,27 +194,27 @@ def _parse_namelists(namelist_lines, filename):
... val = 2, 2*13
... /'''
>>> _parse_namelists(teststr.splitlines(), 'foo')
OrderedDict([('nml', OrderedDict([('val', ['2', '13', '13'])]))])
{'nml': {'val': ['2', '13', '13']}}
>>> teststr = '''&nml
... val = 2 2 3
... /'''
>>> _parse_namelists(teststr.splitlines(), 'foo')
OrderedDict([('nml', OrderedDict([('val', ['2', '2', '3'])]))])
{'nml': {'val': ['2', '2', '3']}}
>>> teststr = '''&nml
... val = 'a brown cow' 'a red hen'
... /'''
>>> _parse_namelists(teststr.splitlines(), 'foo')
OrderedDict([('nml', OrderedDict([('val', ["'a brown cow'", "'a red hen'"])]))])
{'nml': {'val': ["'a brown cow'", "'a red hen'"]}}
"""

comment_re = re.compile(r"^[#!]")
namelist_re = re.compile(r"^&(\S+)$")
name_re = re.compile(r"^([^\s=']+)\s*=\s*(.+)$")
rcline_re = re.compile(r"^([^&\s':]+)\s*:\s*(.+)$")

rv = OrderedDict()
rv = {}
current_namelist = None
multiline_variable = None # (name, value)
for line in namelist_lines:
Expand All @@ -238,7 +236,7 @@ def _parse_namelists(namelist_lines, filename):
logger.debug(" Parsing variable '{}' with data '{}'".format(name, value))

if "seq_maps.rc" not in rv:
rv["seq_maps.rc"] = OrderedDict()
rv["seq_maps.rc"] = {}

expect(
name not in rv["seq_maps.rc"],
Expand All @@ -261,7 +259,7 @@ def _parse_namelists(namelist_lines, filename):
# to signify this event
if namelist_re.match(line) is None:
expect(
rv != OrderedDict(),
rv != {},
"File '{}' does not appear to be a namelist file, skipping".format(
filename
),
Expand All @@ -281,7 +279,7 @@ def _parse_namelists(namelist_lines, filename):
),
)

rv[current_namelist] = OrderedDict()
rv[current_namelist] = {}

logger.debug(" Starting namelist '{}'".format(current_namelist))

Expand Down Expand Up @@ -342,17 +340,17 @@ def _parse_namelists(namelist_lines, filename):
real_value = _interpret_value(line, filename)
if type(current_value) is list:
expect(
type(real_value) is not OrderedDict,
type(real_value) is not dict,
"In file '{}', multiline list variable '{}' had dict entries".format(
filename, multiline_variable[0]
),
)
real_value = real_value if type(real_value) is list else [real_value]
current_value.extend(real_value)

elif type(current_value) is OrderedDict:
elif type(current_value) is dict:
expect(
type(real_value) is OrderedDict,
type(real_value) is dict,
"In file '{}', multiline dict variable '{}' had non-dict entries".format(
filename, multiline_variable[0]
),
Expand Down Expand Up @@ -459,7 +457,7 @@ def _compare_values(name, gold_value, comp_value, case):
name, comp_value_list_item
)

elif type(gold_value) is OrderedDict:
elif type(gold_value) is dict:
for key, gold_value_dict_item in gold_value.items():
if key in comp_value:
comments += _compare_values(
Expand Down Expand Up @@ -639,7 +637,7 @@ def _compare_namelists(gold_namelists, comp_namelists, case):
COMP: csw_specifier dict item DMS = 1.0*other.nc
<BLANKLINE>
"""
different_namelists = OrderedDict()
different_namelists = {}
for namelist, gold_names in gold_namelists.items():
if namelist not in comp_namelists:
different_namelists[namelist] = ["Missing namelist: {}\n".format(namelist)]
Expand Down
Loading

0 comments on commit 3967c7f

Please sign in to comment.