Skip to content

Commit

Permalink
GbpConfArgParser.get_conf_file_value: only allow valid options
Browse files Browse the repository at this point in the history
Raise an exception if the queried option is not in the list of valid
config file args.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
  • Loading branch information
marquiz committed Jan 18, 2018
1 parent b49aeb7 commit 64c98fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions gbp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion tests/18_test_Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 64c98fe

Please sign in to comment.