diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2013-08-07 02:05:18 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2013-08-07 02:08:06 +0200 |
| commit | 06309e301b0008605c4f2c5ad1d3a07276e3865c (patch) | |
| tree | b5c617042179ca83351abd2b273626ef452daae7 | |
| parent | 4f7b2b25dbb66369b8099f596b4593956e9d1cc9 (diff) | |
Add Symbol and Choice interfaces for getting prompt strings.
| -rw-r--r-- | kconfiglib.py | 21 | ||||
| -rw-r--r-- | tests/Kprompt | 77 | ||||
| -rw-r--r-- | testsuite.py | 42 |
3 files changed, 140 insertions, 0 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 0704cc0..743d48f 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2495,6 +2495,16 @@ class Symbol(Item, _HasVisibility): """Returns the name of the symbol.""" return self.name + def get_prompts(self): + """Returns a list of prompts defined for the symbol, in the order they + appear in the configuration files. Returns the empty list for symbols + with no prompt. + + This list will have a single entry for the vast majority of symbols + having prompts, but having multiple prompts for a single symbol is + possible through having multiple 'config' entries for it.""" + return [prompt for prompt, _ in self.orig_prompts] + def get_upper_bound(self): """For string/hex/int symbols and for bool and tristate symbols that cannot be modified (see is_modifiable()), returns None. @@ -3230,6 +3240,17 @@ class Choice(Item, _HasVisibility): as of Linux 3.7.0-rc8.""" return self.name + def get_prompts(self): + """Returns a list of prompts defined for the choice, in the order they + appear in the configuration files. Returns the empty list for choices + with no prompt. + + This list will have a single entry for the vast majority of choices + having prompts, but having multiple prompts for a single choice is + possible through having multiple 'choice' entries for it (though I'm + not sure if that ever happens in practice).""" + return [prompt for prompt, _ in self.orig_prompts] + def get_help(self): """Returns the help text of the choice, or None if the choice has no help text.""" diff --git a/tests/Kprompt b/tests/Kprompt new file mode 100644 index 0000000..a36a0fd --- /dev/null +++ b/tests/Kprompt @@ -0,0 +1,77 @@ +config NO_PROMPT + tristate + +config SINGLE_PROMPT_1 + bool "single prompt 1" + +config SINGLE_PROMPT_2 + bool + prompt "single prompt 2" if n + +config MULTI_PROMPT + bool "ignored prompt" + prompt "prompt 1" +config MULTI_PROMPT + bool "prompt 2" +config MULTI_PROMPT + bool +config MULTI_PROMPT + bool + prompt "prompt 3" +config MULTI_PROMPT + bool + prompt "ignored prompt" + prompt "ignored prompt 2" if y + prompt "prompt 4" if y + +choice NO_PROMPT_CHOICE + tristate +config A + bool +config B + bool +endchoice + +choice SINGLE_PROMPT_1_CHOICE + bool "single prompt 1 choice" +config C + bool +config D + bool +endchoice + +choice SINGLE_PROMPT_2_CHOICE + bool "ignored prompt" + prompt "single prompt 2 choice" +config E + bool +config F + bool +endchoice + +choice MULTI_PROMPT_CHOICE + bool "prompt 1 choice" +config G + bool +config H + bool +endchoice + +choice MULTI_PROMPT_CHOICE + bool + prompt "prompt 2 choice" +config I + bool +config J + bool +endchoice + +choice MULTI_PROMPT_CHOICE + bool + prompt "ignored prompt" + prompt "prompt 3 choice" +config K + bool +config L + bool +endchoice diff --git a/testsuite.py b/testsuite.py index 5cbd4e8..be0082e 100644 --- a/testsuite.py +++ b/testsuite.py @@ -412,6 +412,46 @@ def run_selftests(): verify_equals(c.get_menus()[0].get_title(), "a menu") # + # Prompt queries + # + + print "Testing prompt queries..." + + def verify_prompts(sym_or_choice, prompts): + sym_or_choice_prompts = sym_or_choice.get_prompts() + verify(len(sym_or_choice_prompts) == len(prompts), + "Wrong number of prompts for " + sym_or_choice.get_name()) + for i in range(0, len(sym_or_choice_prompts)): + verify(sym_or_choice_prompts[i] == prompts[i], + "Prompt {0} wrong for {1}: Was '{2}', should be '{3}'". + format(i, sym_or_choice.get_name(), sym_or_choice_prompts[i], + prompts[i])) + + def verify_sym_prompts(sym_name, *prompts): + verify_prompts(c[sym_name], prompts) + + def verify_choice_prompts(choice, *prompts): + verify_prompts(choice, prompts) + + c = kconfiglib.Config("Kconfiglib/tests/Kprompt") + + # Symbols + verify_sym_prompts("NO_PROMPT") + verify_sym_prompts("SINGLE_PROMPT_1", "single prompt 1") + verify_sym_prompts("SINGLE_PROMPT_2", "single prompt 2") + verify_sym_prompts("MULTI_PROMPT", "prompt 1", "prompt 2", "prompt 3", "prompt 4") + + no_prompt_choice, single_prompt_1_choice, single_prompt_2_choice, multi_prompt_choice = \ + c.get_choices() + + # Choices + verify_choice_prompts(no_prompt_choice) + verify_choice_prompts(single_prompt_1_choice, "single prompt 1 choice") + verify_choice_prompts(single_prompt_2_choice, "single prompt 2 choice") + verify_choice_prompts(multi_prompt_choice, + "prompt 1 choice", "prompt 2 choice", "prompt 3 choice") + + # # Location queries # @@ -1704,6 +1744,7 @@ def test_call_all(conf): s.get_lower_bound() s.get_name() s.get_parent() + s.get_prompts() s.get_ref_locations() s.get_referenced_symbols() s.get_referenced_symbols(True) @@ -1763,6 +1804,7 @@ def test_call_all(conf): c.get_mode() c.get_name() c.get_parent() + c.get_prompts() c.get_referenced_symbols() c.get_referenced_symbols(True) c.get_selection() |
