NOAA-EMC / rrfs-workflow

workflow for RRFSv1
Other
13 stars 27 forks source link

how can unit tests and CI be added to the repo? #453

Open edwardhartnett opened 1 month ago

edwardhartnett commented 1 month ago

How can unit tests and CI be added to the repo?

There are shell scripts and python code.

Let's explore ways to add some unit testing.

edwardhartnett commented 1 month ago

Unit tests are great to find bugs and program faster. But they do have a cost. Whereas the code problems detected by pylint/flake8 are free, requiring no more than that we look at the output and fix our code. See #456 for discussion.

I will continue adding a unit test to demonstrate; it may be that you want to have unit testing in place in some cases before fixing the problems detected by pylint.

edwardhartnett commented 1 month ago

OK, if you take a look at my branch you will see the following (failing) test:

from exrrfs_process_glmfed import addmodelfed

def test_addmodelfed():
    addmodelfed(".")

This fails like this:

scripts/test_sample.py:5: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
scripts/exrrfs_process_glmfed.py:45: in addmodelfed
    u = nc.Dataset(corefile,'r')
src/netCDF4/_netCDF4.pyx:2470: in netCDF4._netCDF4.Dataset.__init__
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   FileNotFoundError: [Errno 2] No such file or directory: '.fv_core.res.tile1.nc'

src/netCDF4/_netCDF4.pyx:2107: FileNotFoundError

I need a copy of the file:

corefile = restartpath+'fv_core.res.tile1.nc' # need diff names for ensembles? Can you tell me where to find one of these files for testing?

edwardhartnett commented 1 month ago

OK, we have begun our unit testing journey and that is very exciting. We now have a CI job which runs a flake8 test of the python code to check for syntax errors. If it passes, there are no syntax errors in the python code.

We have a long way to go, but that's a great start.

GitHub repo owners: you need to create a ruleset and apply it to the dev-sci branch. The ruleset should require that only PRs are used to update the branch, and that the flake8 tests must pass. Let me know if you need help setting this up, we have it on all the NCEPLIBS if you want to look.

As new error messages are added to the flake8 check, you'll get incrementally closer to clearing all flake8 warnings.