Skip to content

Commit

Permalink
Remove test_dataset.py and move test_run.py to unit tests dir
Browse files Browse the repository at this point in the history
- Remove `print_statements = True` in `all_sets.cfg` because test log output gets polluted
  • Loading branch information
tomvothecoder committed Dec 13, 2023
1 parent 5eaf7b3 commit 9f1862a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 220 deletions.
11 changes: 10 additions & 1 deletion e3sm_diags/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def __init__(self):
# The list of sets to run using parameter objects.
self.sets_to_run = []

# The path to the user-specified `.cfg` file using `-d/--diags` or
# the default diagnostics `.cfg` file.
self.cfg_path = None

@property
def is_cfg_file_arg_set(self):
"""A property to check if `-d/--diags` was set to a `.cfg` filepath.
Expand All @@ -35,8 +39,11 @@ def is_cfg_file_arg_set(self):
True if list contains more than one path, else False.
"""
args = self.parser.view_args()
self.cfg_path = args.other_parameters

is_set = len(self.cfg_path) > 0

return len(args.other_parameters) > 0
return is_set

def run_diags(
self, parameters: List[CoreParameter], use_cfg: bool = True
Expand Down Expand Up @@ -233,6 +240,8 @@ def _get_default_params_from_cfg_file(self, run_type: str) -> List[CoreParameter
path = get_default_diags_path(set_name, run_type, False)
paths.append(path)

self.cfg_path = paths

# Convert the .cfg file(s) to parameter objects.
params = self.parser.get_cfg_parameters(
files_to_open=paths, argparse_vals_only=False
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ junit_family = "xunit2"
addopts = "--cov=e3sm_diags --cov-report term --cov-report html:tests_coverage_reports/htmlcov --cov-report xml:tests_coverage_reports/coverage.xml -s"
python_files = ["tests.py", "test_*.py"]
# Only run the unit tests because integration tests take a long time.
# Integration tests can be executed manually with `test.sh` or `pytest tests/integration`.
testpaths = "tests/e3sm_diags"

[tool.mypy]
Expand Down
14 changes: 8 additions & 6 deletions tests/integration/test_run.py → tests/e3sm_diags/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_all_sets_and_all_seasons(self):
]

parameters = self.runner.get_run_parameters(
[self.core_param, ts_param, enso_param, streamflow_param]
[self.core_param, ts_param, enso_param, streamflow_param], use_cfg=True
)
# Counts the number of each set and each seasons to run the diags on.
set_counter, season_counter = (
Expand All @@ -88,12 +88,14 @@ def test_all_sets_and_all_seasons(self):
# So, reduce the ANN count by the number of times these appear
season_counter["ANN"] -= set_counter["enso_diags"]
season_counter["ANN"] -= set_counter["streamflow"]
if not all(season_counter["ANN"] == count for count in season_counter.values()):
self.fail(
"In .cfg files, at least one season does not match the count for ANN: {}".format(
season_counter

for season, count in season_counter.items():
if count != season_counter["ANN"]:
self.fail(
"In .cfg files, at least one season does not match the count for ANN: {}".format(
season_counter
)
)
)

def test_zonal_mean_2d(self):
# Running zonal_mean_2d with the core param only.
Expand Down
15 changes: 0 additions & 15 deletions tests/integration/all_sets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test_file = "T_20161118.beta0.FC5COSP.ne30_ne30.edison_ANN_climo.nc"
results_dir = "tests/integration/all_sets_results_test"
debug = True


[zonal_mean_2d]
sets = ["zonal_mean_2d"]
case_id = "ERA-Interim"
Expand All @@ -38,7 +37,6 @@ test_file = "T_20161118.beta0.FC5COSP.ne30_ne30.edison_ANN_climo.nc"
results_dir = "tests/integration/all_sets_results_test"
debug = True


[meridional_mean_2d]
sets = ["meridional_mean_2d"]
case_id = "ERA-Interim"
Expand All @@ -59,7 +57,6 @@ test_file = "T_20161118.beta0.FC5COSP.ne30_ne30.edison_ANN_climo.nc"
results_dir = "tests/integration/all_sets_results_test"
debug = True


[lat_lon]
sets = ["lat_lon"]
case_id = "ERA-Interim"
Expand All @@ -82,8 +79,6 @@ results_dir = "tests/integration/all_sets_results_test"
debug = True
regions=["CONUS_RRM","global"]



[polar]
sets = ["polar"]
case_id = "ERA-Interim"
Expand All @@ -106,7 +101,6 @@ test_file = "T_20161118.beta0.FC5COSP.ne30_ne30.edison_ANN_climo.nc"
results_dir = "tests/integration/all_sets_results_test"
debug = True


[cosp_histogram]
sets = ["cosp_histogram"]
case_id = "MISR-COSP"
Expand All @@ -127,7 +121,6 @@ test_file = "CLD_MISR_20161118.beta0.FC5COSP.ne30_ne30.edison_ANN_climo.nc"
results_dir = "tests/integration/all_sets_results_test"
debug = True


[area_mean_time_series]
sets = ["area_mean_time_series"]
variables = ["TREFHT"]
Expand Down Expand Up @@ -158,7 +151,6 @@ reference_data_path = 'tests/integration/integration_test_data'
ref_file = 'TREFHT_201201_201312.nc'
test_name = "system tests"
variables = ["TREFHT"]
print_statements = True

[#]
sets = ["enso_diags"]
Expand All @@ -177,7 +169,6 @@ reference_data_path = 'tests/integration/integration_test_data'
ref_file = 'TREFHT_201201_201312.nc'
test_name = "system tests"
variables = ["TREFHT"]
print_statements = True

[#]
sets = ["enso_diags"]
Expand All @@ -197,7 +188,6 @@ reference_data_path = 'tests/integration/integration_test_data'
ref_file = 'TREFHT_201201_201312.nc'
test_name = "system tests"
variables = ["TREFHT"]
print_statements = True

[#]
sets = ["enso_diags"]
Expand All @@ -214,7 +204,6 @@ reference_data_path = 'tests/integration/integration_test_data'
ref_file = 'TREFHT_201201_201312.nc'
test_name = "system tests"
variables = ["TREFHT"]
print_statements = True

[#]
sets = ["enso_diags"]
Expand All @@ -232,7 +221,6 @@ reference_data_path = 'tests/integration/integration_test_data'
ref_file = 'TREFHT_201201_201312.nc'
test_name = "system tests"
variables = ["TREFHT"]
print_statements = True

[#]
sets = ["enso_diags"]
Expand All @@ -251,7 +239,6 @@ reference_data_path = 'tests/integration/integration_test_data'
ref_file = 'TREFHT_201201_201312.nc'
test_name = "system tests"
variables = ["TREFHT"]
print_statements = True

[qbo]
sets = ["qbo"]
Expand Down Expand Up @@ -283,7 +270,6 @@ test_start_yr = '1959'
test_end_yr = '1961'
results_dir = "tests/integration/all_sets_results_test"
test_name = "system tests"
print_statements = True

[diurnal_cycle]
sets = ["diurnal_cycle"]
Expand All @@ -304,7 +290,6 @@ test_file = "20180215.DECKv1b_H1.ne30_oEC.edison.cam.h4_JJA_200006_200908_climo.
results_dir = "tests/integration/all_sets_results_test"
debug = True


[arm_diags1]
sets = ["arm_diags"]
diags_set = "annual_cycle"
Expand Down
198 changes: 0 additions & 198 deletions tests/integration/test_dataset.py

This file was deleted.

0 comments on commit 9f1862a

Please sign in to comment.