tests/utils/python/tjson.py: print actual type when a type error occurs
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 12 Feb 2024 19:01:28 +0000 (14:01 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 19 Feb 2024 18:10:15 +0000 (13:10 -0500)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11781
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
tests/utils/python/tjson.py

index 02a2ca211f2d288eb401c899922020e4750e629f..59a5a1c48e1271c693c08b15dadf8cfbf56f2a98 100644 (file)
@@ -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]
             )
         )
 
This page took 0.025583 seconds and 4 git commands to generate.