From 88fc21e9938e08827751509d4da20b9dad44bf92 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 26 Sep 2021 15:33:53 +0100 Subject: [PATCH] [Stats] Fix cairo error and failing tests Fixed the Stats GTKUI test not updated to the new GTK3 dir layout. Fixed pygobject cairo ImageSurface error: AttributeError: 'gi.repository.cairo' object has no attribute 'ImageSurface' The documentation seems to suggest that using `import cairo` is the correct usage and this fixed the issue, along with adding suggested gi.require_foreign call. References: https://pygobject.readthedocs.io/en/latest/guide/cairo_integration.html --- deluge/plugins/Stats/deluge_stats/graph.py | 6 +++++- .../plugins/Stats/deluge_stats/tests/test_stats.py | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/deluge/plugins/Stats/deluge_stats/graph.py b/deluge/plugins/Stats/deluge_stats/graph.py index 847c253d1..bc18913b3 100644 --- a/deluge/plugins/Stats/deluge_stats/graph.py +++ b/deluge/plugins/Stats/deluge_stats/graph.py @@ -20,7 +20,11 @@ import logging import math import time -from gi.repository import cairo +import gi + +gi.require_foreign('cairo') # NOQA: E402 + +import cairo # isort:skip (gi checks required before import). log = logging.getLogger(__name__) diff --git a/deluge/plugins/Stats/deluge_stats/tests/test_stats.py b/deluge/plugins/Stats/deluge_stats/tests/test_stats.py index 07741cbf3..ab2456877 100644 --- a/deluge/plugins/Stats/deluge_stats/tests/test_stats.py +++ b/deluge/plugins/Stats/deluge_stats/tests/test_stats.py @@ -75,14 +75,14 @@ class StatsTestCase(BaseTestCase): from deluge_stats import graph, gtkui from deluge.configmanager import ConfigManager - from deluge.ui.gtkui.gtkui import DEFAULT_PREFS - from deluge.ui.gtkui.mainwindow import MainWindow - from deluge.ui.gtkui.pluginmanager import PluginManager - from deluge.ui.gtkui.preferences import Preferences - from deluge.ui.gtkui.torrentdetails import TorrentDetails - from deluge.ui.gtkui.torrentview import TorrentView + from deluge.ui.gtk3.gtkui import DEFAULT_PREFS + from deluge.ui.gtk3.mainwindow import MainWindow + from deluge.ui.gtk3.pluginmanager import PluginManager + from deluge.ui.gtk3.preferences import Preferences + from deluge.ui.gtk3.torrentdetails import TorrentDetails + from deluge.ui.gtk3.torrentview import TorrentView - ConfigManager('gtkui.conf', defaults=DEFAULT_PREFS) + ConfigManager('gtk3ui.conf', defaults=DEFAULT_PREFS) self.plugins = PluginManager() MainWindow()