Skip to content
Merged
Changes from 2 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
26 changes: 23 additions & 3 deletions test_prebuild/test_track_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
-----------------------------------------------------------------------
Description: Contains unit tests for ccpp_track_variables.py script

Assumptions:
Assumptions: Assumes user has correct environment for running ccpp_track_variables.py script.
This script should not be run directly, but rather invoked with pytest.

Command line arguments: none

Usage: python test_var_transforms.py # run the unit tests
Usage: pytest test_track_variables.py # run the unit tests
-----------------------------------------------------------------------
"""
import sys
Expand All @@ -28,6 +29,9 @@
from ccpp_track_variables import track_variables

def test_successful_match(capsys):
"""Tests whether test_track_variables.py produces expected output from sample suite and
metadata files for a case with a successful match (user provided a variable that exists
within the schemes specified by the test suite)"""
expected_output = """For suite test_track_variables/suite_small_suite.xml, the following schemes (in order for each group) use the variable air_pressure:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A doc string explaining the purpose of the test (what is being tested, test limits, etc.) would be helpful here and for all the test functions below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed

In group group1
scheme_1_run (intent in)
Expand All @@ -43,6 +47,11 @@ def test_successful_match(capsys):
i+=1

def test_successful_match_with_subcycles(capsys):
"""Tests whether test_track_variables.py produces expected output from sample suite and
metadata files for a case with a successful match(user provided a variable that exists

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
metadata files for a case with a successful match(user provided a variable that exists
metadata files for a case with a successful match (user provided a variable that exists

within the schemes specified by the test suite). In this case, the test suite file
contains subcycles, so the output should reflect this."""

expected_output = """For suite test_track_variables/suite_TEST_SUITE.xml, the following schemes (in order for each group) use the variable surface_air_pressure:
In group group1
scheme_3_run (intent inout)
Expand All @@ -69,6 +78,11 @@ def test_successful_match_with_subcycles(capsys):


def test_partial_match(capsys):
"""Tests whether test_track_variables.py produces expected output from sample suite and
metadata files for a case with a partial match: user provided a variable that does not
exist in the test suite, but is a substring of one or more other variables that do
exist."""

expected_output = """Variable surface not found in any suites for sdf test_track_variables/suite_TEST_SUITE.xml

ERROR:ccpp_track_variables:Variable surface not found in any suites for sdf test_track_variables/suite_TEST_SUITE.xml
Expand Down Expand Up @@ -96,6 +110,10 @@ def test_partial_match(capsys):


def test_no_match(capsys):
"""Tests whether test_track_variables.py produces expected output from sample suite and
metadata files for a case with no match (user provided a variable that does not exist
within the schemes specified by the test suite)"""

expected_output = """Variable abc not found in any suites for sdf test_track_variables/suite_TEST_SUITE.xml

ERROR:ccpp_track_variables:Variable abc not found in any suites for sdf test_track_variables/suite_TEST_SUITE.xml"""
Expand All @@ -111,12 +129,14 @@ def test_no_match(capsys):


def test_bad_config(capsys):
"""Tests whether test_track_variables.py fails gracefully when provided a config file that does
not exist."""
with pytest.raises(Exception) as excinfo:
track_variables(SUITE_FILE,SAMPLE_FILES_DIR,f'{SAMPLE_FILES_DIR}/nofile','abc',False)
assert str(excinfo.value) == "Call to import_config failed."


if __name__ == "__main__":
print("This test file is designed to be run with pytest; can not be run directly")

sys.exit(1)