8000 Throw warning for variadic notation for non-variadic names by lukaspie · Pull Request #591 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Throw warning for variadic notation for non-variadic names #591

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

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/pynxtools/data/NXtest.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
</group>
<group name="identified_calibration" type="NXcalibration" optional="true">
<field name="identifier_1"/>
<field name="identifier_2" optional="True"/>
</group>
<group name="named_collection" type="NXcollection" optional="true"/>
</group>
Expand Down
7 changes: 7 additions & 0 deletions src/pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ValidationProblem(Enum):
NXdataMissingAxisData = 19
NXdataAxisMismatch = 20
KeyToBeRemoved = 21
InvalidConceptForNonVariadic = 22


class Collector:
Expand Down Expand Up @@ -151,6 +152,12 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
elif log_type == ValidationProblem.KeyToBeRemoved:
logger.warning(f"The attribute {path} will not be written.")

elif log_type == ValidationProblem.InvalidConceptForNonVariadic:
log_text = f"Given {value.type} name '{path}' conflicts with the non-variadic name '{value}'"
if value.type == "group":
log_text += f", which should be of type {value.nx_class}."
logger.warning(log_text)

def collect_and_log(
self,
path: str,
Expand Down
16 changes: 16 additions & 0 deletions src/pynxtools/dataconverter/validation.py
10000
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ def best_namefit_of(name: str, nodes: Iterable[NexusNode]) -> Optional[NexusNode
for node in nodes:
if not node.variadic:
if instance_name == node.name:
if concept_name and concept_name != node.name:
if node.type == "group":
if concept_name != node.nx_class[2:].upper():
collector.collect_and_log(
concept_name,
ValidationProblem.InvalidConceptForNonVariadic,
node,
)
return None
else:
collector.collect_and_log(
concept_name,
ValidationProblem.InvalidConceptForNonVariadic,
node,
)
return None
return node
else:
if concept_name and concept_name == node.name:
Expand Down
69 changes: 63 additions & 6 deletions tests/dataconverter/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,32 @@ def listify_template(data_dict: Template):
[],
id="no-child-provided-optional-parent",
),
pytest.param(
alter_dict(
remove_from_dict(
remove_from_dict(
remove_from_dict(
TEMPLATE,
"/ENTRY[my_entry]/specified_group/specified_field",
"required",
),
"/ENTRY[my_entry]/specified_group/specified_field/@specified_attr_in_field",
"required",
),
"/ENTRY[my_entry]/specified_group/@specified_attr",
"required",
),
"/ENTRY[my_entry]/SAMPLE[specified_group]/specified_field",
1.0,
),
[
"The required group, /ENTRY[my_entry]/specified_group, hasn't been supplied.",
"Given group name 'SAMPLE' conflicts with the non-variadic name 'specified_group (req)', "
"which should be of type NXdata.",
"Field /ENTRY[my_entry]/SAMPLE[specified_group]/specified_field written without documentation.",
],
id="illegal-concept-name-for-nonvariadic-group",
),
pytest.param(
alter_dict(
remove_from_dict(
Expand All @@ -729,10 +755,13 @@ def listify_template(data_dict: Template):
"/ENTRY[my_entry]/optional_parent/AXISNAME[required_child]",
1,
),
# ToDo: should not raise a warning if sibling inheritance works
# TODO: should not raise a warning if sibling inheritance works
[
"The data entry corresponding to /ENTRY[my_entry]/optional_parent/"
"required_child is required and hasn't been supplied by the reader."
"required_child is required and hasn't been supplied by the reader.",
"Given field name 'AXISNAME' conflicts with the non-variadic name "
"'required_child (req)'",
"Field /ENTRY[my_entry]/optional_parent/AXISNAME[required_child] written without documentation.",
],
id="concept-name-given-for-nonvariadic-field",
),
Expand All @@ -747,9 +776,12 @@ def listify_template(data_dict: Template):
"test value",
),
[
"The value at /ENTRY[my_entry]/optional_parent/AXISNAME[optional_child] should be "
"one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as "
"defined in the NXDL as NX_INT."
"Given field name 'AXISNAME' conflicts with the non-variadic name 'optional_child (opt)'",
"Field /ENTRY[my_entry]/optional_parent/AXISNAME[optional_child] written without documentation.",
# TODO: reactivate if sibling inheritance works
# # "The value at /ENTRY[my_entry]/optional_parent/AXISNAME[optional_child] should be "
# "one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as "
# "defined in the NXDL as NX_INT."
],
id="concept-name-given-for-nonvariadic-field-wrong-type",
),
Expand Down Expand Up @@ -1053,7 +1085,7 @@ def listify_template(data_dict: Template):
"123",
),
[],
id="specified-identifier-with-type",
id="specified-identifier-without-type",
),
# ToDo: reactivate if sibling inheritance works properly
# pytest.param(
Expand Down Expand Up @@ -1095,6 +1127,31 @@ def listify_template(data_dict: Template):
[],
id="name-fitted-identifier-with-type",
),
pytest.param(
alter_dict(
TEMPLATE,
"/ENTRY[my_entry]/CALIBRATION[identified_calibration]/identifier_1",
"123",
),
[],
id="group-with-correct-concept",
),
pytest.param(
alter_dict(
alter_dict(
TEMPLATE,
"/ENTRY[my_entry]/CALIBRATION[identified_calibration]/identifier_1",
"123",
),
"/ENTRY[my_entry]/identified_calibration/identifier_2",
"456",
),
[
"The data entry corresponding to /ENTRY[my_entry]/identified_calibration/identifier_1 is required "
"and hasn't been supplied by the reader."
],
id="group-with-correct-concept-and-non-concept-sibling",
),
# This can be re-used later when we have proper unit checking
pytest.param(
alter_dict(
Expand Down
Loading
0