Skip to content

Commit 31f35dd

Browse files
committed
fix tests
1 parent 0b0bd8a commit 31f35dd

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
@@ -165,16 +165,9 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
165165
elif log_type == ValidationProblem.MissingRequiredAttribute:
166166
logger.warning(f"The required attribute {path} hasn't been supplied.")
167167
elif log_type == ValidationProblem.InvalidType:
168-
type_names = [
169-
f"{t.__module__}.{t.__name__}"
170-
if t.__module__ != "builtins"
171-
else t.__name__
172-
for t in value
173-
]
174168
logger.warning(
175-
f"The value at {path} should be one of the following Python types: "
176-
f"{', '.join(type_names)}, "
177-
f"as defined in the NXDL as {args[0] if args else '<unknown>'}."
169+
f"The value at {path} should be one of the following Python types: {value}"
170+
f", as defined in the NXDL as {args[0] if args else '<unknown>'}."
178171
)
179172
elif log_type == ValidationProblem.InvalidDatetime:
180173
logger.warning(

tests/dataconverter/test_validation.py

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

3333
from .test_helpers import alter_dict # pylint: disable=unused-import
3434

35+
# Workaround for different str representation of np.bool
36+
if np.lib.NumpyVersion(np.__version__) >= "2.0.0":
37+
np_bool = "numpy.bool"
38+
else:
39+
np_bool = "numpy.bool_"
40+
3541

3642
def set_to_none_in_dict(data_dict: Optional[Template], key: str, optionality: str):
3743
"""Helper function to forcefully set path to 'None'"""
@@ -443,7 +449,7 @@ def format_error_message(msg: str) -> str:
443449
),
444450
[
445451
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/anamethatRENAMES[anamethatichangetothis]"
446-
" should be one of the following Python types: int, numpy.integer, as defined in "
452+
" should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
447453
"the NXDL as NX_INT."
448454
],
449455
id="variadic-field-str-instead-of-int",
@@ -456,7 +462,7 @@ def format_error_message(msg: str) -> str:
456462
),
457463
[
458464
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/in"
459-
"t_value should be one of the following Python types: int, numpy.integer, as defined in "
465+
"t_value should be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in "
460466
"the NXDL as NX_INT."
461467
],
462468
id="string-instead-of-int",
@@ -468,7 +474,7 @@ def format_error_message(msg: str) -> str:
468474
"NOT_TRUE_OR_FALSE",
469475
),
470476
[
471-
"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."
477+
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."
472478
],
473479
id="string-instead-of-bool",
474480
),
@@ -480,7 +486,7 @@ def format_error_message(msg: str) -> str:
480486
),
481487
[
482488
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should"
483-
" be one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
489+
" be one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
484490
],
485491
id="list-of-int-str-instead-of-int",
486492
),
@@ -492,7 +498,7 @@ def format_error_message(msg: str) -> str:
492498
),
493499
[
494500
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value should be"
495-
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
501+
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
496502
],
497503
id="array-of-float-instead-of-int",
498504
),
@@ -544,7 +550,7 @@ def format_error_message(msg: str) -> str:
544550
np.complex128(0),
545551
),
546552
[
547-
"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."
553+
"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."
548554
],
549555
id="complex-instead-of-float",
550556
),
@@ -555,7 +561,7 @@ def format_error_message(msg: str) -> str:
555561
"0",
556562
),
557563
[
558-
"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."
564+
"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."
559565
],
560566
id="str-instead-of-number",
561567
),
@@ -567,7 +573,7 @@ def format_error_message(msg: str) -> str:
567573
),
568574
[
569575
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one"
570-
" of the following Python types: str, numpy.character, as"
576+
" of the following Python types: (<class 'str'>, <class 'numpy.character'>), as"
571577
" defined in the NXDL as NX_CHAR."
572578
],
573579
id="wrong-type-ndarray-instead-of-char",
@@ -651,9 +657,9 @@ def format_error_message(msg: str) -> str:
651657
TEMPLATE, "/ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value", 3
652658
),
653659
[
654-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be "
655-
"one of the following Python types: str, numpy.character, "
656-
"as defined in the NXDL as NX_CHAR."
660+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/char_value should be one of the following Python types:"
661+
" (<class 'str'>, <class 'numpy.character'>),"
662+
" as defined in the NXDL as NX_CHAR."
657663
],
658664
id="int-instead-of-chars",
659665
),
@@ -708,7 +714,7 @@ def format_error_message(msg: str) -> str:
708714
),
709715
[
710716
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value should be "
711-
"one of the following Python types: float, numpy.floating, as defined in the NXDL "
717+
"one of the following Python types: (<class 'float'>, <class 'numpy.floating'>), as defined in the NXDL "
712718
"as NX_FLOAT."
713719
],
714720
id="array-of-str-instead-of-float",
@@ -1228,7 +1234,7 @@ def format_error_message(msg: str) -> str:
12281234
),
12291235
[
12301236
"The value at /ENTRY[my_entry]/optional_parent/AXISNAME[optional_child] should be "
1231-
"one of the following Python types: int, numpy.integer, as "
1237+
"one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as "
12321238
"defined in the NXDL as NX_INT."
12331239
],
12341240
id="concept-name-given-for-nonvariadic-field-wrong-type",
@@ -1279,7 +1285,7 @@ def format_error_message(msg: str) -> str:
12791285
["0", 1, 2],
12801286
),
12811287
[
1282-
"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.",
1288+
"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.",
12831289
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type/@array should be one of the following: [[0, 1, 2], [2, 3, 4]].",
12841290
],
12851291
id="wrong-type-array-in-attribute",
@@ -1587,7 +1593,7 @@ def format_error_message(msg: str) -> str:
15871593
),
15881594
[
15891595
"The value at /ENTRY[my_entry]/duration should be"
1590-
" one of the following Python types: int, numpy.integer, as defined in the NXDL as NX_INT."
1596+
" one of the following Python types: (<class 'int'>, <class 'numpy.integer'>), as defined in the NXDL as NX_INT."
15911597
],
15921598
id="baseclass-wrong-dtype",
15931599
),
@@ -1896,7 +1902,7 @@ def format_error_message(msg: str) -> str:
18961902
[
18971903
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/int_value "
18981904
"should be one of the following Python types: "
1899-
"int, numpy.integer, as defined in the "
1905+
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
19001906
"NXDL as NX_INT."
19011907
],
19021908
id="appdef-compressed-wrong-type",
@@ -1943,7 +1949,7 @@ def format_error_message(msg: str) -> str:
19431949
[
19441950
"The value at /ENTRY[my_entry]/SAMPLE[sample1]]/changer_position "
19451951
"should be one of the following Python types: "
1946-
"int, numpy.integer, as defined in the "
1952+
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
19471953
"NXDL as NX_INT."
19481954
],
19491955
id="baseclass-compressed-wrong-type",

0 commit comments

Comments
 (0)