diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2017-10-31 22:34:08 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2017-10-31 23:42:37 +0100 |
| commit | 49a8303ca6e73419a3e26b963f78c61c6ab26d3b (patch) | |
| tree | d6539ebffe9302084376432f6d13ea5097b210ea /testsuite.py | |
| parent | b40a947c533c9560fefa19eef991caa2eeb93614 (diff) | |
Require manual mode setting for choices
Do not change the mode if y is assigned to a choice symbol inside a
choice in m mode, for example. Require Choice.set_value() to be called
instead.
This makes choices way less magical and more menuconfig-like. It would
also be confusing to be able to assign y to a choice symbol when y is
not in sym.assignable.
Set the mode manually in load_config() (y assigned to a choice symbol =>
y mode, and ditto for m). Change the warning for inconsistent values to
one that's probably less confusing, though the old one was closer to the
warning printed by the C implementation.
Need to fix a bunch of tests too...
Diffstat (limited to 'testsuite.py')
| -rw-r--r-- | testsuite.py | 161 |
1 files changed, 78 insertions, 83 deletions
diff --git a/testsuite.py b/testsuite.py index e6d77e3..9ebcef7 100644 --- a/testsuite.py +++ b/testsuite.py @@ -670,12 +670,6 @@ choice <choice CHOICE, tristate, "choice", mode y, user mode y, CHOICE_2 selected, CHOICE_2 selected by user, visibility y, Kconfiglib/tests/Krepr:30> """) - c.syms["CHOICE_1"].set_value(1) - - verify_repr(c.named_choices["CHOICE"], """ -<choice CHOICE, tristate, "choice", mode m, user mode m, CHOICE_2 selected by user (overriden), visibility y, Kconfiglib/tests/Krepr:30> -""") - verify_repr(c.syms["CHOICE_HOOK"].nodes[0].next.item, """ <choice, tristate, "optional choice", mode n, visibility n, optional, Kconfiglib/tests/Krepr:43> """) @@ -867,20 +861,19 @@ g verify_visibility(c.syms["BOOL_CHOICE_N"], 0, 0) # Non-tristate symbols in tristate choices are only visible if the choice - # is in 2 mode - verify_visibility(c.syms["BOOL_CHOICE_M"], 0, 0) + # is in y mode - # Tristate choices start out in m mode. When running without modules, their - # type gets adjusted to bool. - verify_visibility(c.syms["BOOL_CHOICE_Y"], 2, 0) - - c.syms["TRISTATE_CHOICE_M"].set_value(2) - c.syms["TRISTATE_CHOICE_Y"].set_value(2) - - # Still limited by the visibility of the choice + # The choice can't be brought to y mode because of the 'if m' + verify_visibility(c.syms["BOOL_CHOICE_M"], 0, 0) + c.syms["BOOL_CHOICE_M"].choice.set_value(2) verify_visibility(c.syms["BOOL_CHOICE_M"], 0, 0) - # This one should become visible now + # The choice gets y mode only when running without modules, because it + # defaults to m mode + verify_visibility(c.syms["BOOL_CHOICE_Y"], 2, 0) + c.syms["BOOL_CHOICE_Y"].choice.set_value(2) + # When set to y mode, the choice symbol becomes visible both with and + # without modules verify_visibility(c.syms["BOOL_CHOICE_Y"], 2, 2) verify_visibility(c.syms["TRISTATE_IF_N"], 0, 0) @@ -1545,53 +1538,55 @@ g verify(choice.type == BOOL, "choice {} should have type bool".format(choice.name)) + # TODO: Assignment to choice symbols is less magic now. Update these tests. + # TODO: fix this laters. type automatically changed. #for choice in (choice_tristate, choice_tristate_opt, choice_tristate_m): # verify(choice.type == TRISTATE, # "choice {} should have type tristate" # .format(choice.name)) - def select_and_verify(sym): - choice = get_parent(sym) - sym.set_value(2) - verify(choice.str_value == "y", - "The mode of the choice should be y after selecting a symbol") - verify(sym.choice.selection is sym, - "{} should be the selected choice symbol" - .format(sym.name)) - verify(choice.selection is sym, - "{} should be the selected symbol".format(sym.name)) - verify(choice.user_selection is sym, - "{} should be the user selection of the choice" - .format(sym.name)) - - def select_and_verify_all(choice): - # Select in forward order - for sym in choice.syms: - select_and_verify(sym) - # Select in reverse order - for i in range(len(choice.syms) - 1, 0, -1): - select_and_verify(choice.syms[i]) - - def verify_mode(choice, no_modules_mode, modules_mode): - c.modules.set_value(0) - choice_mode = choice.tri_value - verify(choice_mode == no_modules_mode, - 'Wrong mode for choice {} with no modules. Expected {}, got {}.' - .format(choice.name, no_modules_mode, choice_mode)) - - c.modules.set_value(2) - choice_mode = choice.tri_value - verify(choice_mode == modules_mode, - 'Wrong mode for choice {} with modules. Expected {}, got {}.' - .format(choice.name, modules_mode, choice_mode)) - - verify_mode(choice_bool, 2, 2) - verify_mode(choice_bool_opt, 0, 0) - verify_mode(choice_tristate, 2, 1) - verify_mode(choice_tristate_opt, 0, 0) - verify_mode(choice_bool_m, 0, 2) - verify_mode(choice_tristate_m, 0, 1) + #def select_and_verify(sym): + # choice = get_parent(sym) + # sym.set_value(2) + # verify(choice.str_value == "y", + # "The mode of the choice should be y after selecting a symbol") + # verify(sym.choice.selection is sym, + # "{} should be the selected choice symbol" + # .format(sym.name)) + # verify(choice.selection is sym, + # "{} should be the selected symbol".format(sym.name)) + # verify(choice.user_selection is sym, + # "{} should be the user selection of the choice" + # .format(sym.name)) + + #def select_and_verify_all(choice): + # # Select in forward order + # for sym in choice.syms: + # select_and_verify(sym) + # # Select in reverse order + # for i in range(len(choice.syms) - 1, 0, -1): + # select_and_verify(choice.syms[i]) + + #def verify_mode(choice, no_modules_mode, modules_mode): + # c.modules.set_value(0) + # choice_mode = choice.tri_value + # verify(choice_mode == no_modules_mode, + # 'Wrong mode for choice {} with no modules. Expected {}, got {}.' + # .format(choice.name, no_modules_mode, choice_mode)) + + # c.modules.set_value(2) + # choice_mode = choice.tri_value + # verify(choice_mode == modules_mode, + # 'Wrong mode for choice {} with modules. Expected {}, got {}.' + # .format(choice.name, modules_mode, choice_mode)) + + #verify_mode(choice_bool, 2, 2) + #verify_mode(choice_bool_opt, 0, 0) + #verify_mode(choice_tristate, 2, 1) + #verify_mode(choice_tristate_opt, 0, 0) + #verify_mode(choice_bool_m, 0, 2) + #verify_mode(choice_tristate_m, 0, 1) # Test defaults @@ -1611,47 +1606,47 @@ g # Test "y" mode selection - c.modules.set_value(2) + #c.modules.set_value(2) - select_and_verify_all(choice_bool) - select_and_verify_all(choice_bool_opt) - select_and_verify_all(choice_tristate) - select_and_verify_all(choice_tristate_opt) + #select_and_verify_all(choice_bool) + #select_and_verify_all(choice_bool_opt) + #select_and_verify_all(choice_tristate) + #select_and_verify_all(choice_tristate_opt) # For BOOL_M, the mode should have been promoted - select_and_verify_all(choice_bool_m) + #select_and_verify_all(choice_bool_m) # Test "m" mode selection... # ...for a choice that can also be in "y" mode - for sym_name in ("T_1", "T_2"): - assign_and_verify_value(sym_name, 1, 1) - verify(choice_tristate.tri_value == 1, - 'Selecting {} to "m" should have changed the mode of the ' - 'choice to "m"'.format(sym_name)) + #for sym_name in ("T_1", "T_2"): + # assign_and_verify_value(sym_name, 1, 1) + # verify(choice_tristate.tri_value == 1, + # 'Selecting {} to "m" should have changed the mode of the ' + # 'choice to "m"'.format(sym_name)) - assign_and_verify_value(sym_name, 2, 2) - verify(choice_tristate.tri_value == 2 and - choice_tristate.selection is c.syms[sym_name], - 'Selecting {} to "y" should have changed the mode of the ' - 'choice to "y" and made it the selection'.format(sym_name)) + # assign_and_verify_value(sym_name, 2, 2) + # verify(choice_tristate.tri_value == 2 and + # choice_tristate.selection is c.syms[sym_name], + # 'Selecting {} to "y" should have changed the mode of the ' + # 'choice to "y" and made it the selection'.format(sym_name)) # ...for a choice that can only be in "m" mode - for sym_name in ("TM_1", "TM_2"): - assign_and_verify_value(sym_name, 1, 1) - assign_and_verify_value(sym_name, 0, 0) - # "y" should be truncated - assign_and_verify_value(sym_name, 2, 1) - verify(choice_tristate_m.tri_value == 1, - 'A choice that can only be in m mode was not') + #for sym_name in ("TM_1", "TM_2"): + # assign_and_verify_value(sym_name, 1, 1) + # assign_and_verify_value(sym_name, 0, 0) + # # "y" should be truncated + # assign_and_verify_value(sym_name, 2, 1) + # verify(choice_tristate_m.tri_value == 1, + # 'A choice that can only be in m mode was not') # Verify that choices with no explicitly specified type get the type of the # first contained symbol with a type - verify(choice_no_type_bool.type == BOOL, + verify(choice_no_type_bool.orig_type == BOOL, "Expected first choice without explicit type to have type bool") - verify(choice_no_type_tristate.type == TRISTATE, + verify(choice_no_type_tristate.orig_type == TRISTATE, "Expected second choice without explicit type to have type " "tristate") |
