Skip to content

Commit

Permalink
Merge pull request #130 from NOAA-GFDL/122.cli.separate
Browse files Browse the repository at this point in the history
122.cli.separate
  • Loading branch information
ilaflott authored Jul 26, 2024
2 parents 7f716a5 + d7b3005 commit 2947c44
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fre/pp/frepp.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def configure_xml(context, xml, platform, target, experiment, do_analysis, histo
)
@click.pass_context
def wrapper(context, experiment, platform, target, config_file, branch='main'):
""" - Execute fre pp checkout """
""" - Execute fre pp steps in order """
context.forward(runFre2pp)

if __name__ == "__main__":
Expand Down
95 changes: 95 additions & 0 deletions fre/pp/tests/test_fre_pp_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3

from fre import fre
from fre import pp

from click.testing import CliRunner
runner = CliRunner()

#tests are structured in the manner of:
#https://click.palletsprojects.com/en/8.1.x/testing/
#general intent for these tests is that each fre tool has 2 commandline tests:
#help, command does not exist

#Test list:
#fre pp (covered in fre/tests, not fre/pp/tests)
#-- fre pp checkout
#-- fre pp configure-xml
#-- fre pp configure-yaml
#-- fre pp install
#-- fre pp run
#-- fre pp status
#-- fre pp validate
#-- fre pp wrapper

#-- fre pp checkout
def test_cli_fre_pp_checkout_help():
result = runner.invoke(fre.fre, args=['--help', "pp checkout"])
assert result.exit_code == 0

def test_cli_fre_pp_checkout_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp checkout"])
assert result.exit_code == 2

#-- fre pp configure-xml
def test_cli_fre_pp_configure_xml_help():
result = runner.invoke(fre.fre, args=['--help', "pp configure-xml"])
assert result.exit_code == 0

def test_cli_fre_pp_configure_xml_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp configure-xml"])
assert result.exit_code == 2

#-- fre pp configure-yaml
def test_cli_fre_pp_configure_yaml_help():
result = runner.invoke(fre.fre, args=['--help', "pp configure-yaml"])
assert result.exit_code == 0

def test_cli_fre_pp_configure_yaml_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp configure-yaml"])
assert result.exit_code == 2

#-- fre pp install
def test_cli_fre_pp_install_help():
result = runner.invoke(fre.fre, args=['--help', "pp install"])
assert result.exit_code == 0

def test_cli_fre_pp_install_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp install"])
assert result.exit_code == 2

#-- fre pp run
def test_cli_fre_pp_run_help():
result = runner.invoke(fre.fre, args=['--help', "pp run"])
assert result.exit_code == 0

def test_cli_fre_pp_run_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp run"])
assert result.exit_code == 2

#-- fre pp status
def test_cli_fre_pp_status_help():
result = runner.invoke(fre.fre, args=['--help', "pp status"])
assert result.exit_code == 0

def test_cli_fre_pp_status_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp status"])
assert result.exit_code == 2

#-- fre pp validate
def test_cli_fre_pp_validate_help():
result = runner.invoke(fre.fre, args=['--help', "pp validate"])
assert result.exit_code == 0

def test_cli_fre_pp_validate_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp validate"])
assert result.exit_code == 2

#-- fre pp wrapper
def test_cli_fre_pp_wrapper_help():
result = runner.invoke(fre.fre, args=['--help', "pp wrapper"])
assert result.exit_code == 0

def test_cli_fre_pp_wrapper_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp wrapper"])
assert result.exit_code == 2
2 changes: 1 addition & 1 deletion fre/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ testpaths =
# fre/cmor/tests
# fre/list/tests
# fre/make/tests
# fre/pp/tests
fre/pp/tests
# fre/run/tests
# fre/test/tests
# fre/yamltools/tests
Expand Down
17 changes: 17 additions & 0 deletions fre/tests/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
note- this directory is for unit tests assessing `fre` functionality, and NOT for code corresponding to the command `fre test`

to run the tests as intended, simply call `pytest` from the root directory of this repository.

From the root directory of this repository, if you want to...

Invoke all tests (intended use):
`pytest fre/tests/`

Invoke all tests in a single file:
`pytest fre/tests/test_fre_cli.py`

Invoke a single test in a file:
`pytest fre/tests/test_fre_cli.py::test_cli_fre_option_dne`


Note that pytest will not print stdout from individual tests. If you want to...

Print stdout from an invoked test (debugging with print statements):
`pytest fre/tests/test_fre_cli.py::test_cli_fre_option_dne -s`
122 changes: 122 additions & 0 deletions fre/tests/test_fre_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
from click.testing import CliRunner
runner = CliRunner()

#tests are structured in the manner of:
#https://click.palletsprojects.com/en/8.1.x/testing/
#general intent for these tests is that each fre tool has 3 commandline tests:
#command, help, command does not exist

#Test list:
#fre
#-- fre app
#-- fre catalog
#-- fre check
#-- fre cmor
#-- fre list
#-- fre make
#-- fre pp
#-- fre run

def test_cli_fre():
result = runner.invoke(fre.fre)
Expand All @@ -23,3 +38,110 @@ def test_cli_fre_option_dne():
#print(f'exit code of runner result is {result.exit_code}')
#print(f'output of runner result is {result.output}')
assert result.exit_code == 2

#-- fre app

def test_cli_fre_app():
result = runner.invoke(fre.fre, args=["app"])
assert result.exit_code == 0

def test_cli_fre_app_help():
result = runner.invoke(fre.fre, args=['--help', "app"])
assert result.exit_code == 0

def test_cli_fre_app_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "app"])
assert result.exit_code == 2

#-- fre catalog
def test_cli_fre_catalog():
result = runner.invoke(fre.fre, args=["catalog"])
assert result.exit_code == 0

def test_cli_fre_catalog_help():
result = runner.invoke(fre.fre, args=['--help', "catalog"])
assert result.exit_code == 0

def test_cli_fre_catalog_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "catalog"])
assert result.exit_code == 2

#-- fre check

def test_cli_fre_check():
result = runner.invoke(fre.fre, args=["check"])
assert result.exit_code == 0

def test_cli_fre_check_help():
result = runner.invoke(fre.fre, args=['--help', "check"])
assert result.exit_code == 0

def test_cli_fre_check_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "check"])
assert result.exit_code == 2

#-- fre cmor

def test_cli_fre_cmor():
result = runner.invoke(fre.fre, args=["cmor"])
assert result.exit_code == 0

def test_cli_fre_cmor_help():
result = runner.invoke(fre.fre, args=['--help', "cmor"])
assert result.exit_code == 0

def test_cli_fre_cmor_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "cmor"])
assert result.exit_code == 2

#-- fre list
def test_cli_fre_list():
result = runner.invoke(fre.fre, args=["list"])
assert result.exit_code == 0

def test_cli_fre_list_help():
result = runner.invoke(fre.fre, args=['--help', "list"])
assert result.exit_code == 0

def test_cli_fre_list_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "list"])
assert result.exit_code == 2

#-- fre make
def test_cli_fre_make():
result = runner.invoke(fre.fre, args=["make"])
assert result.exit_code == 0

def test_cli_fre_make_help():
result = runner.invoke(fre.fre, args=['--help', "make"])
assert result.exit_code == 0

def test_cli_fre_make_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "make"])
assert result.exit_code == 2

#-- fre pp
def test_cli_fre_pp():
result = runner.invoke(fre.fre, args=["pp"])
assert result.exit_code == 0

def test_cli_fre_pp_help():
result = runner.invoke(fre.fre, args=['--help', "pp"])
assert result.exit_code == 0

def test_cli_fre_pp_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "pp"])
assert result.exit_code == 2

#-- fre run
def test_cli_fre_run():
result = runner.invoke(fre.fre, args=["run"])
assert result.exit_code == 0

def test_cli_fre_run_help():
result = runner.invoke(fre.fre, args=['--help', "run"])
assert result.exit_code == 0

def test_cli_fre_run_opt_dne():
result = runner.invoke(fre.fre, args=['optionDNE', "run"])
assert result.exit_code == 2

0 comments on commit 2947c44

Please sign in to comment.