From fe17f546b5cd5fd8b9df7d53856efd7b207faa0e Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 25 Sep 2017 17:19:09 +0200 Subject: Don't set defaults that will always be overwritten The constructors previously defaulted all properties. This is dead code for properties that are always set on items from outside during parsing, and obfuscates the code flow and wastes time. Instead, just mention other properties that exist in comments in the constructors. Also add test cases for missing and empty 'choice' help texts. Removing the default 'self._help = None' assignment in Choice.__init__() wasn't caught by the selftests. --- testsuite.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'testsuite.py') diff --git a/testsuite.py b/testsuite.py index b193414..9d364c8 100644 --- a/testsuite.py +++ b/testsuite.py @@ -553,6 +553,9 @@ def run_selftests(): c.set_print_warnings(False) c.set_print_undef_assign(True) + choice_print, choice_no_help, choice_empty_help, choice_help = \ + c.get_choices() + verify_print(c, """ Configuration File : Kconfiglib/tests/Ktext @@ -689,7 +692,7 @@ def run_selftests(): # Printing of Choice - verify_print(c.get_choices()[0], """ + verify_print(choice_print, """ Choice Name (for named choices): (no name) Type : bool @@ -710,7 +713,7 @@ def run_selftests(): c["CHOICE_ITEM_2"].set_user_value("y") - verify_print(c.get_choices()[0], """ + verify_print(choice_print, """ Choice Name (for named choices): (no name) Type : bool @@ -768,12 +771,14 @@ def run_selftests(): Location: Kconfiglib/tests/Ktext:76""") verify_equals(c["NO_HELP"].get_help(), None) + verify_equals(choice_no_help.get_help(), None) verify_equals(c["EMPTY_HELP"].get_help(), "") + verify_equals(choice_empty_help.get_help(), "") verify_equals(c["HELP_TERMINATED_BY_COMMENT"].get_help(), "a\nb\nc\n") verify_equals(c["TRICKY_HELP"].get_help(), "a\n b\n c\n\n d\n e\n f\n\n\ng\n h\n i\n") verify_equals(c["S"].get_help(), "help for\nS\n") - verify_equals(c.get_choices()[1].get_help(), "help for\nC\n") + verify_equals(choice_help.get_help(), "help for\nC\n") verify_equals(c["S"].get_name(), "S") verify_equals(c.get_comments()[2].get_text(), "a comment") -- cgit v1.2.3