mirror of
https://github.com/caronc/apprise.git
synced 2025-01-03 20:49:19 +01:00
handle ValueError Exception via Gnome import; refs #75
This commit is contained in:
parent
e61d9ddab3
commit
81b6e7a212
@ -47,10 +47,13 @@ try:
|
||||
# We're good to go!
|
||||
NOTIFY_GNOME_SUPPORT_ENABLED = True
|
||||
|
||||
except ImportError:
|
||||
except (ImportError, ValueError):
|
||||
# No problem; we just simply can't support this plugin; we could
|
||||
# be in microsoft windows, or we just don't have the python-gobject
|
||||
# library available to us (or maybe one we don't support)?
|
||||
|
||||
# Alternativey A ValueError will get thrown upon calling
|
||||
# gi.require_version() if the requested Notify namespace isn't available
|
||||
pass
|
||||
|
||||
|
||||
|
@ -260,3 +260,34 @@ 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)
|
||||
|
||||
# Force a global import error
|
||||
_session_bus = sys.modules['dbus']
|
||||
sys.modules['dbus'] = compile('raise ImportError()', 'dbus', 'exec')
|
||||
|
||||
# Reload our modules
|
||||
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 fail because the dbus library wasn't present
|
||||
assert(obj.notify(title='title', body='body',
|
||||
notify_type=apprise.NotifyType.INFO) is False)
|
||||
|
||||
# Since playing with the sys.modules is not such a good idea,
|
||||
# let's just put it back now :)
|
||||
sys.modules['dbus'] = _session_bus
|
||||
# Reload our modules
|
||||
reload(sys.modules['apprise.plugins.NotifyDBus'])
|
||||
reload(sys.modules['apprise.plugins'])
|
||||
reload(sys.modules['apprise.Apprise'])
|
||||
reload(sys.modules['apprise'])
|
||||
|
@ -153,3 +153,31 @@ def test_gnome_plugin():
|
||||
|
||||
# Test the setting of a the urgency
|
||||
apprise.plugins.NotifyGnome(urgency=0)
|
||||
|
||||
# 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.NotifyGnome'])
|
||||
reload(sys.modules['apprise.plugins'])
|
||||
reload(sys.modules['apprise.Apprise'])
|
||||
reload(sys.modules['apprise'])
|
||||
|
||||
# Create our instance
|
||||
obj = apprise.Apprise.instantiate('gnome://', suppress_exceptions=False)
|
||||
assert(isinstance(obj, apprise.plugins.NotifyGnome) is True)
|
||||
obj.duration = 0
|
||||
|
||||
# Our notifications can not work without our gi library having been
|
||||
# loaded.
|
||||
assert(obj.notify(title='title', body='body',
|
||||
notify_type=apprise.NotifyType.INFO) is False)
|
||||
|
Loading…
Reference in New Issue
Block a user