Skip to content

Commit 96c6f8c

Browse files
committed
reorganize error messages
1 parent 456825d commit 96c6f8c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/pynxtools/dataconverter/helpers.py

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

155155
elif log_type == ValidationProblem.InvalidEnum:
156156
logger.warning(
157-
f"The value '{args[0]}' at {path} should be one of the following: {value}."
157+
f"The value {args[0]} at {path} should be one of the following: {value}."
158158
)
159159
elif log_type == ValidationProblem.OpenEnumWithCustom:
160160
logger.info(
161161
f"The value '{args[0]}' at {path} does not match with the enumerated items from the open enumeration: {value}."
162162
)
163163
elif log_type == ValidationProblem.OpenEnumWithCustomFalse:
164164
logger.warning(
165-
f"The value '{args[0]}' at {path} does not match with the enumerated items from the open enumeration: {value}."
165+
f"The value '{args[0]}' at {path} does not match with the enumerated items from the open enumeration: {value}. "
166166
"When a different value is used, the boolean 'custom' attribute cannot be False."
167167
)
168168
elif log_type == ValidationProblem.OpenEnumWithMissingCustom:

tests/dataconverter/test_validation.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,9 @@ def format_error_message(msg: str) -> str:
862862
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/type", "Wrong option"
863863
),
864864
[
865-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type should "
866-
"be one of the following"
867-
": ['1st type', '2nd type', '3rd type', '4th type']."
865+
"The value Wrong option at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type "
866+
"should be one of the following: "
867+
"['1st type', '2nd type', '3rd type', '4th type']."
868868
],
869869
id="wrong-enum-choice",
870870
),
@@ -961,10 +961,12 @@ def format_error_message(msg: str) -> str:
961961
[
962962
"The value 'a very different type' at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type2 does not match "
963963
"with the enumerated items from the open enumeration: ['1st type open', '2nd type open']. "
964-
"When a different value is used, a boolean 'custom' attribute must be added.",
964+
"When a different value is used, a boolean 'custom=True' attribute must be added. "
965+
"It was added here automatically.",
965966
"The value '3rd option' at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type2/@attribute_with_open_enum "
966967
"does not match with the enumerated items from the open enumeration: ['1st option', '2nd option']. "
967-
"When a different value is used, a boolean 'custom' attribute must be added.",
968+
"When a different value is used, a boolean 'custom=True' attribute must be added. "
969+
"It was added here automatically.",
968970
],
969971
id="open-enum-with-new-item-custom-missing",
970972
),
@@ -1369,7 +1371,7 @@ def format_error_message(msg: str) -> str:
13691371
),
13701372
[
13711373
"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.",
1372-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]].",
1374+
"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]].",
13731375
],
13741376
id="wrong-type-array-in-attribute",
13751377
),
@@ -1378,7 +1380,7 @@ def format_error_message(msg: str) -> str:
13781380
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array", [1, 2]
13791381
),
13801382
[
1381-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]]."
1383+
"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]]."
13821384
],
13831385
id="wrong-value-array-in-attribute",
13841386
),
@@ -1722,7 +1724,7 @@ def format_error_message(msg: str) -> str:
17221724
"Cu",
17231725
),
17241726
[
1725-
"The value at /ENTRY[my_entry]/INSTRUMENT[my_instrument]/SOURCE[my_source]/target_material "
1727+
"The value Cu at /ENTRY[my_entry]/INSTRUMENT[my_instrument]/SOURCE[my_source]/target_material "
17261728
"should be one of the following: ['Ta', 'W', 'depleted_U', 'enriched_U', 'Hg', 'Pb', 'C']."
17271729
],
17281730
id="baseclass-wrong-enum",
@@ -2056,6 +2058,7 @@ def test_validate_data_dict(data_dict, error_messages, caplog, request):
20562058
"baseclass-field-with-illegal-unit",
20572059
"open-enum-with-new-item",
20582060
"open-enum-with-new-item-compressed",
2061+
"open-enum-with-new-item-custom-missing",
20592062
"baseclass-open-enum-with-new-item",
20602063
"appdef-compressed-strength-0",
20612064
):

0 commit comments

Comments
 (0)