Skip to content
Snippets Groups Projects
Commit a4dc1959 authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Add method to see if key exists

parent 505cf0b4
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,12 @@ class ConfigUserTest(TestCase): ...@@ -62,6 +62,12 @@ class ConfigUserTest(TestCase):
self.assertEqual(True, self.cfg.get('main/bool_option2')) self.assertEqual(True, self.cfg.get('main/bool_option2'))
def test_has_keys(self):
self.assertTrue(self.cfg.has('main', 'a_default_key'))
self.assertTrue(self.cfg.has('main/a_default_key'))
self.assertFalse(self.cfg.has('main', 'missing-key'))
self.assertFalse(self.cfg.has('main/missing-key'))
# ---------------------------------------------- # ----------------------------------------------
# Failure tests # Failure tests
# ---------------------------------------------- # ----------------------------------------------
......
...@@ -91,6 +91,14 @@ class UserConfig(object): ...@@ -91,6 +91,14 @@ class UserConfig(object):
else: else:
return value return value
def has(self, option, second=None):
"""Return a True if the key exists in the
settings. ``config.get('main', 'window/size')`` and
``config.get('main/window/size')`` are equivalent.
"""
option = self._check_section_option_is_valid(option, second)
return option in self.all_keys()
def set(self, option, value, extra=None): def set(self, option, value, extra=None):
"""Set a value for an option in a given section. Can either supply """Set a value for an option in a given section. Can either supply
the fully qualified option or add the section as an additional the fully qualified option or add the section as an additional
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment