def reset(): nonlocal prev_cmd reset_registry() del notifications[:] del activations[:] prev_cmd = NotificationCommand()
def test_desktop_notify(self): reset_registry() notifications = [] activations = [] prev_cmd = NotificationCommand() def reset(): nonlocal prev_cmd reset_registry() del notifications[:] del activations[:] prev_cmd = NotificationCommand() def notify(title, body, identifier): notifications.append((title, body, identifier)) def h(raw_data, osc_code=99, window_id=1): nonlocal prev_cmd x = handle_notification_cmd(osc_code, raw_data, window_id, prev_cmd, notify) if x is not None and osc_code == 99: prev_cmd = x def activated(identifier, window_id, focus, report): activations.append((identifier, window_id, focus, report)) h('test it', osc_code=9) self.ae(notifications, [('test it', '', 'i0')]) notification_activated(notifications[-1][-1], activated) self.ae(activations, [('0', 1, True, False)]) reset() h('d=0:i=x;title') h('d=1:i=x:p=body;body') self.ae(notifications, [('title', 'body', 'i0')]) notification_activated(notifications[-1][-1], activated) self.ae(activations, [('x', 1, True, False)]) reset() h('i=x:p=body:a=-focus;body') self.ae(notifications, [('body', '', 'i0')]) notification_activated(notifications[-1][-1], activated) self.ae(activations, []) reset() h('i=x:e=1;' + standard_b64encode(b'title').decode('ascii')) self.ae(notifications, [('title', '', 'i0')]) notification_activated(notifications[-1][-1], activated) self.ae(activations, [('x', 1, True, False)]) reset() h('d=0:i=x:a=-report;title') h('d=1:i=x:a=report;body') self.ae(notifications, [('titlebody', '', 'i0')]) notification_activated(notifications[-1][-1], activated) self.ae(activations, [('x', 1, True, True)]) reset() h(';title') self.ae(notifications, [('title', '', 'i0')]) notification_activated(notifications[-1][-1], activated) self.ae(activations, [('0', 1, True, False)]) reset()