8000 handle broken links, add test by lukaspie · Pull Request #645 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

handle broken links, add test #645

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

Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/pynxtools/dataconverter/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ def _follow_link(
ValidationProblem.KeyToBeRemoved,
"key",
)
keys_to_remove.append(key_path)
del resolved_keys[key]
else:
resolved_keys[key] = current_keys
Expand Down Expand Up @@ -763,6 +764,10 @@ def is_documented(key: str, tree: NexusNode) -> bool:
if isinstance(mapping[key], dict) and "link" in mapping[key]:
resolved_link = _follow_link({key: mapping[key]}, "")

if key not in resolved_link:
# Link is broken and key will be removed; no need to check further
return False

is_mapping = isinstance(resolved_link[key], Mapping)

if node.type == "group" and not is_mapping:
Expand Down
36 changes: 36 additions & 0 deletions tests/dataconverter/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,24 @@ def listify_template(data_dict: Template):
],
id="field-instead-of-named-group",
),
pytest.param(
alter_dict(
alter_dict(
TEMPLATE,
"/ENTRY[my_entry]/identified_calibration",
{"link": "/my_entry/some_group"},
),
"/ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value",
{"link": "/my_entry/specified_group/some_field"},
),
[
"Broken link at /ENTRY[my_entry]/identified_calibration to /my_entry/some_group.",
"The key /ENTRY[my_entry]/identified_calibration will not be written.",
"Broken link at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value to /my_entry/specified_group/some_field.",
"The key /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value will not be written.",
],
id="appdef-broken-links",
),
pytest.param(
alter_dict(
alter_dict(
Expand Down Expand Up @@ -850,6 +868,24 @@ def listify_template(data_dict: Template):
],
id="appdef-links-with-wrong-nexus-types",
),
pytest.param(
alter_dict(
alter_dict(
TEMPLATE,
"/ENTRY[my_entry]/SAMPLE[my_sample]",
{"link": "/my_entry/some_group"},
),
"/ENTRY[my_entry]/SAMPLE[my_sample2]/name",
{"link": "/my_entry/specified_group/some_field223"},
),
[
"Broken link at /ENTRY[my_entry]/SAMPLE[my_sample] to /my_entry/some_group.",
"The key /ENTRY[my_entry]/SAMPLE[my_sample] will not be written.",
"Broken link at /ENTRY[my_entry]/SAMPLE[my_sample2]/name to /my_entry/specified_group/some_field223.",
"The key /ENTRY[my_entry]/SAMPLE[my_sample2]/name will not be written.",
],
id="baseclass-broken-links",
),
pytest.param(
alter_dict(
alter_dict(
Expand Down
Loading
0