Skip to content

Commit

Permalink
Add: Allow to check if a Config has a key
Browse files Browse the repository at this point in the history
This will allow for easier handling of config setting changes and to
check whether a setting is available.
  • Loading branch information
bjoernricks committed Feb 4, 2025
1 parent b4ea89a commit 52e7ea9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autohooks/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def is_empty(self) -> bool:
"""
return not bool(self._config_dict)

def has_key(self, key: str) -> bool:
"""
Returns True if the key is in the config.
"""
return key in self._config_dict


def _gather_mode(mode_string: Optional[str]) -> Mode:
"""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ def test_config_point_syntax(self):
self.assertFalse(bar_config.is_empty())
self.assertEqual(bar_config.get_value("lorem"), "ipsum")

def test_has_key(self):
config = Config()
self.assertFalse(config.has_key("foo"))
config = Config({"foo": "bar"})
self.assertTrue(config.has_key("foo"))


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

0 comments on commit 52e7ea9

Please sign in to comment.