Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixes #646

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ simulations by automating commonly performed tasks.

See [documentation](https://e3sm-project.github.io/zppy) for more details.

- Run `python -m unittest discover -s tests -p "test_*.py"` to run all tests.
- Run `python -m unittest tests/test_*.py` to run only unit tests.
- Run `python -m unittest tests/integration/test_*.py` to run only integration tests (on server).
- Run `pytest tests/test_*.py` to run only unit tests.
- Run `pytest tests/integration/test_*.py` to run only integration tests (on server).

## License

Expand Down
2 changes: 1 addition & 1 deletion docs/source/dev_guide/new_glb_plot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Note that unlike E3SM Diags and MPAS-Analysis which are packages called by ``zpp
- In `coupled_global.py <https://github.com/E3SM-Project/zppy/blob/main/zppy/templates/coupled_global.py>`_: Add variables under "# Variables to extract". Add the code for your new plot under "Plotting functions"; the name of your function should start with ``plot_``. In ``PLOT_DICT``, add ``"function name without plot_" : function name``.
- If this plot should be added to the defaults, then complete this step: for ``plot_names`` under ``[global_time_series]`` in `default.ini <https://github.com/E3SM-Project/zppy/blob/main/zppy/templates/default.ini>`_, add the function name without plot to the string.
- Optionally, after making your edits, you can run ``pre-commit run --all-files`` to clean up your code and check for any obvious errors.
- Run the `integration tests <https://e3sm-project.github.io/zppy/_build/html/main/dev_guide/testing.html#integration-tests>`_ and examine the differences from the expected files. If they match what you expect, update the expected files following "Commands to run to replace outdated expected files" on the machine-specific directions. (The commands to run all the integration tests are ``pip install .`` followed by ``python -u -m unittest tests/integration/test_*.py``).
- Run the `integration tests <https://e3sm-project.github.io/zppy/_build/html/main/dev_guide/testing.html#integration-tests>`_ and examine the differences from the expected files. If they match what you expect, update the expected files following "Commands to run to replace outdated expected files" on the machine-specific directions. (The commands to run all the integration tests are ``pip install .`` followed by ``pytest tests/integration/test_*.py``).
4 changes: 2 additions & 2 deletions docs/source/dev_guide/release_testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Testing directions for making a release
* Compy: ``source /share/apps/E3SM/conda_envs/load_latest_e3sm_unified_compy.sh``
* Perlmutter: ``source /global/common/software/e3sm/anaconda_envs/load_latest_e3sm_unified_pm-cpu.sh``

7. Run the unit tests with ``python -u -m unittest tests/test_*.py``.
7. Run the unit tests with ``pytest tests/test_*.py``.

a. test dev (run before making a new zppy RC):

Expand All @@ -107,7 +107,7 @@ Testing directions for making a release
* `Compy <https://github.com/E3SM-Project/zppy/blob/main/tests/integration/generated/directions_compy.md>`_
* `Perlmutter <https://github.com/E3SM-Project/zppy/blob/main/tests/integration/generated/directions_pm-cpu.md>`_

9. Run the integration tests with ``python -u -m unittest tests/integration/test_*.py``. Note that ``test_complete_run.py`` takes approximately 75 minutes to run on Compy.
9. Run the integration tests with ``pytest tests/integration/test_*.py``. Note that ``test_complete_run.py`` takes approximately 75 minutes to run on Compy.

a. test dev (run before making a new zppy RC):

Expand Down
4 changes: 2 additions & 2 deletions docs/source/dev_guide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Run all unit tests by doing the following:
.. code::

pip install . # Install your changes (`python -m pip install .` also works)
python -u -m unittest tests/test_*.py # Run all unit tests
pytest tests/test_*.py # Run all unit tests

Integration tests
=================
Expand All @@ -24,7 +24,7 @@ Run all integration tests by doing the following:

pip install . # Install your changes (`python -m pip install .` also works)

python -u -m unittest tests/integration/test_*.py # Run all integration tests
pytest tests/integration/test_*.py # Run all integration tests

Automated tests
===============
Expand Down
4 changes: 2 additions & 2 deletions docs/source/dev_guide/tutorial_testing_e3sm_unified.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,5 @@ Run the unit tests and integration tests on Chrysalis:
git fetch upstream
git rebase upstream/main
<ENVIRONMENT_COMMANDS> # Load the appropriate environment
python -u -m unittest tests/test_*.py # Run unit tests
python -u -m unittest tests/integration/test_*.py # Run integration tests
pytest tests/test_*.py # Run unit tests
pytest tests/integration/test_*.py # Run integration tests
2 changes: 1 addition & 1 deletion tests/integration/generated/directions_chrysalis.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Changing `UNIQUE_ID` allows you to simultaneously run jobs
launched from `zppy` on different branches,
without worrying about overwriting results.

NOTE: Actually running the tests (e.g., `python -u -m unittest tests/integration/test_*.py`)
NOTE: Actually running the tests (e.g., `pytest tests/integration/test_*.py`)
can not be done from two different branches simultaneously
(since files in the `zppy` directory rather than an external directory get changed).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[default]
case = "v3.LR.historical_0051"
constraint = ""
dry_run = "False"
environment_commands = ""
fail_on_dependency_skip = True
guess_path_parameters = False
guess_section_parameters = False
input = /lcrc/group/e3sm2/ac.wlin/E3SMv3/v3.LR.historical_0051
input_subdir = archive/atm/hist
mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc"
output = "/lcrc/group/e3sm/ac.forsyth2/zppy_min_case_global_time_series_comprehensive_v3_setup_only_output/unique_id/v3.LR.historical_0051"
partition = "debug"
qos = "regular"
www = "/lcrc/group/e3sm/public_html/diagnostic_output/ac.forsyth2/zppy_min_case_global_time_series_comprehensive_v3_setup_only_www/unique_id"
years = "1985:1989:2",

[ts]
active = True
e3sm_to_cmip_environment_commands = ""
walltime = "00:30:00"

[[ atm_monthly_glb ]]
# Note global average won't work for 3D variables.
frequency = "monthly"
input_files = "eam.h0"
input_subdir = "archive/atm/hist"
mapping_file = "glb"
years = "1985:1995:5",

[[ lnd_monthly_glb ]]
frequency = "monthly"
input_files = "elm.h0"
input_subdir = "archive/lnd/hist"
mapping_file = "glb"
vars = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR"
years = "1985:1995:5",

[mpas_analysis]
active = True
anomalyRefYear = 1985
climo_years = "1985-1989", "1990-1995",
enso_years = "1985-1989", "1990-1995",
mesh = "IcoswISC30E3r5"
parallelTaskCount = 6
partition = "compute"
qos = "regular"
shortTermArchive = True
ts_years = "1985-1989", "1985-1995",
walltime = "00:30:00"

# (This cfg is the setup portion only)
# [global_time_series]
# active = True
# climo_years = "1985-1989", "1990-1995",
# environment_commands = "source <INSERT PATH TO CONDA>/conda.sh; conda activate <INSERT ENV NAME>"
# experiment_name = "v3.LR.historical_0051"
# figstr = "v3.LR.historical_0051"
# moc_file=mocTimeSeries_1985-1995.nc
# plots_lnd = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR"
# ts_num_years = 5
# ts_years = "1985-1989", "1985-1995",
# walltime = "00:30:00"
# years = "1985-1995",
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ rm -rf /lcrc/group/e3sm/public_html/zppy_test_resources/expected_bash_files
# You can just move (i.e., not copy) the output since re-running this test will re-generate the output.
mv test_bash_generation_output/post/scripts /lcrc/group/e3sm/public_html/zppy_test_resources/expected_bash_files
# Rerun test
python -u -m unittest tests/integration/test_bash_generation.py
pytest tests/integration/test_bash_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ do
done

# Rerun test
python -m unittest tests/integration/test_campaign.py
pytest tests/integration/test_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mkdir -p /lcrc/group/e3sm/public_html/zppy_test_resources/test_defaults_expected
# You can just move (i.e., not copy) the output since re-running this test will re-generate the output.
mv test_defaults_output/post/scripts/*.settings /lcrc/group/e3sm/public_html/zppy_test_resources/test_defaults_expected_files
# Rerun test
python -u -m unittest tests/integration/test_defaults.py
pytest tests/integration/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ do
done

# Rerun test
python -u -m unittest tests/integration/test_weekly.py
pytest tests/integration/test_weekly.py
2 changes: 1 addition & 1 deletion tests/integration/template_directions.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Changing `UNIQUE_ID` allows you to simultaneously run jobs
launched from `zppy` on different branches,
without worrying about overwriting results.

NOTE: Actually running the tests (e.g., `python -u -m unittest tests/integration/test_*.py`)
NOTE: Actually running the tests (e.g., `pytest tests/integration/test_*.py`)
can not be done from two different branches simultaneously
(since files in the `zppy` directory rather than an external directory get changed).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[default]
case = "#expand case_name#"
constraint = "#expand constraint#"
dry_run = "#expand dry_run#"
environment_commands = "#expand environment_commands#"
fail_on_dependency_skip = True
guess_path_parameters = False
guess_section_parameters = False
input = /lcrc/group/e3sm2/ac.wlin/E3SMv3/#expand case_name#
input_subdir = archive/atm/hist
mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc"
output = "#expand user_output#zppy_min_case_global_time_series_comprehensive_v3_setup_only_output/#expand unique_id#/#expand case_name#"
partition = "#expand partition_short#"
qos = "#expand qos_short#"
www = "#expand user_www#zppy_min_case_global_time_series_comprehensive_v3_setup_only_www/#expand unique_id#"
years = "1985:1989:2",

[ts]
active = True
e3sm_to_cmip_environment_commands = "#expand e3sm_to_cmip_environment_commands#"
walltime = "00:30:00"

[[ atm_monthly_glb ]]
# Note global average won't work for 3D variables.
frequency = "monthly"
input_files = "eam.h0"
input_subdir = "archive/atm/hist"
mapping_file = "glb"
years = "1985:1995:5",

[[ lnd_monthly_glb ]]
frequency = "monthly"
input_files = "elm.h0"
input_subdir = "archive/lnd/hist"
mapping_file = "glb"
vars = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR"
years = "1985:1995:5",

[mpas_analysis]
active = True
anomalyRefYear = 1985
climo_years = "1985-1989", "1990-1995",
enso_years = "1985-1989", "1990-1995",
mesh = "IcoswISC30E3r5"
parallelTaskCount = 6
partition = "#expand partition_long#"
qos = "#expand qos_long#"
shortTermArchive = True
ts_years = "1985-1989", "1985-1995",
walltime = "#expand mpas_analysis_walltime#"

# (This cfg is the setup portion only)
# [global_time_series]
# active = True
# climo_years = "1985-1989", "1990-1995",
# environment_commands = "#expand global_time_series_environment_commands#"
# experiment_name = "#expand case_name#"
# figstr = "#expand case_name#"
# moc_file=mocTimeSeries_1985-1995.nc
# plots_lnd = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR"
# ts_num_years = 5
# ts_years = "1985-1989", "1985-1995",
# walltime = "00:30:00"
# years = "1985-1995",
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ rm -rf #expand expected_dir#expected_bash_files
# You can just move (i.e., not copy) the output since re-running this test will re-generate the output.
mv test_bash_generation_output/post/scripts #expand expected_dir#expected_bash_files
# Rerun test
python -u -m unittest tests/integration/test_bash_generation.py
pytest tests/integration/test_bash_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ do
done

# Rerun test
python -m unittest tests/integration/test_campaign.py
pytest tests/integration/test_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mkdir -p #expand expected_dir#test_defaults_expected_files
# You can just move (i.e., not copy) the output since re-running this test will re-generate the output.
mv test_defaults_output/post/scripts/*.settings #expand expected_dir#test_defaults_expected_files
# Rerun test
python -u -m unittest tests/integration/test_defaults.py
pytest tests/integration/test_defaults.py
2 changes: 1 addition & 1 deletion tests/integration/template_update_weekly_expected_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ do
done

# Rerun test
python -u -m unittest tests/integration/test_weekly.py
pytest tests/integration/test_weekly.py
29 changes: 10 additions & 19 deletions tests/integration/test_bash_generation.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import os
import unittest

from tests.integration.utils import get_expansions


class TestBashGeneration(unittest.TestCase):
def test_bash_generation(self):
# cfg is not machine-specific
self.assertEqual(
os.system("zppy -c tests/integration/test_bash_generation.cfg"), 0
def test_bash_generation():
# cfg is not machine-specific
assert os.system("zppy -c tests/integration/test_bash_generation.cfg") == 0
expected_dir = get_expansions()["expected_dir"]
assert (
os.system(
f"diff -bur -I 'templateDir' test_bash_generation_output/post/scripts {expected_dir}expected_bash_files"
)
expected_dir = get_expansions()["expected_dir"]
self.assertEqual(
os.system(
f"diff -bur -I 'templateDir' test_bash_generation_output/post/scripts {expected_dir}expected_bash_files"
),
0,
)
self.assertEqual(os.system("rm -r test_bash_generation_output"), 0)


if __name__ == "__main__":
# Run from top level of repo
unittest.main()
== 0
)
assert os.system("rm -r test_bash_generation_output") == 0
Loading
Loading