From 64c98fe42626ad35aea91f4eb7ebd0b895c7412e Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 28 May 2014 12:30:56 +0300 Subject: [PATCH] GbpConfArgParser.get_conf_file_value: only allow valid options Raise an exception if the queried option is not in the list of valid config file args. Signed-off-by: Markus Lehtonen --- gbp/config.py | 6 +++--- tests/18_test_Config.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gbp/config.py b/gbp/config.py index 9357e267..9cd1aedd 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -702,10 +702,10 @@ def get_conf_file_value(self, option_name): @returns: The config file option value or C{None} if it doesn't exist @rtype: C{str} or C{None} """ - try: + if option_name in self.conf_file_args: return self.config.get_value(option_name) - except KeyError: - return None + else: + raise KeyError("Invalid option: %s" % option_name) class GbpConfigDebian(GbpConfig): diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py index 74f97064..6571b6fb 100644 --- a/tests/18_test_Config.py +++ b/tests/18_test_Config.py @@ -95,9 +95,11 @@ def test_get_conf_file_value(self): Read a single value from the parsed config """ parser = GbpConfArgParser.create_parser(prog='cmd4') + parser.add_conf_file_arg('--new_overrides_git_option1') self.assertEqual(parser.get_conf_file_value('new_overrides_git_option1'), 'new_overrides_git_value1') - self.assertEqual(parser.get_conf_file_value('doesnotexist'), None) + with self.assertRaises(KeyError): + parser.get_conf_file_value('doesnotexist') def test_param_list(self): parser = GbpConfArgParser.create_parser(prog='cmd4')