diff --git a/qt/applications/workbench/workbench/config/test/test_user.py b/qt/applications/workbench/workbench/config/test/test_user.py index 04e8858ba335638f8e93f6fee2d9db07738f0d54..44cbe84769b07c27902e347a9c4efca68e573c75 100644 --- a/qt/applications/workbench/workbench/config/test/test_user.py +++ b/qt/applications/workbench/workbench/config/test/test_user.py @@ -62,6 +62,12 @@ class ConfigUserTest(TestCase): 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 # ---------------------------------------------- diff --git a/qt/applications/workbench/workbench/config/user.py b/qt/applications/workbench/workbench/config/user.py index 2bb0f6b778a3b2ee1838c4eda9181db45583c2e5..f7658e2db6120f807037fea3bce0e937de621a89 100644 --- a/qt/applications/workbench/workbench/config/user.py +++ b/qt/applications/workbench/workbench/config/user.py @@ -91,6 +91,14 @@ class UserConfig(object): else: 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): """Set a value for an option in a given section. Can either supply the fully qualified option or add the section as an additional