From e45fa35b841ef375a2911ff89f19c8dd68dcaec6 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 12 Feb 2024 14:01:28 -0500 Subject: [PATCH] tests/utils/python/tjson.py: print actual type when a type error occurs Make `_check_type` output the actual type in addition to the expected type. Example: Before: # TypeError: `.[0]."cond-id"`: expecting a string value After: # TypeError: `.[0]."cond-id"`: expecting a string value, got an array Change-Id: I9615aa380b12fe5e7fd65b079840b779f9530f3a Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11781 Reviewed-by: Philippe Proulx Tested-by: jenkins --- tests/utils/python/tjson.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/utils/python/tjson.py b/tests/utils/python/tjson.py index 02a2ca21..59a5a1c4 100644 --- a/tests/utils/python/tjson.py +++ b/tests/utils/python/tjson.py @@ -219,8 +219,10 @@ class ObjVal(Val, Mapping[str, Val]): def _check_type(val: Val, expected_type: Type[Val]): if not isinstance(val, expected_type): raise TypeError( - "`{}`: expecting {} value".format( - val.path, expected_type._name # pyright: ignore [reportPrivateUsage] + "`{}`: expecting {} value, got {}".format( + val.path, + expected_type._name, # pyright: ignore [reportPrivateUsage] + type(val)._name, # pyright: ignore [reportPrivateUsage] ) ) -- 2.34.1