Skip to content

Commit

Permalink
Merge pull request #1197 from alphagov/insensitive-set-contains
Browse files Browse the repository at this point in the history
Implement `InsensitiveSet.__contains__`
  • Loading branch information
quis authored Feb 26, 2025
2 parents 1b1d0ef + b1da482 commit a6b6dd1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 95.2.0

* Implement `InsensitiveSet.__contains__`

## 95.1.2

* Fix to the number of arguments the `on_retry` of the `NotifyTask` class takes.
Expand Down
3 changes: 3 additions & 0 deletions notifications_utils/insensitive_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ def make_key(original_key):
class InsensitiveSet(OrderedSet):
def __init__(self, iterable):
return super().__init__(InsensitiveDict.from_keys(iterable).values())

def __contains__(self, key):
return key in InsensitiveDict.from_keys(self)
2 changes: 1 addition & 1 deletion notifications_utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# - `make version-minor` for new features
# - `make version-patch` for bug fixes

__version__ = "95.1.2" # a47171c8774fee6d72573d446710b651
__version__ = "95.2.0" # e423953f9dec74010897c62aa4e035de
21 changes: 21 additions & 0 deletions tests/test_insensitive_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ def test_insensitive_set():
)


def test_insensitive_set_contains():
foobar = InsensitiveSet(("foo", "bar"))

for key in (
"foo",
"F o o ",
"F_O_O",
"B_A_R",
"B a r",
"bar",
):
assert key in foobar

for key in (
"baz",
"barz",
"z foo",
):
assert key not in foobar


@pytest.mark.parametrize(
"extra_args, expected_dict",
(
Expand Down

0 comments on commit a6b6dd1

Please sign in to comment.