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

Add github actions for python unittests. #747

Merged
merged 10 commits into from
May 16, 2022
32 changes: 32 additions & 0 deletions .github/workflows/python_unittests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Python unittests
on: [push, pull_request]
jobs:

python_unittests:
name: Python unittests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Install dependencies
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install python3 python3-pip netcdf-bin
sudo pip3 install pyyaml jinja2 f90nml

# Run python unittests
- name: Run python unittests
run: |
cd ush
python3 -m unittest -b python_utils/test_python_utils.py
python3 -m unittest -b check_ruc_lsm.py create_diag_table_file.py \
create_model_configure_file.py link_fix.py set_cycle_dates.py \
set_extrn_mdl_params.py set_FV3nml_sfc_climo_filenames.py \
set_FV3nml_ens_stoch_seeds.py set_gridparams_ESGgrid.py \
set_gridparams_GFDLgrid.py set_ozone_param.py \
set_predef_grid_params.py set_thompson_mp_fix_files.py \
get_crontab_contents.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work if there is just a pattern like *.py so we don't have to keep track of which files have tests in them?

Copy link
Collaborator Author

@danielabdi-noaa danielabdi-noaa Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had issues with some python scripts in ush dir and unittests. On hera, for example, numpy and matplotlib needed by mrms_pull_topofhour.py and UFS_plot_domains.py, are missing even after activating wflow_hera.env, so unittest fails. Moreover, with the former there is an issue with scripts that accept arguments but don't have unittest class implemented -- which I have fixed now. UFS_plot_domains.py uses deprecated plotting libraray Basemap from mpl_toolkits so need to figure out a way to install that for github actions. Or I could simply include all python scripts except problematic ones with some sort of wildcard ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok all is good now. It doesn't fail with *.py but no real unittests are done on python scripts not related to the workflow generation.


6 changes: 3 additions & 3 deletions ush/set_extrn_mdl_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class Testing(unittest.TestCase):
def test_extrn_mdl_params(self):
set_extrn_mdl_params()
EXTRN_MDL_SYSBASEDIR_ICS = get_env_var("EXTRN_MDL_SYSBASEDIR_ICS")
COMINgfs = get_env_var("COMINgfs")
self.assertEqual(EXTRN_MDL_SYSBASEDIR_ICS,COMINgfs)
COMIN = get_env_var("COMIN")
self.assertEqual(EXTRN_MDL_SYSBASEDIR_ICS,COMIN)

def setUp(self):
set_env_var("MACHINE","HERA")
Expand All @@ -76,4 +76,4 @@ def setUp(self):
set_env_var("EXTRN_MDL_SYSBASEDIR_ICS",None)
set_env_var("EXTRN_MDL_SYSBASEDIR_LBCS",None)
set_env_var("EXTRN_MDL_LBCS_OFFSET_HRS",None)
set_env_var("COMINgfs","/base/path/of/directory/containing/gfs/input/files")
set_env_var("COMIN","/base/path/of/directory/containing/gfs/input/files")