Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
0f46c34
Fix the nx_char type for numpy to and .
RubelMozumder Feb 18, 2025
dd8beb4
Still char instead of the int is being validated which is wrong.
RubelMozumder Feb 19, 2025
351f377
Remove auto conversion for datatype.
RubelMozumder Feb 20, 2025
00b78aa
extends tests.
RubelMozumder Feb 20, 2025
3ad40a0
resolve PR comments
RubelMozumder Feb 27, 2025
6cf6f6d
Remove unnecessary returned value.
RubelMozumder Feb 27, 2025
539bdea
fix np integer and float.
RubelMozumder Feb 27, 2025
cde7a6e
minor change.
RubelMozumder Feb 28, 2025
4ab4b53
check enums for documented fields, and don't return False if any issu…
rettigl Feb 28, 2025
ae10916
add enum checking for attributes
rettigl Feb 18, 2025
8f4291e
Adds parsing code for enumeration tree generation during validation
sherjeelshabih Feb 24, 2025
099b965
Fix typos in old test
sherjeelshabih Feb 24, 2025
4da5735
always check data types and enums, and check NXdata attributes separa…
rettigl Feb 25, 2025
d4f4c2f
fix typos
rettigl Feb 26, 2025
1925d5d
move enum checking into is_valid_data_field, and proper bool conversion
rettigl Feb 28, 2025
ecb4914
satisfy mypy
rettigl Feb 28, 2025
3a1703e
mark namefitted group as undocumented
lukaspie Mar 3, 2025
2fae4de
Merge pull request #565 from FAIRmat-NFDI/fix_check_undocumented
rettigl Mar 4, 2025
4a29251
add tests from branch fix_attribute_enum_check
rettigl Mar 4, 2025
31cd131
add review suggestion
rettigl Mar 5, 2025
ca1ef4f
Merge pull request #573 from FAIRmat-NFDI/add_more_tests
sherjeelshabih Mar 5, 2025
3aabe0b
Fixes the types and removes bytes from NX_char as that creates failures
sherjeelshabih Mar 5, 2025
bd478e8
Fixes for arrays in an array
sherjeelshabih Mar 5, 2025
b336ca5
fix mypy error
rettigl Mar 5, 2025
e9b025e
ruff
rettigl Mar 5, 2025
8c89eef
Applies suggested fix
sherjeelshabih Mar 11, 2025
1c5538d
Update src/pynxtools/dataconverter/helpers.py
sherjeelshabih Mar 11, 2025
365f061
Applies fixes from suggestions
sherjeelshabih Mar 11, 2025
bd250cc
Updates
sherjeelshabih Mar 11, 2025
84426b7
Ruff
sherjeelshabih Mar 11, 2025
5a63c3b
Update src/pynxtools/dataconverter/helpers.py
sherjeelshabih Mar 11, 2025
0d056b7
ruff
sherjeelshabih Mar 11, 2025
70a457c
remove empty string
rettigl Mar 11, 2025
b6b112b
Fixes
sherjeelshabih Mar 11, 2025
467194e
rename original into one of the aux copies
rettigl Mar 13, 2025
65a1774
clean copies
rettigl Mar 13, 2025
a93300f
revert name of original file
rettigl Mar 13, 2025
9023d8d
rename original targets
rettigl Mar 13, 2025
36b6517
rename aux targets
rettigl Mar 13, 2025
ce574a8
combine with renamed
rettigl Mar 13, 2025
d878bf0
restore original target filenames
rettigl Mar 13, 2025
5bba3d3
fix converted tests
rettigl Mar 11, 2025
6520ffa
add additional tests for base class elements
rettigl Mar 11, 2025
67cb8c1
fix validation issues and add further tests
rettigl Mar 12, 2025
25fe60e
add case and tests for undocumented units
rettigl Mar 12, 2025
e719ea8
Merge remote-tracking branch 'origin/fix_validation_and_add_more_test…
rettigl Mar 13, 2025
5a8b46a
Merge remote-tracking branch 'origin/master' into fix_validation_and_…
rettigl Mar 13, 2025
3a4ecd8
reset definitions
rettigl Mar 13, 2025
74bb0da
revert tests and reflog
rettigl Mar 13, 2025
88451d7
update definitions to ref
rettigl Mar 13, 2025
434a626
Merge remote-tracking branch 'origin/fix_validation_and_add_more_test…
rettigl Mar 13, 2025
3cc7a01
update and fix merge errors, add test
rettigl Mar 13, 2025
7de7d5a
revert nomad example test - open enums not working yet
rettigl Mar 13, 2025
3f256a4
don't check for units if no good namefit or a group
rettigl Mar 13, 2025
bdf8997
allow multiple error messages and test for additional error messages
rettigl Mar 14, 2025
eb5f8f6
add test for wrong namefitting
rettigl Mar 14, 2025
802c394
Merge remote-tracking branch 'origin/fix_validation_and_add_more_test…
rettigl Mar 14, 2025
25656bd
trigger workflow
rettigl Mar 14, 2025
8829f06
fix reader tests
rettigl Mar 14, 2025
501537d
catch failing namefitting
rettigl Mar 14, 2025
55397df
tread undocumented units as warning
rettigl Mar 14, 2025
6828e03
require concept_name fornamefitting
lukaspie Mar 14, 2025
a493e1a
add test for namefitting with typo in concept_name
lukaspie Mar 14, 2025
3371825
remove test comment
lukaspie Mar 14, 2025
d317a7e
add proper handling of group attributes
rettigl Mar 14, 2025
a018c9b
add exception for @URL, and run tests on update branch
rettigl Mar 14, 2025
25e0013
prefer direct name match over concept match reliably
rettigl Mar 14, 2025
f24e9e0
streamline best_namefit_of function
lukaspie Mar 17, 2025
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
4 changes: 1 addition & 3 deletions src/pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
value = "<unknown>"

if log_type == ValidationProblem.UnitWithoutDocumentation:
logger.warning(
f"The unit, {path} = {value}, is being written but has no documentation"
)
logger.warning(f"The unit, {path} = {value} written without documentation.")
elif log_type == ValidationProblem.InvalidEnum:
logger.warning(
f"The value at {path} should be on of the following strings: {value}"
Expand Down
36 changes: 21 additions & 15 deletions src/pynxtools/dataconverter/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def split_class_and_name_of(name: str) -> Tuple[Optional[str], str]:
), f"{name_match.group(2)}{'' if prefix is None else prefix}"


def best_namefit_of(name: str, keys: Iterable[str]) -> Optional[str]:
def best_namefit_of(name: str, keys: Iterable[str]) -> Tuple[Optional[str], bool]:
"""
Get the best namefit of `name` in `keys`.

Expand All @@ -143,25 +143,26 @@ def best_namefit_of(name: str, keys: Iterable[str]) -> Optional[str]:
keys (Iterable[str]): The keys to fit `name` against.

Returns:
Optional[str]: The best fitting key. None if no fit was found.
Tuple[Optional[str], bool]: A tuple where the first element is the best fitting key (or None if no fit was found),
and the second element is a boolean indicating if the match was exact.
"""

if not keys:
return None
return None, True

nx_name, name2fit = split_class_and_name_of(name)

if name2fit in keys:
return name2fit
return name2fit, True
if nx_name is not None and nx_name in keys:
return nx_name

return nx_name, True
best_match, score = max(
map(lambda x: (x, get_nx_namefit(name2fit, x)), keys), key=lambda x: x[1]
)
if score < 0:
return None
return None, False

return best_match
return best_match, False


def validate_dict_against(
Expand Down Expand Up @@ -209,6 +210,7 @@ def get_variations_of(node: NexusNode, keys: Mapping[str, Any]) -> List[str]:
and key not in node.parent.get_all_direct_children_names()
):
variations.append(key)

if nx_name is not None and not variations:
collector.collect_and_log(
nx_name, ValidationProblem.FailedNamefitting, keys
Expand Down Expand Up @@ -342,6 +344,7 @@ def handle_group(node: NexusGroup, keys: Mapping[str, Any], prev_path: str):
None,
)
return

for variant in variants:
if variant in [node.name for node in node.parent_of]:
# Don't process if this is actually a sub-variant of this group
Expand Down Expand Up @@ -511,12 +514,15 @@ def is_documented(key: str, node: NexusNode) -> bool:

for name in key[1:].replace("@", "").split("/"):
children = node.get_all_direct_children_names()
best_name = best_namefit_of(name, children)
best_name, good_name_fit = best_namefit_of(name, children)
if best_name is None:
return False

node = node.search_add_child_for(best_name)

if not good_name_fit:
return False

if isinstance(mapping[key], dict) and "link" in mapping[key]:
# TODO: Follow link and check consistency with current field
return True
Expand Down Expand Up @@ -755,12 +761,12 @@ def startswith_with_variations(
ValidationProblem.UnitWithoutField,
not_visited_key.rsplit("/", 1)[0],
)
if not ignore_undocumented:
collector.collect_and_log(
not_visited_key,
ValidationProblem.UnitWithoutDocumentation,
mapping[not_visited_key],
)
# if not ignore_undocumented:
# collector.collect_and_log(
# not_visited_key,
# ValidationProblem.UnitWithoutDocumentation,
# mapping[not_visited_key],
# )
Comment thread
lukaspie marked this conversation as resolved.
Outdated
if is_documented(not_visited_key, tree):
continue

Expand Down
14 changes: 9 additions & 5 deletions tests/dataconverter/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_data_dict():
"/ENTRY[my_entry]/OPTIONAL_group[my_group]/optional_field": 1,
"/ENTRY[my_entry]/required_group/description": "An example description",
"/ENTRY[my_entry]/required_group2/description": "An example description",
"/ENTRY[my_entry]/optional_parent/req_group_in_opt_group/data": 1,
"/ENTRY[my_entry]/optional_parent/req_group_in_opt_group/DATA[data]": 1,
"/@default": "Some NXroot attribute",
}

Expand All @@ -86,21 +86,25 @@ def alter_dict(new_values: Dict[str, Any], data_dict: Dict[str, Any]) -> Dict[st


@pytest.mark.parametrize(
"data_dict",
"data_dict, ignore_undocumented",
[
pytest.param(get_data_dict(), id="valid-unaltered-data-dict"),
pytest.param(get_data_dict(), True, id="valid-unaltered-data-dict"),
pytest.param(
remove_from_dict(
"/ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value_no_attr",
get_data_dict(),
),
False,
id="removed-optional-value",
),
],
)
def test_valid_data_dict(caplog, data_dict):
def test_valid_data_dict(caplog, data_dict, ignore_undocumented):
with caplog.at_level(logging.WARNING):
assert validate_dict_against("NXtest", data_dict)[0]
assert validate_dict_against(
"NXtest", data_dict, ignore_undocumented=ignore_undocumented
)[0]

assert caplog.text == ""


Expand Down