Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications: fixes, cleanup, and tests #131

Merged
merged 4 commits into from May 9, 2020

Conversation

jaredks
Copy link
Owner

@jaredks jaredks commented Mar 14, 2020

Fixes #126

master

Issue 1

import rumps
rumps.notification('a', 'b', 'c', data='string data')
$ python test_notifications.py 
Traceback (most recent call last):
  File "test_notifications.py", line 2, in <module>
    rumps.notification('a', 'b', 'c', data='string data')
  File "rumps/rumps.py", line 171, in notification
    raise TypeError('notification data must be a mapping')
TypeError: notification data must be a mapping

Not exactly an error but an unnecessary restriction since changing to serializing provided data.

Issue 2

import rumps
rumps.notification('a', 'b', 'c', data={2: 22})
$ python test_notifications.py 
Traceback (most recent call last):
  File "test_notifications.py", line 2, in <module>
    rumps.notification('a', 'b', 'c', data={2: 22})
  File "rumps/rumps.py", line 182, in notification
    app = getattr(App, '*app_instance')
AttributeError: type object 'App' has no attribute '*app_instance'

Again, not an error but we don't need to have an instance to just use the default serializer on the class (pickle). This is also not a particularly helpful error.

Issue 3

import rumps
app = rumps.App('test app')
@rumps.clicked('test')
def test(menuitem):
    rumps.notification('a', 'b', 'c', data={2: 22})
app.run()

Run, then click "test" menu item,

2020-03-13 22:16:04.707 Python[57808:6820751] -[OC_BuiltinPythonData fastestEncoding]: unrecognized selector sent to instance 0x7fc3107598f0
rumps/rumps.py:185: UninitializedDeallocWarning: leaking an uninitialized object of type NSPlaceholderString
  ns_string = NSString.alloc().initWithString_(dumped)

This happens on Python 3 because pickle returns bytes which cannot be turned into NSString directly.

Issue 4

import rumps
app = rumps.App('test app')
@rumps.clicked('test')
def test(menuitem):
    rumps.notification('a', 'b', 'c')
@rumps.notifications
def on_notification(n):
    print('got', n)
app.run(debug=True)

Run, then click "test" menu item, then click the notification that is created,

$ python test_notifications.py 
2020-03-13 22:21:18.365 Python[57820:6823320] <MenuItem: ['test' -> []; callback: <function test at 0x10ec3d5e0>]>
2020-03-13 22:21:19.539 Python[57820:6823320] Traceback (most recent call last):
  File "rumps/rumps.py", line 1081, in userNotificationCenter_didActivateNotification_
    data['activationType'] = notification.activationType()
TypeError: 'NoneType' object does not support item assignment

This branch

Issue 1

No errors, notification works.

Issue 2

No errors, notification works.

Issue 3

No errors, notification works.

Issue 4

2020-03-13 22:31:56.071 Python[57840:6826369] <MenuItem: ['test' -> []; callback: <function test at 0x10d93f5e0>]>
got <Notification: [data: None]>

@jaredks jaredks marked this pull request as ready for review May 9, 2020 13:16
@jaredks jaredks merged commit 7fb9e87 into master May 9, 2020
@jaredks jaredks deleted the notifications-fixes-and-cleanup branch May 9, 2020 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notification data passing error
1 participant