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

Correct validation for required fields in variadic groups #314

Merged
merged 21 commits into from
Apr 26, 2024

Conversation

domna
Copy link
Collaborator

@domna domna commented Apr 18, 2024

Fixes

  • Correct validation of repeating groups inside the template
  • Correct validation of variadic groups with an optional parent

Additions

This adds a Collector class for the validation to collect and log validation problems in one central place. This can be used for a verifier.

Initial problem

Since merging of #310 I get the following error with the mpes example:

LookupError: The data entry, /ENTRY[entry]/INSTRUMENT[instrument]/sourceTYPE[source_probe]/probe,
has an optional parent, /ENTRY[entry]/INSTRUMENT[instrument]/sourceTYPE[sourcetype],
with required children set.
Either provide no children for /ENTRY[entry]/INSTRUMENT[instrument]/sourceTYPE[sourcetype] 
or provide all required ones.

This PR attempts to fix the issue and adds tests for the particular issue

@domna domna requested a review from sherjeelshabih April 19, 2024 14:41
@domna domna marked this pull request as ready for review April 19, 2024 14:41
@domna
Copy link
Collaborator Author

domna commented Apr 19, 2024

@sherjeelshabih The actual problem here is fixed. However, the test do strange things but it's probably that I did something wrong. When I test it with the mpes example it all works as expected now. Nevermind, figured it out

@coveralls
Copy link

coveralls commented Apr 19, 2024

Pull Request Test Coverage Report for Build 8844173385

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 176 of 186 (94.62%) changed or added relevant lines in 3 files are covered.
  • 52 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.7%) to 78.622%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tests/dataconverter/test_helpers.py 28 30 93.33%
pynxtools/dataconverter/helpers.py 142 150 94.67%
Files with Coverage Reduction New Missed Lines %
pynxtools/definitions/dev_tools/utils/nxdl_utils.py 1 74.23%
pynxtools/dataconverter/helpers.py 14 90.89%
pynxtools/dataconverter/template.py 15 86.05%
pynxtools/dataconverter/convert.py 22 75.69%
Totals Coverage Status
Change from base Build 8741788106: 0.7%
Covered Lines: 2784
Relevant Lines: 3541

💛 - Coveralls

@domna
Copy link
Collaborator Author

domna commented Apr 19, 2024

We also have a second problem here:

is_path_in_data_dict, renamed_path = path_in_data_dict(
nxdl_path, tuple(data.keys())
)

The renamed_path only contains the generic path. So if we only write a variation of this in the dict and the generic one is still contained in the dict it reports it as required but missing even though a variation is present.

Also the new field name doesn't end up in the required dict in the Template. I have the following idea: When we insert something in the template it checks if the inserted check is a variation of an already existing key. If this is the case it removes the generic group entirely. That way we make sure that 1. we always have the required keys present if nothing is provided and 2. we don't have to deal with the generic keys if a group with another variadic name has been provided. The rest of the implementation should be able to figure everything out based on the variation. What do you think @sherjeelshabih?

@sherjeelshabih
Copy link
Collaborator

I like this idea. Please give it a try. We also have this func:

def try_undocumented(data, nxdl_root: ET.Element):

If somehow we need a complete Template to correctly place such a field, this func can help. But it's another loop so it will be better to avoid this.

@domna
Copy link
Collaborator Author

domna commented Apr 24, 2024

@sherjeelshabih I got a first version working, which also does the group checking. I still need to clean it up a bit but if you want to have a look already feel free to comment on it already.

Edit: It's cleaned up now and ready to be reviewed

@domna
Copy link
Collaborator Author

domna commented Apr 24, 2024

I also added a collector class so we can actually check whether a validation was successful or not and bundle the logging in one place. This is needed for #133.

@domna domna changed the title Fix retrieval for required fields under optional groups Correct validation for required fields in variadic groups Apr 24, 2024
@domna domna self-assigned this Apr 24, 2024
@domna domna requested a review from sanbrock April 25, 2024 07:54
@domna domna removed the request for review from sherjeelshabih April 25, 2024 07:54
tests/dataconverter/test_helpers.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@sanbrock sanbrock left a comment

Choose a reason for hiding this comment

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

LGTM

@domna domna merged commit c4a9466 into master Apr 26, 2024
7 checks passed
@domna domna deleted the fix-required-under-optional branch April 26, 2024 10:24
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.

4 participants