Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from mache import MachineInfo
from PIL import Image, ImageChops, ImageDraw

UNIQUE_ID = "unique_id"

# Image checking ##########################################################


Expand Down Expand Up @@ -194,13 +192,8 @@ def get_chyrsalis_expansions(config):
"case_name": "v3.LR.historical_0051",
"case_name_v2": "v2.LR.historical_0201",
"constraint": "",
# To run this test, replace conda environment with your e3sm_diags dev environment
# To use default environment_commands, set to ""
"diags_environment_commands": "source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>",
"diags_walltime": "5:00:00",
"environment_commands_test": "",
"expected_dir": "/lcrc/group/e3sm/public_html/zppy_test_resources/",
"global_time_series_environment_commands": "source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>",
"mpas_analysis_walltime": "00:30:00",
"partition_long": "compute",
"partition_short": "debug",
Expand All @@ -223,13 +216,8 @@ def get_compy_expansions(config):
"case_name": "v3.LR.historical_0051",
"case_name_v2": "v2.LR.historical_0201",
"constraint": "",
# To run this test, replace conda environment with your e3sm_diags dev environment
# To use default environment_commands, set to ""
"diags_environment_commands": "source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>",
"diags_walltime": "03:00:00",
"environment_commands_test": "",
"expected_dir": "/compyfs/www/zppy_test_resources/",
"global_time_series_environment_commands": "source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>",
"mpas_analysis_walltime": "02:00:00",
"partition_long": "slurm",
"partition_short": "short",
Expand All @@ -252,13 +240,8 @@ def get_perlmutter_expansions(config):
"case_name": "v3.LR.historical_0051",
"case_name_v2": "v2.LR.historical_0201",
"constraint": "cpu",
# To run this test, replace conda environment with your e3sm_diags dev environment
# To use default environment_commands, set to ""
"diags_environment_commands": "source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>",
"diags_walltime": "6:00:00",
"environment_commands_test": "",
"expected_dir": "/global/cfs/cdirs/e3sm/www/zppy_test_resources/",
"global_time_series_environment_commands": "source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>",
"mpas_analysis_walltime": "03:00:00",
"partition_long": "",
"partition_short": "",
Expand All @@ -273,7 +256,7 @@ def get_perlmutter_expansions(config):
return d


def get_expansions():
def get_expansions(unique_id: str):
machine_info = MachineInfo()
config = machine_info.config
machine = machine_info.machine
Expand All @@ -287,7 +270,7 @@ def get_expansions():
raise ValueError(f"Unsupported machine={machine}")
expansions["diagnostics_base_path"] = config.get("diagnostics", "base_path")
expansions["machine"] = machine
expansions["unique_id"] = UNIQUE_ID
expansions["unique_id"] = unique_id
return expansions


Expand All @@ -307,28 +290,22 @@ def substitute_expansions(expansions, file_in, file_out):
file_write.write(line)


def generate_cfgs(unified_testing=False, dry_run=False):
def generate_cfgs(
unique_id: str,
e3sm_diags_env_cmds: str,
zi_env_cmds: str,
unified_env_cmds: str,
dry_run=False,
):
git_top_level = (
subprocess.check_output("git rev-parse --show-toplevel".split())
.strip()
.decode("utf-8")
)
expansions = get_expansions()
if unified_testing:
expansions["environment_commands"] = expansions["environment_commands_test"]
# Use Unified for e3sm_diags and global_time_series unless we specify otherwise
if expansions["diags_environment_commands"] == "":
expansions["diags_environment_commands"] = expansions[
"environment_commands_test"
]
if expansions["global_time_series_environment_commands"] == "":
expansions["global_time_series_environment_commands"] = expansions[
"environment_commands_test"
]
else:
# The cfg doesn't need this line,
# but it would be difficult to only write environment_commands in the unified_testing case.
expansions["environment_commands"] = ""
expansions = get_expansions(unique_id)
expansions["diags_environment_commands"] = e3sm_diags_env_cmds
expansions["global_time_series_environment_commands"] = zi_env_cmds
expansions["environment_commands"] = unified_env_cmds
machine = expansions["machine"]

if dry_run:
Expand Down Expand Up @@ -416,8 +393,7 @@ def generate_cfgs(unified_testing=False, dry_run=False):
script_generated = f"{git_top_level}/tests/integration/generated/update_{script_name}_expected_files_{machine}.sh"
substitute_expansions(expansions, script_template, script_generated)
print("CFG FILES HAVE BEEN GENERATED FROM TEMPLATES WITH THESE SETTINGS:")
print(f"UNIQUE_ID={UNIQUE_ID}")
print(f"unified_testing={unified_testing}")
print(f"UNIQUE_ID={unique_id}")
print(f"diags_environment_commands={expansions['diags_environment_commands']}")
print(
f"global_time_series_environment_commands={expansions['global_time_series_environment_commands']}"
Expand All @@ -429,4 +405,28 @@ def generate_cfgs(unified_testing=False, dry_run=False):


if __name__ == "__main__":
generate_cfgs(unified_testing=False, dry_run=False)
import sys

if len(sys.argv) == 6:
unique_id = sys.argv[1]
e3sm_diags_env_cmds = sys.argv[2]
zi_env_cmds = sys.argv[3]
unified_env_cmds = sys.argv[4]
else:
# Set manually:
unique_id = "unique_id"
# For e3sm_diags_env and zi_env, use the following format:
# source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>
# Default "" will use the latest E3SM Unified environment
e3sm_diags_env_cmds = ""
zi_env_cmds = ""
unified_env_cmds = ""
if e3sm_diags_env_cmds == "None":
e3sm_diags_env_cmds = "" # Should pick up the latest E3SM Unified environment
if zi_env_cmds == "None":
zi_env_cmds = "" # Should pick up the latest E3SM Unified environment
if re.match("load_latest_e3sm_unified", unified_env_cmds):
unified_env_cmds = "" # Should pick up the latest E3SM Unified environment
generate_cfgs(
unique_id, e3sm_diags_env_cmds, zi_env_cmds, unified_env_cmds, dry_run=False
)
69 changes: 69 additions & 0 deletions tests/integration/utils_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Run this script to set up the zppy integration test environments.

Check failure on line 1 in tests/integration/utils_setup.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/integration/utils_setup.sh#L1

Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
# Run from the top level of the zppy repo

set -e # Fail immediately if a command exits with a non-zero status

# Define these for yourself
unique_id=unique_id
use_custom_e3sm_diags=false
use_custom_zi=false
use_custom_zppy=false
unified_env_cmds="source /lcrc/soft/climate/e3sm-unified/load_latest_e3sm_unified_chrysalis.sh" # Set to the command to load the latest unified environment.
conda_source_file="/gpfs/fs1/home/ac.forsyth2/miniforge3/etc/profile.d/conda.sh" # Set to the path of your conda source file


# Don't need to change anything below this line

conda clean --all --y # Clean up conda envs; also confirms conda is installed
workdir=~/zppy_test_setup_${unique_id}
rm -rf ${workdir} # Remove any old test setup
mkdir ${workdir}
cd ${workdir}

if [ "$use_custom_e3sm_diags" = "true" ]; then
git clone [email protected]:E3SM-Project/e3sm_diags.git
cd e3sm_diags
e3sm_diags_env=e3sm_diags_dev_${unique_id}
conda env create -f conda-env/dev.yml -n ${e3sm_diags_env}
conda activate ${e3sm_diags_env} && pip install .
cd ..
e3sm_diags_env_cmds="source ${conda_source_file}; conda activate ${e3sm_diags_env}"

else
e3sm_diags_env_cmds="None"
fi

if [ "$use_custom_zi" = "true" ]; then
git clone [email protected]:E3SM-Project/zppy-interfaces.git
cd zppy-interfaces
zi_env=zi_dev_${unique_id}
conda env create -f conda/dev.yml -n ${zi_env}
conda activate ${zi_env} && pip install .
pytest tests/unit/global_time_series/test_*.py
cd ..
zi_env_cmds="source ${conda_source_file}; conda activate ${zi_env}"
else
zi_env_cmds="None"
fi

git clone [email protected]:E3SM-Project/zppy.git
cd zppy
if [ "$use_custom_zppy" = "true" ]; then
zppy_env=zppy_dev_${unique_id}
conda env create -f conda/dev.yml -n ${zppy_env}
conda activate ${zppy_env} && pip install .
pytest tests/test_*.py
zppy_env_cmds="source ${conda_source_file}; conda activate ${zppy_env}"
else
zppy_env_cmds="${unified_env_cmds}"

Check warning on line 58 in tests/integration/utils_setup.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/integration/utils_setup.sh#L58

zppy_env_cmds appears unused. Verify use (or export if used externally).
fi
python tests/integration/utils.py ${unique_id} ${e3sm_diags_env_cmds} ${zi_env_cmds} ${unified_env_cmds}

Check warning on line 60 in tests/integration/utils_setup.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/integration/utils_setup.sh#L60

Double quote to prevent globbing and word splitting.
echo 'Generated diffs:'
git diff tests/integration/generated/test_weekly_comprehensive_v3_chrysalis.cfg
git diff tests/integration/generated/test_weekly_comprehensive_v2_chrysalis.cfg
git diff tests/integration/generated/test_weekly_bundles_chrysalis.cfg
echo "Run these commands from ${workdir}/zppy to create output for the integration tests:"
echo 'zppy -c tests/integration/generated/test_weekly_comprehensive_v3_chrysalis.cfg'
echo 'zppy -c tests/integration/generated/test_weekly_comprehensive_v2_chrysalis.cfg'
echo 'zppy -c tests/integration/generated/test_weekly_bundles_chrysalis.cfg # Runs 1st part of bundles cfg'
echo 'zppy -c tests/integration/generated/test_weekly_bundles_chrysalis.cfg # Runs 2nd part of bundles cfg'
Loading