diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 9b1ef299..5fe3d893 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -7,8 +7,6 @@ from mache import MachineInfo from PIL import Image, ImageChops, ImageDraw -UNIQUE_ID = "unique_id" - # Image checking ########################################################## @@ -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 /conda.sh; conda activate ", "diags_walltime": "5:00:00", - "environment_commands_test": "", "expected_dir": "/lcrc/group/e3sm/public_html/zppy_test_resources/", - "global_time_series_environment_commands": "source /conda.sh; conda activate ", "mpas_analysis_walltime": "00:30:00", "partition_long": "compute", "partition_short": "debug", @@ -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 /conda.sh; conda activate ", "diags_walltime": "03:00:00", - "environment_commands_test": "", "expected_dir": "/compyfs/www/zppy_test_resources/", - "global_time_series_environment_commands": "source /conda.sh; conda activate ", "mpas_analysis_walltime": "02:00:00", "partition_long": "slurm", "partition_short": "short", @@ -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 /conda.sh; conda activate ", "diags_walltime": "6:00:00", - "environment_commands_test": "", "expected_dir": "/global/cfs/cdirs/e3sm/www/zppy_test_resources/", - "global_time_series_environment_commands": "source /conda.sh; conda activate ", "mpas_analysis_walltime": "03:00:00", "partition_long": "", "partition_short": "", @@ -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 @@ -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 @@ -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: @@ -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']}" @@ -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 /conda.sh; conda activate + # 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 + ) diff --git a/tests/integration/utils_setup.sh b/tests/integration/utils_setup.sh new file mode 100644 index 00000000..47bb890b --- /dev/null +++ b/tests/integration/utils_setup.sh @@ -0,0 +1,69 @@ +# Run this script to set up the zppy integration test environments. +# 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 git@github.com: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 git@github.com: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 git@github.com: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}" +fi +python tests/integration/utils.py ${unique_id} ${e3sm_diags_env_cmds} ${zi_env_cmds} ${unified_env_cmds} +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'