From e4def6d67d8d26479a361335ddfc3d3a7ee2f09b Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Wed, 30 Jul 2025 21:19:56 -0400 Subject: [PATCH] glib test coverage --- tests/test_plugin_glib.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_plugin_glib.py b/tests/test_plugin_glib.py index d86fd855..f610d231 100644 --- a/tests/test_plugin_glib.py +++ b/tests/test_plugin_glib.py @@ -77,6 +77,41 @@ def enabled_glib_environment(monkeypatch): reload_plugin("glib") +def test_plugin_glib_gdkpixbuf_attribute_error(monkeypatch): + """Simulate AttributeError from importing GdkPixbuf""" + + # Create gi module + gi = types.ModuleType("gi") + + # Create gi.repository mock, but DO NOT include GdkPixbuf + gi.repository = types.SimpleNamespace( + Gio=Mock(), + GLib=types.SimpleNamespace( + Variant=Mock(), + Error=type("GLibError", (Exception,), {}) + ), + # GdkPixbuf missing entirely triggers AttributeError + ) + + def fake_require_version(name, version): + if name == "GdkPixbuf": + # Simulate success in require_version + return + return + + gi.require_version = Mock(side_effect=fake_require_version) + + # Inject into sys.modules + sys.modules["gi"] = gi + sys.modules["gi.repository"] = gi.repository + + # Trigger the plugin reload with our patched environment + reload_plugin("glib") + + from apprise.plugins import glib as plugin_glib + assert plugin_glib.NOTIFY_GLIB_IMAGE_SUPPORT is False + + def test_plugin_glib_basic_notify(enabled_glib_environment): """Basic notification path""" obj = apprise.Apprise.instantiate("glib://", suppress_exceptions=False)