mirror of
https://github.com/caronc/apprise.git
synced 2025-01-06 05:59:23 +01:00
Merge pull request #76 from caronc/75-bug-gdk-gnome-exception
Handle ValueError Exception via Dbus import; refs #75
This commit is contained in:
commit
e61d9ddab3
@ -86,9 +86,12 @@ try:
|
||||
from gi.repository import GdkPixbuf
|
||||
NOTIFY_DBUS_IMAGE_SUPPORT = True
|
||||
|
||||
except ImportError:
|
||||
except (ImportError, ValueError):
|
||||
# No problem; this will get caught in outer try/catch
|
||||
raise
|
||||
|
||||
# A ValueError will get thrown upon calling gi.require_version() if
|
||||
# GDK/GTK isn't installed on the system but gi is.
|
||||
pass
|
||||
|
||||
except ImportError:
|
||||
# No problem; we just simply can't support this plugin; we could
|
||||
|
@ -230,3 +230,33 @@ def test_dbus_plugin(mock_mainloop, mock_byte, mock_bytearray,
|
||||
# Our notification succeeds even though the gi library was not loaded
|
||||
assert(obj.notify(title='title', body='body',
|
||||
notify_type=apprise.NotifyType.INFO) is True)
|
||||
|
||||
# Verify this all works in the event a ValueError is also thronw
|
||||
# out of the call to gi.require_version()
|
||||
|
||||
# Emulate require_version function:
|
||||
gi.require_version.side_effect = ValueError()
|
||||
|
||||
# The following libraries need to be reloaded to prevent
|
||||
# TypeError: super(type, obj): obj must be an instance or subtype of type
|
||||
# This is better explained in this StackOverflow post:
|
||||
# https://stackoverflow.com/questions/31363311/\
|
||||
# any-way-to-manually-fix-operation-of-\
|
||||
# super-after-ipython-reload-avoiding-ty
|
||||
#
|
||||
reload(sys.modules['apprise.plugins.NotifyDBus'])
|
||||
reload(sys.modules['apprise.plugins'])
|
||||
reload(sys.modules['apprise.Apprise'])
|
||||
reload(sys.modules['apprise'])
|
||||
|
||||
# Create our instance
|
||||
obj = apprise.Apprise.instantiate('glib://', suppress_exceptions=False)
|
||||
assert(isinstance(obj, apprise.plugins.NotifyDBus) is True)
|
||||
obj.duration = 0
|
||||
|
||||
# Test url() call
|
||||
assert(compat_is_basestring(obj.url()) is True)
|
||||
|
||||
# Our notification succeeds even though the gi library was not loaded
|
||||
assert(obj.notify(title='title', body='body',
|
||||
notify_type=apprise.NotifyType.INFO) is True)
|
||||
|
@ -77,7 +77,7 @@ def test_gnome_plugin():
|
||||
gi.repository.Notify.init.return_value = True
|
||||
gi.repository.Notify.Notification = mock_notify
|
||||
|
||||
# Emulate require_version function1k:
|
||||
# Emulate require_version function:
|
||||
gi.require_version = mock.Mock(
|
||||
name=gi_name + '.require_version')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user