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

Add options for pre-registered DDT names #644

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

gold2718
Copy link
Collaborator

Add options for pre-registered DDT names

Add an option for pre-registered DDT names
Add ccpp_constituent_prop_ptr_t as a default (pre-registered) DDT
Add test for 'unknown' DDT variables

User interface changes?: Yes
Added a new option, --ddt-names, to allow users to simply add DDT names that allow generation of a CCPP metadata template from a Fortran source. Because it is an option, it is backwards compatible.

Fixes: #643
ccpp_fortran_to_metadata.py errors out when given a file that has a constituent properties object

Testing:
test removed: None
unit tests: NA
system tests: NA
manual testing: Added a manual test that tests this bug fix

Add ccpp_constituent_prop_ptr_t as default DDT
Add test for 'unknown' DDT variables
@gold2718 gold2718 added the bugfix Fix for issue with 'bug' label. label Feb 15, 2025
@gold2718 gold2718 requested a review from cacraigucar February 15, 2025 20:19
@gold2718 gold2718 self-assigned this Feb 15, 2025
@gold2718
Copy link
Collaborator Author

I wasn't sure how to best add a test for a one-off script such as ccpp_fortran_to_metadata.py so I just plunked a test script and example file in the test directory. Perhaps @mwaxmonsky can provide guidance that is more or less inline with his testing refactoring work .

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.

I'll defer to @mwaxmonsky for the best way to test this, otherwise this looks good to me

@mwaxmonsky
Copy link
Collaborator

I wasn't sure how to best add a test for a one-off script such as ccpp_fortran_to_metadata.py so I just plunked a test script and example file in the test directory. Perhaps @mwaxmonsky can provide guidance that is more or less inline with his testing refactoring work .

Thanks for adding this in @gold2718!

In terms of setup, this feels in the spirit of the tests in the unit_test directory with a sample file. I'm still testing it out but I tried a pure CMake approach and a pure Python approach and it's kind of a tie in terms of complexity so I'm going ahead with a Python approach at the moment since it would also be useful for refactoring some of the unit_test file IO soon as well.

If I can get it working, would there be any concerns with using something like:

import unittest
import subprocess
import tempfile
import difflib

def test_pre_registered_ddt_type(unittest.TestCase):
    script = "..." #will follow current shell implementation.
    
    d = tempfile.TemporaryDirectory(dir=...) #Will be the same temp directory from script.
    subprocess.run(script)

    expected_data = fopen(...)
    actual_file   = fopen(...)
    deltas = list(difflib.ndiff(expected_data.readlines(), actual_file.readlines()))

    assertEqual([], deltas)

    d.cleanup()

Again, I'm still flushing out a working version and if there is a benefit to using the script approach, I'm happy to add that capability to the python test harness if I can so the script isn't needed.

@gold2718
Copy link
Collaborator Author

@mwaxmonsky, I have no problem with your approach. I slapped the bash script together because it is easy (no subprocess stuff to set up and analyze). To make this work, I recognize a consistent approach is best. Do you want me to use (and fix) your script as a substitute for test_fortran_to_metadata.sh?

@mwaxmonsky
Copy link
Collaborator

@mwaxmonsky, I have no problem with your approach. I slapped the bash script together because it is easy (no subprocess stuff to set up and analyze). To make this work, I recognize a consistent approach is best. Do you want me to use (and fix) your script as a substitute for test_fortran_to_metadata.sh?

I would say go with this as is and I can scoop it up into the refactor (or the next one at the current pace) since the test setup isn't a priority and I'm having to work through some other scenarios that will be useful in other places.

The only thing I would suggest is adding this to one of the workflow files as I don't think it is currently run and will be missed in the CI jobs.

@dustinswales
Copy link
Collaborator

@gold2718 Thanks for adding this feature. For the SCM I did something much less elegant for the mpi_Comm type

@gold2718
Copy link
Collaborator Author

The only thing I would suggest is adding this to one of the workflow files

Thanks, done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fix for issue with 'bug' label.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants