Skip to content

Commit de669c9

Browse files
committed
Revert some now-unneeded changes to testing scripts.
1 parent 131d93a commit de669c9

File tree

3 files changed

+61
-75
lines changed

3 files changed

+61
-75
lines changed

testing/run_functional_tests.py

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
from build_fortran_tests import build_tests, build_exists
3535
from functional_class_with_drivers import FunctionalTestWithDrivers
3636
from path_utils import add_cime_lib_to_path
37-
from utils import copy_file, config_to_dict, parse_test_list
38-
from utils import check_param_file, create_param_file, _DEFAULT_CDL_PATH
37+
from utils import copy_file, create_nc_from_cdl, config_to_dict, parse_test_list
3938

4039
# load the functional test classes
4140
from load_functional_tests import *
@@ -47,6 +46,14 @@
4746
# constants for this script
4847
_FILE_DIR = os.path.dirname(__file__)
4948
_DEFAULT_CONFIG_FILE = os.path.join(_FILE_DIR, "functional_tests.cfg")
49+
_DEFAULT_CDL_PATH = os.path.abspath(
50+
os.path.join(
51+
_FILE_DIR,
52+
os.pardir,
53+
"parameter_files",
54+
"fates_params_default.cdl",
55+
)
56+
)
5057
_CMAKE_BASE_DIR = os.path.join(_FILE_DIR, os.pardir)
5158
_TEST_SUB_DIR = "testing"
5259

@@ -196,6 +203,25 @@ def check_arg_validity(args):
196203
raise RuntimeError(f"config 'file' is a directory: '{args.config_file}'")
197204

198205

206+
def check_param_file(param_file):
207+
"""Checks to see if param_file exists and is of the correct form (.nc or .cdl)
208+
209+
Args:
210+
param_file (str): path to parameter file
211+
212+
Raises:
213+
argparse.ArgumentError: Parameter file is not of the correct form (.nc or .cdl)
214+
argparse.ArgumentError: Can't find parameter file
215+
"""
216+
file_suffix = os.path.basename(param_file).split(".")[-1]
217+
if not file_suffix in ["cdl", "nc"]:
218+
raise argparse.ArgumentError(
219+
None, "Must supply parameter file with .cdl or .nc ending."
220+
)
221+
if not os.path.isfile(param_file):
222+
raise FileNotFoundError(param_file)
223+
224+
199225
def check_build_dir(build_dir, test_dict):
200226
"""Checks to see if all required build directories and executables are present
201227
@@ -334,6 +360,37 @@ def make_plotdirs(run_dir, test_dict):
334360
os.mkdir(sub_dir)
335361

336362

363+
def create_param_file(param_file, run_dir):
364+
"""Creates and/or move the default or input parameter file to the run directory
365+
Creates a netcdf file from a cdl file if a cdl file is supplied
366+
367+
Args:
368+
param_file (str): path to parmaeter file
369+
run_dir (str): full path to run directory
370+
371+
Raises:
372+
RuntimeError: Supplied parameter file is not netcdf (.cd) or cdl (.cdl)
373+
374+
Returns:
375+
str: full path to new parameter file name/location
376+
"""
377+
if param_file is None:
378+
print("Using default parameter file.")
379+
param_file = _DEFAULT_CDL_PATH
380+
param_file_update = create_nc_from_cdl(param_file, run_dir)
381+
else:
382+
print(f"Using parameter file {param_file}.")
383+
file_suffix = os.path.basename(param_file).split(".")[-1]
384+
if file_suffix == "cdl":
385+
param_file_update = create_nc_from_cdl(param_file, run_dir)
386+
elif file_suffix == "nc":
387+
param_file_update = copy_file(param_file, run_dir)
388+
else:
389+
raise RuntimeError("Must supply parameter file with .cdl or .nc ending.")
390+
391+
return param_file_update
392+
393+
337394
def run_fortran_exectuables(build_dir, test_dir, test_exe, run_dir, args):
338395
"""Run the generated Fortran executables
339396

testing/run_unit_tests.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
1919
"""
2020
import os
21-
from shutil import copyfile
2221
import argparse
2322

2423
from build_fortran_tests import build_tests
@@ -27,9 +26,7 @@
2726

2827
add_cime_lib_to_path()
2928

30-
from CIME.utils import (
31-
run_cmd_no_fail,
32-
) # pylint: disable=wrong-import-position,import-error,wrong-import-order
29+
from CIME.utils import run_cmd_no_fail # pylint: disable=wrong-import-position,import-error,wrong-import-order
3330

3431
# constants for this script
3532
_FILE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -129,7 +126,6 @@ def run_unit_tests(clean, verbose_make, build_dir, make_j, test_dict):
129126

130127
test_dir = os.path.join(build_dir_path, _TEST_SUB_DIR, attributes["test_dir"])
131128
ctest_command = ["ctest", "--output-on-failure"]
132-
133129
output = run_cmd_no_fail(
134130
" ".join(ctest_command), from_dir=test_dir, combine_output=True
135131
)
@@ -146,11 +142,7 @@ def main():
146142
test_dict = parse_test_list(full_test_dict, args.test_list)
147143

148144
run_unit_tests(
149-
args.clean,
150-
args.verbose_make,
151-
args.build_dir,
152-
args.make_j,
153-
test_dict,
145+
args.clean, args.verbose_make, args.build_dir, args.make_j, test_dict
154146
)
155147

156148

testing/utils.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@
1414
run_cmd_no_fail,
1515
) # pylint: disable=wrong-import-position,import-error,wrong-import-order
1616

17-
# constants for this script
18-
_FILE_DIR = os.path.dirname(__file__)
19-
_DEFAULT_CDL_PATH = os.path.abspath(
20-
os.path.join(
21-
_FILE_DIR,
22-
os.pardir,
23-
"parameter_files",
24-
"fates_params_default.cdl",
25-
)
26-
)
27-
2817

2918
def round_up(num: float, decimals: int = 0) -> float:
3019
"""Rounds a number up
@@ -214,55 +203,3 @@ def str_to_list(val: str) -> list:
214203
return []
215204
res = val.strip("][").split(",")
216205
return [n.strip() for n in res]
217-
218-
219-
def check_param_file(param_file):
220-
"""Checks to see if param_file exists and is of the correct form (.nc or .cdl)
221-
222-
Args:
223-
param_file (str): path to parameter file
224-
225-
Raises:
226-
argparse.ArgumentError: Parameter file is not of the correct form (.nc or .cdl)
227-
argparse.ArgumentError: Can't find parameter file
228-
"""
229-
file_suffix = os.path.basename(param_file).split(".")[-1]
230-
if not file_suffix in ["cdl", "nc"]:
231-
raise argparse.ArgumentError(
232-
None, "Must supply parameter file with .cdl or .nc ending."
233-
)
234-
if not os.path.isfile(param_file):
235-
raise FileNotFoundError(param_file)
236-
237-
238-
def create_param_file(param_file, run_dir):
239-
"""Creates and/or move the default or input parameter file to the run directory
240-
Creates a netcdf file from a cdl file if a cdl file is supplied
241-
242-
Args:
243-
param_file (str): path to parmaeter file
244-
run_dir (str): full path to run directory
245-
246-
Raises:
247-
RuntimeError: Supplied parameter file is not netcdf (.cd) or cdl (.cdl)
248-
249-
Returns:
250-
str: full path to new parameter file name/location
251-
"""
252-
if param_file is None:
253-
print("Using default parameter file.")
254-
param_file = _DEFAULT_CDL_PATH
255-
param_file_update = create_nc_from_cdl(param_file, run_dir)
256-
else:
257-
print(f"Using parameter file {param_file}.")
258-
file_suffix = os.path.basename(param_file).split(".")[-1]
259-
if file_suffix == "cdl":
260-
param_file_update = create_nc_from_cdl(param_file, run_dir)
261-
elif file_suffix == "nc":
262-
param_file_update = copy_file(param_file, run_dir)
263-
else:
264-
raise RuntimeError("Must supply parameter file with .cdl or .nc ending.")
265-
266-
print(f"Parameter file saved to {os.path.abspath(param_file_update)}")
267-
268-
return param_file_update

0 commit comments

Comments
 (0)