Skip to content

Commit 9bb754d

Browse files
committed
Automate zppy tests
1 parent dadaadc commit 9bb754d

File tree

3 files changed

+122
-9
lines changed

3 files changed

+122
-9
lines changed

tests/integration/generated/test_complete_run_chrysalis.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ years = "1850:1854:2", "1850:1854:4",
9393
walltime = "5:00:00"
9494

9595
[[ atm_monthly_180x360_aave_environment_commands ]]
96-
environment_commands = "source /home/ac.forsyth2/miniconda3/etc/profile.d/conda.sh; conda activate e3sm_diags_20230914"
96+
environment_commands = "source"
9797
sets = "qbo",
9898
ts_subsection = "atm_monthly_180x360_aave"
9999

tests/integration/utils.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import shutil
44
import subprocess
5+
import sys
56
from typing import List
67

78
from mache import MachineInfo
@@ -133,8 +134,6 @@ def get_chyrsalis_expansions(config):
133134
d = {
134135
"bundles_walltime": "07:00:00",
135136
"constraint": "",
136-
# To run this test, replace conda environment with your e3sm_diags dev environment
137-
"diags_environment_commands": "source /home/ac.forsyth2/miniconda3/etc/profile.d/conda.sh; conda activate e3sm_diags_20230914",
138137
"diags_walltime": "5:00:00",
139138
"environment_commands_test": "source /lcrc/soft/climate/e3sm-unified/test_e3sm_unified_1.9.0rc16_chrysalis.sh",
140139
"expected_dir": "/lcrc/group/e3sm/public_html/zppy_test_resources/",
@@ -158,8 +157,6 @@ def get_compy_expansions(config):
158157
d = {
159158
"bundles_walltime": "02:00:00",
160159
"constraint": "",
161-
# To run this test, replace conda environment with your e3sm_diags dev environment
162-
"diags_environment_commands": "source /qfs/people/fors729/mambaforge/etc/profile.d/conda.sh; conda activate e3sm_diags_20230914",
163160
"diags_walltime": "03:00:00",
164161
"environment_commands_test": "source /share/apps/E3SM/conda_envs/test_e3sm_unified_1.9.0rc16_compy.sh",
165162
"expected_dir": "/compyfs/www/zppy_test_resources/",
@@ -183,8 +180,6 @@ def get_perlmutter_expansions(config):
183180
d = {
184181
"bundles_walltime": "6:00:00",
185182
"constraint": "cpu",
186-
# To run this test, replace conda environment with your e3sm_diags dev environment
187-
"diags_environment_commands": "source /global/homes/f/forsyth/miniconda3/etc/profile.d/conda.sh; conda activate e3sm_diags_20230914",
188183
"diags_walltime": "6:00:00",
189184
"environment_commands_test": "source /global/common/software/e3sm/anaconda_envs/test_e3sm_unified_1.9.0rc16_pm-cpu.sh",
190185
"expected_dir": "/global/cfs/cdirs/e3sm/www/zppy_test_resources/",
@@ -234,19 +229,26 @@ def substitute_expansions(expansions, file_in, file_out):
234229
file_write.write(line)
235230

236231

237-
def generate_cfgs(unified_testing=False, dry_run=False):
232+
def generate_cfgs(unified_testing=False, diags_environment_commands="", dry_run=False):
238233
git_top_level = (
239234
subprocess.check_output("git rev-parse --show-toplevel".split())
240235
.strip()
241236
.decode("utf-8")
242237
)
243238
expansions = get_expansions()
239+
244240
if unified_testing:
245241
expansions["environment_commands"] = expansions["environment_commands_test"]
246242
else:
247243
# The cfg doesn't need this line,
248244
# but it would be difficult to only write environment_commands in the unified_testing case.
249245
expansions["environment_commands"] = ""
246+
247+
if diags_environment_commands:
248+
expansions["diags_environment_commands"] = diags_environment_commands
249+
else:
250+
expansions["diags_environment_commands"] = ""
251+
250252
machine = expansions["machine"]
251253

252254
if dry_run:
@@ -276,4 +278,6 @@ def generate_cfgs(unified_testing=False, dry_run=False):
276278

277279

278280
if __name__ == "__main__":
279-
generate_cfgs(unified_testing=False)
281+
generate_cfgs(
282+
unified_testing=(sys.argv[1] == "True"), diags_environment_commands=sys.argv[2]
283+
)

tests/scripts/test_dev.bash

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/bash
2+
3+
# Before running this script ########################################################
4+
5+
# Make sure you're on the branch you want to test!
6+
7+
# If you want to test `main`, do the following:
8+
# git fetch upstream main
9+
# git checkout -b test_pre_zppy_rc<#>_<machine_name> upstream/main
10+
# git log # check the commits match https://github.com/E3SM-Project/zppy/commits/main
11+
12+
# Set these parameters
13+
DIAGS_DIR=/home/ac.forsyth2/e3sm_diags/
14+
DIAGS_DEV=diags_dev_2023_10_05
15+
ZPPY_DIR=/home/ac.forsyth2/zppy/
16+
DIAGS_ENV_CMD="source /home/ac.forsyth2/miniconda3/etc/profile.d/conda.sh; conda activate ${DIAGS_DEV}"
17+
ZPPY_DEV=zppy_dev_n516
18+
19+
# Make sure you do not have important changes on the `main` branch in your
20+
# E3SM_DIAGS_DIRECTORY. This script will reset that branch to match `upstream`!
21+
22+
#####################################################################################
23+
24+
echo "Update E3SM Diags"
25+
# `cd` to e3sm_diags directory
26+
cd ${DIAGS_DIR}
27+
git checkout main
28+
git fetch upstream
29+
git reset --hard upstream/main
30+
git log # Should match https://github.com/E3SM-Project/e3sm_diags/commits/main # TODO: Requires user review
31+
mamba clean --all # TODO: Requires user input to advance
32+
conda remove -n ${DIAGS_DEV} --all
33+
mamba env create -f conda-env/dev.yml -n ${DIAGS_DEV}
34+
conda activate ${DIAGS_DEV} # TODO: errors with ./tests/scripts/test_dev.bash: line 34: {DIAGS_DEV}: command not found
35+
pip install .
36+
cd ${ZPPY_DIR}
37+
38+
echo "Make sure we're using the latest packages"
39+
UNIFIED_TESTING=False
40+
python tests/integration/utils.py ${UNIFIED_TESTING} ${DIAGS_ENV_CMD}
41+
42+
echo "Set up our environment"
43+
mamba clean --all # TODO: Requires user input to advance
44+
mamba env create -f conda/dev.yml -n ${ZPPY_DEV}
45+
conda activate ${ZPPY_DEV} # TODO: errors with CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
46+
pip install .
47+
48+
echo "Run unit tests"
49+
python -u -m unittest tests/test_*.py
50+
if [ $? != 0 ]; then
51+
echo 'ERROR (1): unit tests failed'
52+
exit 1
53+
fi
54+
55+
exit 7
56+
57+
echo "Set up integration tests"
58+
# TODO: somehow use Mache (a Python package) to get machine-independent paths in this bash script!
59+
# test_complete_run
60+
rm -rf /lcrc/group/e3sm/public_html/diagnostic_output/ac.forsyth2/zppy_test_complete_run_www/v2.LR.historical_0201
61+
rm -rf /lcrc/group/e3sm/ac.forsyth2/zppy_test_complete_run_output/v2.LR.historical_0201/post
62+
# Run jobs:
63+
zppy -c tests/integration/generated/test_complete_run_chrysalis.cfg
64+
# TODO: how can we possibly tell, automatically, when this is finished?
65+
# After they finish, check the results:
66+
cd /lcrc/group/e3sm/ac.forsyth2/zppy_test_complete_run_output/v2.LR.historical_0201/post/scripts
67+
grep -v "OK" *status
68+
if [ $? == 0 ]; then
69+
# The above command succeeds only if there are reported failures.
70+
echo 'ERROR (2): zppy complete run failed.'
71+
exit 2
72+
fi
73+
cd ${ZPPY_DIR}
74+
# test_bundles
75+
rm -rf /lcrc/group/e3sm/public_html/diagnostic_output/ac.forsyth2/zppy_test_bundles_www/v2.LR.historical_0201
76+
rm -rf /lcrc/group/e3sm/ac.forsyth2/zppy_test_bundles_output/v2.LR.historical_0201/post
77+
# Run first set of jobs:
78+
zppy -c tests/integration/generated/test_bundles_chrysalis.cfg
79+
# TODO: how can we possibly tell, automatically, when this is finished?
80+
# bundle1 and bundle2 should run. After they finish, check the results:
81+
cd /lcrc/group/e3sm/ac.forsyth2/zppy_test_bundles_output/v2.LR.historical_0201/post/scripts
82+
grep -v "OK" *status
83+
if [ $? == 0 ]; then
84+
# The above command succeeds only if there are reported failures.
85+
echo 'ERROR (3): zppy bundles 1st run failed.'
86+
exit 3
87+
fi
88+
cd ${ZPPY_DIR}
89+
# Now, invoke zppy again to run jobs that needed to wait for dependencies:
90+
zppy -c tests/integration/generated/test_bundles_chrysalis.cfg
91+
# TODO: how can we possibly tell, automatically, when this is finished?
92+
# bundle3 and ilamb should run. After they finish, check the results:
93+
cd /lcrc/group/e3sm/ac.forsyth2/zppy_test_bundles_output/v2.LR.historical_0201/post/scripts
94+
grep -v "OK" *status
95+
if [ $? == 0 ]; then
96+
# The above command succeeds only if there are reported failures.
97+
echo 'ERROR (4): zppy bundles 2nd run failed.'
98+
exit 4
99+
fi
100+
cd ${ZPPY_DIR}
101+
102+
echo "Run the integration tests"
103+
python -u -m unittest tests/integration/test_*.py
104+
if [ $? != 0 ]; then
105+
echo 'ERROR (5): integration tests failed'
106+
exit 5
107+
fi
108+
109+
echo "All tests passed!"

0 commit comments

Comments
 (0)