From 6ef362c490bc2608c971eeabd5930ea0d8893dbe Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 26 Mar 2018 15:12:09 +0200 Subject: Refactor expr_str() cases - Detect Symbol directly instead of as (not tuple) + (not choice) - Test explicitly for a tuple (non-Symbol) in NOT - Add some tests to get better coverage for NOT and parentheses --- kconfiglib.py | 21 +++++++++------------ tests/Kstr | 3 +-- testsuite.py | 3 +-- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index ed945ca..46da1c1 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4106,23 +4106,20 @@ def expr_str(expr): Passing subexpressions of expressions to this function works as expected. """ - if not isinstance(expr, tuple): - if isinstance(expr, Choice): - if expr.name is not None: - return "".format(expr.name) - return "" - - # Symbol - + if isinstance(expr, Symbol): if expr.is_constant: return '"{}"'.format(escape(expr.name)) - return expr.name + if isinstance(expr, Choice): + if expr.name is not None: + return "".format(expr.name) + return "" + if expr[0] == NOT: - if isinstance(expr[1], Symbol): - return "!" + expr_str(expr[1]) - return "!({})".format(expr_str(expr[1])) + if isinstance(expr[1], tuple): + return "!({})".format(expr_str(expr[1])) + return "!" + expr_str(expr[1]) # Symbol if expr[0] == AND: return "{} && {}".format(_format_and_op(expr[1]), diff --git a/tests/Kstr b/tests/Kstr index 0948b11..2498a74 100644 --- a/tests/Kstr +++ b/tests/Kstr @@ -30,8 +30,7 @@ config ADVANCED prompt "prompt 2" menuconfig ADVANCED - prompt "prompt 3" - depends on DEP2 + prompt "prompt 3" if DEP2 && (DEP3 || !DEP4 || !(DEP5 && DEP6)) if DEP3 diff --git a/testsuite.py b/testsuite.py index 7617226..9177efd 100644 --- a/testsuite.py +++ b/testsuite.py @@ -528,8 +528,7 @@ config ADVANCED prompt "prompt 2" menuconfig ADVANCED - prompt "prompt 3" if DEP2 - depends on DEP2 + prompt "prompt 3" if DEP2 && (DEP3 || !DEP4 || !(DEP5 && DEP6)) config ADVANCED depends on DEP4 && DEP3 -- cgit v1.2.3