From 3c8d22b32e8253e90e78c32a292e47046de52644 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Thu, 2 Oct 2025 15:11:18 +0800 Subject: [PATCH] Improve code quality across test suite - Fix missing global declaration and copy-paste error in property test - Prevent KeyError for unset environment variables - Add try-finally for robust warning flag handling - Anchor regex pattern for proper color validation --- allnoconfig.py | 8 +++++--- genconfig.py | 2 +- menuconfig.py | 2 +- testsuite.py | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/allnoconfig.py b/allnoconfig.py index de90d8b..83bceb0 100755 --- a/allnoconfig.py +++ b/allnoconfig.py @@ -32,9 +32,11 @@ def main(): # accept 0/1/2, for n/m/y). The assignments will be ignored for other # symbol types, which is what we want. kconf.warn = False - for sym in kconf.unique_defined_syms: - sym.set_value(2 if sym.is_allnoconfig_y else 0) - kconf.warn = True + try: + for sym in kconf.unique_defined_syms: + sym.set_value(2 if sym.is_allnoconfig_y else 0) + finally: + kconf.warn = True kconf.load_allconfig("allno.config") diff --git a/genconfig.py b/genconfig.py index 62f065b..171b329 100755 --- a/genconfig.py +++ b/genconfig.py @@ -138,7 +138,7 @@ def main(): if args.env_list is not None: with _open_write(args.env_list) as f: for env_var in kconf.env_vars: - f.write("{}={}\n".format(env_var, os.environ[env_var])) + f.write("{}={}\n".format(env_var, os.environ.get(env_var, ""))) def _open_write(path): diff --git a/menuconfig.py b/menuconfig.py index 3ad5dfd..cb1fd99 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -555,7 +555,7 @@ def parse_color(color_def): color_def = color_def.split(":", 1)[1] # HTML format, #RRGGBB - if re.match("#[A-Fa-f0-9]{6}", color_def): + if re.match("^#[A-Fa-f0-9]{6}$", color_def): return _color_from_rgb(( int(color_def[1:3], 16), int(color_def[3:5], 16), diff --git a/testsuite.py b/testsuite.py index a4ea556..b533bec 100644 --- a/testsuite.py +++ b/testsuite.py @@ -89,7 +89,7 @@ def verify_equal(x, y): def run_tests(): - global obsessive, log + global obsessive, obsessive_min_config, log for s in sys.argv[1:]: if s == "obsessive": obsessive = True @@ -2379,7 +2379,7 @@ def verify_props(desc, props, prop_names): verify_props("select", c.syms["MULTIDEF"].selects, "AA BB CC DD EE FF GG HH II JJ") - verify_props("imply", c.syms["MULTIDEF"].selects, + verify_props("imply", c.syms["MULTIDEF"].implies, "AA BB CC DD EE FF GG HH II JJ") verify_props("select", c.syms["MULTIDEF_CHOICE"].selects,