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

Cleanup, adding unit tests for ccpp_track_variables.py, activate "chunked data" CI test, add missing MPI target in src/CMakeLists.txt #555

Merged
merged 12 commits into from
May 1, 2024

Conversation

mkavulich
Copy link
Collaborator

This PR makes several related changes:

  • Add unit tests for the ccpp_track_variables.py script, and run them automatically in CI, as requested in Implement CI for ccpp_track_variables.py #511. In addition, some cleanup changes were made to ccpp_track_variables.py to make implementing the CI test easier.
  • In implementing these new CI tests, I realized that the new "chunked_data" CI tests were not actually run; this PR will activate them.
  • Finally, there was a single change to ccpp_prebuild.py to make the import_config() routine fail "correctly" when the config file is not present: previous behavior was an exception due to mismatched return values.

User interface changes?: No

Fixes: #511

Testing:
test removed: None
unit tests: Adds test_track_variables.py to CI. Also, activates
system tests: I am not sure what this means 🤷
manual testing: Ran new tests manually with pytest

Copy link
Collaborator

@gold2718 gold2718 left a comment

Choose a reason for hiding this comment

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

I don't want to hold up this PR but I think docstrings for each test function would add helpful documentation of the tests and logical test coverage.

@@ -70,7 +70,7 @@ def import_config(configfile, builddir):
if not os.path.isfile(configfile):
logging.error("Configuration file {0} not found".format(configfile))
success = False
return
return(success, config)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the tuple? Doesn't Python do that anyway? Is that a style thing and if so, do we want to be consistent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gold2718 Sorry, I'm not sure what you mean. This function as called from main() expects two return values, and so currently when this block of code is executed (when there is no configuration file) it fails with a TypeError because it is not returning the expected values.

> ../scripts/ccpp_track_variables.py -s test_track_variables/suite_small_suite.xml -c test_track_variables/ccpp_prebuild_config -m test_track_variables/ -v air_pressure
ERROR:root:Configuration file test_track_variables/ccpp_prebuild_config not found
Traceback (most recent call last):
  File "/glade/derecho/scratch/kavulich/CCPP/track_variables_unit_test/ccpp-framework/test_prebuild/../scripts/ccpp_track_variables.py", line 217, in <module>
    track_variables(args.sdf,args.metadata_path,args.config,args.variable,args.debug)
  File "/glade/derecho/scratch/kavulich/CCPP/track_variables_unit_test/ccpp-framework/test_prebuild/../scripts/ccpp_track_variables.py", line 191, in track_variables
    (success, config) = import_config(config, None)
TypeError: cannot unpack non-iterable NoneType object

This change fixes the error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for the lack of clarity. All I was saying is that the parentheses are not needed so I was wondering why you use them. The same goes below where you call this function.
Is this a style thing we want to adopt? A quick look shows that the prebuild code seems to consistently use the parentheses syntax while the capgen code is . . . . mixed (I'm sure for good reasons :).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the clarification. I did not realize this until you brought this up, but parentheses are not strictly necessary for tuples, so this would be purely stylistic. Since the existing return tuples use parens I'll stick with that for now, especially since PEP8 doesn't seem to specify a preference from what I can tell.


(success, config) = import_config(args.config, None)
(success, config) = import_config(config, None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You also do not need the tuple to unpack the variables. Same questions as above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But it doesn't hurt, or? If so, then does it matter?

from ccpp_track_variables import track_variables

def test_successful_match(capsys):
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
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
Collaborator

Choose a reason for hiding this comment

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

Agreed

Copy link
Collaborator

@climbfuji climbfuji left a comment

Choose a reason for hiding this comment

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

Approving based on the CI tests all passing and the changes requested not absolutely necessary (but it would be nice to have a bit of documentation for the newly added track_variables test).

from ccpp_track_variables import track_variables

def test_successful_match(capsys):
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
Collaborator

Choose a reason for hiding this comment

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

Agreed


(success, config) = import_config(args.config, None)
(success, config) = import_config(config, None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

But it doesn't hurt, or? If so, then does it matter?

@mkavulich
Copy link
Collaborator Author

@climbfuji @gold2718 I agree we should have some docstrings here before merge, I'll work on that today.

@mkavulich
Copy link
Collaborator Author

@climbfuji @gold2718 I have added the requested docstrings, as well as updating the existing file-level docstring and adding a call to sys.exit() for the case where the test is not run with pytest. Let me know if you'd like any further changes/updates.

Copy link
Collaborator

@climbfuji climbfuji left a comment

Choose a reason for hiding this comment

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

This is great, thanks! One typo left to correct.

@@ -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
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

Copy link
Collaborator

@mwaxmonsky mwaxmonsky left a comment

Choose a reason for hiding this comment

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

Looks great! Just had one minor change in mind that might be useful but please feel free to disregard if it's not ideal.

test_prebuild/test_track_variables.py Outdated Show resolved Hide resolved
test_prebuild/test_track_variables.py Outdated Show resolved Hide resolved
test_prebuild/test_track_variables.py Outdated Show resolved Hide resolved
test_prebuild/test_track_variables.py Outdated Show resolved Hide resolved
@mkavulich
Copy link
Collaborator Author

@climbfuji @mwaxmonsky Thanks for the reviews, I have adopted your suggested changes.

@grantfirl
Copy link
Collaborator

@mkavulich Can you pull #556 into this so that I can add the latest hash of this branch to NOAA-EMC/fv3atm#816.

@mkavulich
Copy link
Collaborator Author

@grantfirl Done

@mkavulich mkavulich changed the title Cleanup, adding unit tests for ccpp_track_variables.py, activate "chunked data" CI test Cleanup, adding unit tests for ccpp_track_variables.py, activate "chunked data" CI test, add missing MPI target in src/CMakeLists.txt Apr 22, 2024
@grantfirl grantfirl merged commit 741212e into NCAR:main May 1, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement CI for ccpp_track_variables.py
5 participants