diff --git a/.github/workflows/norms.yaml b/.github/workflows/norms.yaml new file mode 100644 index 0000000..d277d66 --- /dev/null +++ b/.github/workflows/norms.yaml @@ -0,0 +1,24 @@ +name: Coding Norms +on: [push] + +jobs: + check_pynorms: + runs-on: ubuntu-latest + name: Check coding norms with pycodestyle + + steps: + + - name: Install dependencies + run: | + pip install --upgrade pip + pip install pycodestyle + - name: Checkout + uses: actions/checkout@v2 + with: + path: RDASApp + + - name: Run pycodestyle + run: | + cd $GITHUB_WORKSPACE/RDASApp + pycodestyle -v --config ./.pycodestyle ./ush ./test + diff --git a/.github/workflows/unittests.yaml b/.github/workflows/unittests.yaml new file mode 100644 index 0000000..b3cc630 --- /dev/null +++ b/.github/workflows/unittests.yaml @@ -0,0 +1,58 @@ +name: Unit Tests +on: [push, pull_request] + +jobs: + ctests: + runs-on: ubuntu-latest + name: Run Unit Tests with ctest + + steps: + + - name: Install pip dependencies + run: | + pip install --upgrade pip + pip install pycodestyle + pip install netCDF4 + pip install xarray + + - name: Checkout wxflow + uses: actions/checkout@v3 + with: + repository: NOAA-EMC/wxflow + ref: develop + path: wxflow + + - name: Install wxflow + run: | + cd wxflow + pip install . + + - name: Checkout + uses: actions/checkout@v2 + with: + path: RDASApp + + - name: Install ecBuild + run: | + git clone https://github.com/ecmwf/ecbuild.git ecbuild + cd ecbuild + git checkout 3.6.1 + mkdir bootstrap + cd bootstrap + ../bin/ecbuild .. + sudo make install + + - name: Configure with cmake + run: | + mkdir $GITHUB_WORKSPACE/build && cd $GITHUB_WORKSPACE/build + cmake -DBUILD_RDASBUNDLE=OFF $GITHUB_WORKSPACE/RDASApp + + - name: Build RDASApp + run: | + cd $GITHUB_WORKSPACE/build + make + + - name: Run ctest + run: | + cd $GITHUB_WORKSPACE/build + ctest --output-on-failure diff --git a/.pycodestyle b/.pycodestyle new file mode 100644 index 0000000..162186c --- /dev/null +++ b/.pycodestyle @@ -0,0 +1,6 @@ +[pycodestyle] +count = False +ignore = E226,E401,E402,W504 +max-line-length = 160 +statistics = True +exclude = Experimental diff --git a/CMakeLists.txt b/CMakeLists.txt index 6492baf..3b9937a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,7 +144,7 @@ endif(BUILD_RDASBUNDLE) #add_subdirectory(ush) # Include testing. -#add_subdirectory(test) +add_subdirectory(test) # Finalize bundle # --------------- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..3e44b28 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,11 @@ +# create testrun dir +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test/testrun) + +# test for python coding norms +add_test(NAME test_rdasapp_check_python_norms + COMMAND pycodestyle -v --config ./.pycodestyle ./ush ./test + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + +add_test(NAME test_rdasapp_gen_3dvar_yaml + COMMAND python3 ${PROJECT_SOURCE_DIR}/test/test_gen_3dvar_yaml.py --input ${PROJECT_SOURCE_DIR}/parm/atm/variational/3dvar_dripcg.yaml --output ${PROJECT_BINARY_DIR}/test/testrun/3dvar_example.yaml + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/testrun) diff --git a/test/test_gen_3dvar_yaml.py b/test/test_gen_3dvar_yaml.py new file mode 100644 index 0000000..2e1b52e --- /dev/null +++ b/test/test_gen_3dvar_yaml.py @@ -0,0 +1,39 @@ +import argparse +import datetime as dt +import os +from wxflow import parse_j2yaml, cast_strdict_as_dtypedict, save_as_yaml +from wxflow import add_to_datetime, to_timedelta, to_datetime + +my_dir = os.path.dirname(__file__) +rdas_dir = os.path.join(my_dir, '../') + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('-i', '--input', type=str, help='Input YAML Template', required=True) + parser.add_argument('-o', '--output', type=str, help='Output YAML File', required=True) + args = parser.parse_args() + + os.environ['BERROR_YAML'] = os.path.join(rdas_dir, 'parm', 'atm', 'berror', 'staticb_identity.yaml') + os.environ['OBS_LIST'] = os.path.join(rdas_dir, 'parm', 'atm', 'obs', 'lists', 'rdas_prototype.yaml') + os.environ['OBS_YAML_DIR'] = os.path.join(rdas_dir, 'parm', 'atm', 'obs', 'config') + + # let us define a configuration dictionary, note this will be incomplete and an example + config = { + 'ATM_WINDOW_BEGIN': to_datetime('2023-11-01T23:30:00Z'), + 'ATM_WINDOW_LENGTH': 'PT1H', + 'layout_x': 1, + 'layout_y': 1, + 'npx_ges': 201, + 'npy_ges': 151, + 'npz_ges': 65, + 'current_cycle': to_datetime('2023-11-02T00:00:00Z'), + 'npx_anl': 201, + 'npy_anl': 151, + 'npz_anl': 65, + 'DATA': os.path.join(os.path.dirname(args.output)), + 'GPREFIX': 'rrfs.t23z.', + 'APREFIX': 'rrfs.t00z.', + } + + final_config = parse_j2yaml(args.input, config) + save_as_yaml(final_config, args.output)