Skip to content

Commit 52e7ea9

Browse files
committed
Add: Allow to check if a Config has a key
This will allow for easier handling of config setting changes and to check whether a setting is available.
1 parent b4ea89a commit 52e7ea9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

autohooks/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def is_empty(self) -> bool:
7171
"""
7272
return not bool(self._config_dict)
7373

74+
def has_key(self, key: str) -> bool:
75+
"""
76+
Returns True if the key is in the config.
77+
"""
78+
return key in self._config_dict
79+
7480

7581
def _gather_mode(mode_string: Optional[str]) -> Mode:
7682
"""

tests/test_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ def test_config_point_syntax(self):
246246
self.assertFalse(bar_config.is_empty())
247247
self.assertEqual(bar_config.get_value("lorem"), "ipsum")
248248

249+
def test_has_key(self):
250+
config = Config()
251+
self.assertFalse(config.has_key("foo"))
252+
config = Config({"foo": "bar"})
253+
self.assertTrue(config.has_key("foo"))
254+
249255

250256
if __name__ == "__main__":
251257
unittest.main()

0 commit comments

Comments
 (0)