Skip to content

Commit 6a5d057

Browse files
committed
reorganize error messages
1 parent 0986b0a commit 6a5d057

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/pynxtools/dataconverter/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
119119

120120
elif log_type == ValidationProblem.InvalidEnum:
121121
logger.warning(
122-
f"The value '{args[0]}' at {path} should be one of the following: {value}."
122+
f"The value {args[0]} at {path} should be one of the following: {value}."
123123
)
124124
elif log_type == ValidationProblem.OpenEnumWithCustom:
125125
logger.info(
126126
f"The value '{args[0]}' at {path} does not match with the enumerated items from the open enumeration: {value}."
127127
)
128128
elif log_type == ValidationProblem.OpenEnumWithCustomFalse:
129129
logger.warning(
130-
f"The value '{args[0]}' at {path} does not match with the enumerated items from the open enumeration: {value}."
130+
f"The value '{args[0]}' at {path} does not match with the enumerated items from the open enumeration: {value}. "
131131
"When a different value is used, the boolean 'custom' attribute cannot be False."
132132
)
133133
elif log_type == ValidationProblem.OpenEnumWithMissingCustom:

src/pynxtools/dataconverter/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def is_valid_enum(
12731273
)
12741274

12751275
elif custom_attr is None:
1276-
mapping[path] = True
1276+
mapping[custom_path] = True
12771277
collector.collect_and_log(
12781278
path,
12791279
ValidationProblem.OpenEnumWithMissingCustom,

tests/dataconverter/test_validation.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ def listify_template(data_dict: Template):
824824
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/type", "Wrong option"
825825
),
826826
[
827-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type should "
828-
"be one of the following"
829-
": ['1st type', '2nd type', '3rd type', '4th type']."
827+
"The value Wrong option at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type "
828+
"should be one of the following: "
829+
"['1st type', '2nd type', '3rd type', '4th type']."
830830
],
831831
id="wrong-enum-choice",
832832
),
@@ -923,10 +923,12 @@ def listify_template(data_dict: Template):
923923
[
924924
"The value 'a very different type' at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type2 does not match "
925925
"with the enumerated items from the open enumeration: ['1st type open', '2nd type open']. "
926-
"When a different value is used, a boolean 'custom' attribute must be added.",
926+
"When a different value is used, a boolean 'custom=True' attribute must be added. "
927+
"It was added here automatically.",
927928
"The value '3rd option' at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type2/@attribute_with_open_enum "
928929
"does not match with the enumerated items from the open enumeration: ['1st option', '2nd option']. "
929-
"When a different value is used, a boolean 'custom' attribute must be added.",
930+
"When a different value is used, a boolean 'custom=True' attribute must be added. "
931+
"It was added here automatically.",
930932
],
931933
id="open-enum-with-new-item-custom-missing",
932934
),
@@ -1219,7 +1221,7 @@ def listify_template(data_dict: Template):
12191221
),
12201222
[
12211223
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT.",
1222-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]].",
1224+
"The value ['0', 1, 2] at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]].",
12231225
],
12241226
id="wrong-type-array-in-attribute",
12251227
),
@@ -1228,7 +1230,7 @@ def listify_template(data_dict: Template):
12281230
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array", [1, 2]
12291231
),
12301232
[
1231-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]]."
1233+
"The value [1, 2] at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]]."
12321234
],
12331235
id="wrong-value-array-in-attribute",
12341236
),
@@ -1560,7 +1562,7 @@ def listify_template(data_dict: Template):
15601562
"Cu",
15611563
),
15621564
[
1563-
"The value at /ENTRY[my_entry]/INSTRUMENT[my_instrument]/SOURCE[my_source]/target_material "
1565+
"The value Cu at /ENTRY[my_entry]/INSTRUMENT[my_instrument]/SOURCE[my_source]/target_material "
15641566
"should be one of the following: ['Ta', 'W', 'depleted_U', 'enriched_U', 'Hg', 'Pb', 'C']."
15651567
],
15661568
id="baseclass-wrong-enum",
@@ -1906,6 +1908,7 @@ def format_error_message(msg: str) -> str:
19061908
"baseclass-field-with-illegal-unit",
19071909
"open-enum-with-new-item",
19081910
"open-enum-with-new-item-compressed",
1911+
"open-enum-with-new-item-custom-missing",
19091912
"baseclass-open-enum-with-new-item",
19101913
"appdef-compressed-strength-0",
19111914
):

0 commit comments

Comments
 (0)