Skip to content

Commit c7f5607

Browse files
committed
fix tests
1 parent ec6ee17 commit c7f5607

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/pynxtools/dataconverter/helpers.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,9 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
132132
"and hasn't been supplied by the reader.",
133133
)
134134
elif log_type == ValidationProblem.InvalidType:
135-
type_names = [
136-
f"{t.__module__}.{t.__name__}"
137-
if t.__module__ != "builtins"
138-
else t.__name__
139-
for t in value
140-
]
141135
logger.warning(
142-
f"The value at {path} should be one of the following Python types: "
143-
f"{', '.join(type_names)}, "
144-
f"as defined in the NXDL as {args[0] if args else '<unknown>'}."
136+
f"The value at {path} should be one of the following Python types: {value}"
137+
f", as defined in the NXDL as {args[0] if args else '<unknown>'}."
145138
)
146139
elif log_type == ValidationProblem.InvalidDatetime:
147140
logger.warning(

tests/dataconverter/test_validation.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
from .test_helpers import alter_dict # pylint: disable=unused-import
2929

30+
# Workaround for different str representation of np.bool
31+
if np.lib.NumpyVersion(np.__version__) >= "2.0.0":
32+
np_bool = "numpy.bool"
33+
else:
34+
np_bool = "numpy.bool_"
35+
3036

3137
def set_to_none_in_dict(data_dict: Optional[Template], key: str, optionality: str):
3238
"""Helper function to forcefully set path to 'None'"""
@@ -419,7 +425,7 @@ def listify_template(data_dict: Template):
419425
),
420426
[
421427
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/anamethatRENAMES[anamethatichangetothis]"
422-
" should be one of the following Python types: int, numpy.integer, as defined in "
428+
" should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
423429
"the NXDL as NX_INT."
424430
],
425431
id="variadic-field-str-instead-of-int",
@@ -432,7 +438,7 @@ def listify_template(data_dict: Template):
432438
),
433439
[
434440
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/in"
435-
"t_value should be one of the following Python types: int, numpy.integer, as defined in "
441+
"t_value should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
436442
"the NXDL as NX_INT."
437443
],
438444
id="string-instead-of-int",
@@ -444,7 +450,7 @@ def listify_template(data_dict: Template):
444450
"NOT_TRUE_OR_FALSE",
445451
),
446452
[
447-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/bool_value should be one of the following Python types: bool, numpy.bool, as defined in the NXDL as NX_BOOLEAN."
453+
f"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/bool_value should be one of the following Python types: (<class 'bool'>, <class '{np_bool}'>), as defined in the NXDL as NX_BOOLEAN."
448454
],
449455
id="string-instead-of-bool",
450456
),
@@ -456,7 +462,7 @@ def listify_template(data_dict: Template):
456462
),
457463
[
458464
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should"
459-
" be one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
465+
" be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
460466
],
461467
id="list-of-int-str-instead-of-int",
462468
),
@@ -468,7 +474,7 @@ def listify_template(data_dict: Template):
468474
),
469475
[
470476
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should be"
471-
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
477+
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
472478
],
473479
id="array-of-float-instead-of-int",
474480
),
@@ -520,7 +526,7 @@ def listify_template(data_dict: Template):
520526
np.complex128(0),
521527
),
522528
[
523-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be one of the following Python types: float, numpy.floating, as defined in the NXDL as NX_FLOAT."
529+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be one of the following Python types: (<class 'float'>, <class 'numpy.floating'>), as defined in the NXDL as NX_FLOAT."
524530
],
525531
id="complex-instead-of-float",
526532
),
@@ -531,7 +537,7 @@ def listify_template(data_dict: Template):
531537
"0",
532538
),
533539
[
534-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/number_value should be one of the following Python types: int, numpy.integer, float, numpy.floating, as defined in the NXDL as NX_NUMBER."
540+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/number_value should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>, <class 'float'>, <class 'numpy.floating'>), as defined in the NXDL as NX_NUMBER."
535541
],
536542
id="str-instead-of-number",
537543
),
@@ -543,7 +549,7 @@ def listify_template(data_dict: Template):
543549
),
544550
[
545551
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one"
546-
" of the following Python types: str, numpy.character, as"
552+
" of the following Python types: (<class 'str'>, <class 'numpy.character'>), as"
547553
" defined in the NXDL as NX_CHAR."
548554
],
549555
id="wrong-type-ndarray-instead-of-char",
@@ -627,9 +633,9 @@ def listify_template(data_dict: Template):
627633
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value", 3
628634
),
629635
[
630-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be "
631-
"one of the following Python types: str, numpy.character, "
632-
"as defined in the NXDL as NX_CHAR."
636+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one of the following Python types:"
637+
" (<class 'str'>, <class 'numpy.character'>),"
638+
" as defined in the NXDL as NX_CHAR."
633639
],
634640
id="int-instead-of-chars",
635641
),
@@ -684,7 +690,7 @@ def listify_template(data_dict: Template):
684690
),
685691
[
686692
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be "
687-
"one of the following Python types: float, numpy.floating, as defined in the NXDL "
693+
"one of the following Python types: (<class 'float'>, <class 'numpy.floating'>), as defined in the NXDL "
688694
"as NX_FLOAT."
689695
],
690696
id="array-of-str-instead-of-float",
@@ -1076,7 +1082,7 @@ def listify_template(data_dict: Template):
10761082
),
10771083
[
10781084
"The value at /ENTRY[my_entry]/optional_parent/AXISNAME[optional_child] should be "
1079-
"one of the following Python types: int, numpy.integer, as "
1085+
"one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as "
10801086
"defined in the NXDL as NX_INT."
10811087
],
10821088
id="concept-name-given-for-nonvariadic-field-wrong-type",
@@ -1130,7 +1136,7 @@ def listify_template(data_dict: Template):
11301136
["0", 1, 2],
11311137
),
11321138
[
1133-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT.",
1139+
"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.",
11341140
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]].",
11351141
],
11361142
id="wrong-type-array-in-attribute",
@@ -1438,7 +1444,7 @@ def listify_template(data_dict: Template):
14381444
),
14391445
[
14401446
"The value at /ENTRY[my_entry]/duration should be"
1441-
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
1447+
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
14421448
],
14431449
id="baseclass-wrong-dtype",
14441450
),
@@ -1741,7 +1747,7 @@ def listify_template(data_dict: Template):
17411747
[
17421748
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value "
17431749
"should be one of the following Python types: "
1744-
"int, numpy.integer, as defined in the "
1750+
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
17451751
"NXDL as NX_INT."
17461752
],
17471753
id="appdef-compressed-wrong-type",
@@ -1788,7 +1794,7 @@ def listify_template(data_dict: Template):
17881794
[
17891795
"The value at /ENTRY[my_entry]/SAMPLE[sample1]]/changer_position "
17901796
"should be one of the following Python types: "
1791-
"int, numpy.integer, as defined in the "
1797+
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
17921798
"NXDL as NX_INT."
17931799
],
17941800
id="baseclass-compressed-wrong-type",

0 commit comments

Comments
 (0)