[PATCH 01/14] unittests: test_tokenizer: better handle mismatch error

From: Mauro Carvalho Chehab

Date: Wed Mar 18 2026 - 05:17:39 EST


The current logic is too sensitive to how c_lex name is
placed. Also, it doesn't really check the log.

Change it to check if the expected message will be reported
after a call to C tokenizer with an invalid source.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx>
---
tools/unittests/test_tokenizer.py | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/unittests/test_tokenizer.py b/tools/unittests/test_tokenizer.py
index 5634b4a7283e..d1f3c565b9cf 100755
--- a/tools/unittests/test_tokenizer.py
+++ b/tools/unittests/test_tokenizer.py
@@ -46,10 +46,17 @@ def make_tokenizer_test(name, data):
#
# Check if logger is working
#
- if "log_level" in data:
- with self.assertLogs('kdoc.c_lex', level='ERROR') as cm:
+ if "log_msg" in data:
+ with self.assertLogs() as cm:
tokenizer = CTokenizer(data["source"])

+ msg_found = False
+ for result in cm.output:
+ if data["log_msg"] in result:
+ msg_found = True
+
+ self.assertTrue(msg_found, f"Missing log {data['log_msg']}")
+
return

#
@@ -124,7 +131,7 @@ TESTS_TOKENIZER = {

"mismatch_error": {
"source": "int a$ = 5;", # $ is illegal
- "log_level": "ERROR",
+ "log_msg": "Unexpected token",
},
}

--
2.53.0