From bf36f5de0f49d56975b1a844e25484ec385dc971 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 3 Jun 2019 01:55:50 +0200 Subject: Improve warning control API (with backwards compatibility) A wart of the warning control API (enable/disable_*_warnings()) is that the current warning settings can't be queried. Querying warning settings is useful in functions that want to temporarily enable/disable some warning and then put things back to how they were. kconfiglib.load_allconfig() ran into this, for example. Make the internal warning control variables public (improve the naming at the same time), and encourage just setting them directly. Keep the old API for backwards compatibility. Also remove _warn_redun_assign() and _warn_override(). They're trivial and were called in a single place. --- testsuite.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'testsuite.py') diff --git a/testsuite.py b/testsuite.py index 376f165..8e17d84 100644 --- a/testsuite.py +++ b/testsuite.py @@ -356,7 +356,7 @@ def run_selftests(): verify_eval('"foo" = "foo"', 2) # Undefined symbols get their name as their value - c.disable_warnings() + c.warn = False verify_eval("'not_defined' = not_defined", 2) verify_eval("not_defined_2 = not_defined_2", 2) verify_eval("not_defined_1 != not_defined_2", 2) @@ -957,20 +957,21 @@ config DEP_REM_CORNER_CASES print("Testing Kconfig.__repr__()") verify_repr(c, """ - + """) os.environ["srctree"] = "Kconfiglib" os.environ["CONFIG_"] = "CONFIG_ value" c = Kconfig("tests/Krepr", warn=False) - c.enable_warnings() - c.disable_stderr_warnings() - c.disable_redun_warnings() - c.enable_undef_warnings() + c.warn = True + c.warn_to_stderr = False + c.warn_assign_override = False + c.warn_assign_redun = False + c.warn_assign_undef = True verify_repr(c, """ - + """) os.environ.pop("srctree", None) @@ -1311,7 +1312,7 @@ tests/Krecursive2:1 print("Testing split_expr()") c = Kconfig("Kconfiglib/tests/empty") - c.disable_warnings() + c.warn = False def verify_split(to_split, op, operand_strs): # The same hackage as in Kconfig.eval_string() @@ -1630,7 +1631,7 @@ tests/Krecursive2:1 # User values and dependent ranges # Avoid warnings for assigning values outside the active range - c.disable_warnings() + c.warn = False def verify_range(sym_name, low, high, default): # Verifies that all values in the range 'low'-'high' can be assigned, @@ -1760,7 +1761,7 @@ tests/Krecursive2:1 # Avoid warnings from assigning invalid user values and assigning user # values to symbols without prompts - c.disable_warnings() + c.warn = False syms = [c.syms[name] for name in ("BOOL", "TRISTATE", "STRING", "INT", "HEX")] @@ -2803,6 +2804,8 @@ def test_sanity(arch, srcarch): kconf.modules kconf.defconfig_list kconf.defconfig_filename + + # Legacy warning functions kconf.enable_redun_warnings() kconf.disable_redun_warnings() kconf.enable_undef_warnings() @@ -2811,6 +2814,7 @@ def test_sanity(arch, srcarch): kconf.disable_warnings() kconf.enable_stderr_warnings() kconf.disable_stderr_warnings() + kconf.mainmenu_text kconf.unset_values() @@ -2843,7 +2847,7 @@ def test_sanity(arch, srcarch): sym.set_value(2) sym.set_value("foo") sym.unset_value() - kconf.enable_warnings() + kconf.enable_warnings() # Legacy warning function sym.str_value sym.tri_value sym.type @@ -2881,7 +2885,7 @@ def test_sanity(arch, srcarch): sym.set_value(2) sym.set_value("foo") sym.unset_value() - kconf.enable_warnings() + kconf.enable_warnings() # Legacy warning function sym.str_value sym.tri_value sym.type -- cgit v1.2.3