From 59c175f3128a3b688e6aaee02b58f1fe8678d7fc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 28 Jul 2024 09:15:18 +0530 Subject: [PATCH] Add test for filtering --- kitty/notifications.py | 6 +++++- kitty_tests/notifications.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/kitty/notifications.py b/kitty/notifications.py index 39079c0ec..f409311fa 100644 --- a/kitty/notifications.py +++ b/kitty/notifications.py @@ -685,11 +685,15 @@ def is_notification_allowed(self, cmd: NotificationCommand, channel_id: int, app return False return True + @property + def filter_rules(self) -> Iterator[str]: + return iter(get_options().filter_notification.keys()) + def is_notification_filtered(self, cmd: NotificationCommand) -> bool: if self.filter_script(cmd): self.log(f'Notification {cmd.title!r} filtered out by script') return True - for rule in get_options().filter_notification: + for rule in self.filter_rules: if cmd.matches_rule(rule): self.log(f'Notification {cmd.title!r} filtered out by filter_notification rule: {rule}') return True diff --git a/kitty_tests/notifications.py b/kitty_tests/notifications.py index 86b189357..57755965a 100644 --- a/kitty_tests/notifications.py +++ b/kitty_tests/notifications.py @@ -69,6 +69,13 @@ def send(self, channel_id: int, osc_escape_code: str) -> bool: self.responses.append(osc_escape_code) +class NotificationManager(NotificationManager): + + @property + def filter_rules(self): + yield from ('title:filterme',) + + def do_test(self: 'TestNotifications', tdir: str) -> None: di = DesktopIntegration(None) ch = Channel() @@ -162,6 +169,12 @@ def assert_events(focus=True, close=0, report='', close_response=''): self.ae(di.notifications, [n()]) reset() + # test filtering + h(';title') + h(';filterme please') + self.ae(di.notifications, [n()]) + reset() + # test closing interactions with reporting and activation h('i=c;title') self.ae(di.notifications, [n()])