diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
commit | 2e2851dc13d73352530dd4495c7e05603b2e520d (patch) | |
tree | 622b9cd8e5d32091c9aa9e4937b533975a40356c /deluge/plugins/Stats/deluge_stats/tests/test_stats.py | |
parent | Initial commit. (diff) | |
download | deluge-2e2851dc13d73352530dd4495c7e05603b2e520d.tar.xz deluge-2e2851dc13d73352530dd4495c7e05603b2e520d.zip |
Adding upstream version 2.1.2~dev0+20240219.upstream/2.1.2_dev0+20240219upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'deluge/plugins/Stats/deluge_stats/tests/test_stats.py')
-rw-r--r-- | deluge/plugins/Stats/deluge_stats/tests/test_stats.py | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/deluge/plugins/Stats/deluge_stats/tests/test_stats.py b/deluge/plugins/Stats/deluge_stats/tests/test_stats.py new file mode 100644 index 0000000..d61cd46 --- /dev/null +++ b/deluge/plugins/Stats/deluge_stats/tests/test_stats.py @@ -0,0 +1,106 @@ +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# +import pytest +import pytest_twisted +from twisted.internet import defer + +from deluge.common import fsize, fspeed +from deluge.ui.client import client + + +def print_totals(totals): + for name, value in totals.items(): + print(name, fsize(value)) + + print('overhead:') + print('up:', fsize(totals['total_upload'] - totals['total_payload_upload'])) + print('down:', fsize(totals['total_download'] - totals['total_payload_download'])) + + +class TestStatsPlugin: + @pytest_twisted.async_yield_fixture(autouse=True) + async def set_up(self, component): + defer.setDebugging(True) + client.start_standalone() + client.core.enable_plugin('Stats') + await component.start() + yield + client.stop_standalone() + + @defer.inlineCallbacks + def test_client_totals(self): + plugins = yield client.core.get_available_plugins() + if 'Stats' not in plugins: + pytest.skip('Stats plugin not available for testing') + + totals = yield client.stats.get_totals() + assert totals['total_upload'] == 0 + assert totals['total_payload_upload'] == 0 + assert totals['total_payload_download'] == 0 + assert totals['total_download'] == 0 + # print_totals(totals) + + @defer.inlineCallbacks + def test_session_totals(self): + plugins = yield client.core.get_available_plugins() + if 'Stats' not in plugins: + pytest.skip('Stats plugin not available for testing') + + totals = yield client.stats.get_session_totals() + assert totals['total_upload'] == 0 + assert totals['total_payload_upload'] == 0 + assert totals['total_payload_download'] == 0 + assert totals['total_download'] == 0 + # print_totals(totals) + + @pytest.mark.gtkui + @defer.inlineCallbacks + def test_write(self, tmp_path): + """ + writing to a file-like object; need this for webui. + + Not strictly a unit test, but tests if calls do not fail... + """ + from deluge_stats import graph, gtkui + + from deluge.configmanager import ConfigManager + 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('gtk3ui.conf', defaults=DEFAULT_PREFS) + + self.plugins = PluginManager() + MainWindow() + TorrentView() + TorrentDetails() + Preferences() + + class FakeFile: + def __init__(self): + self.data = [] + + def write(self, data): + self.data.append(data) + + stats_gtkui = gtkui.GtkUI('test_stats') + stats_gtkui.enable() + yield stats_gtkui.graphs_tab.update() + + g = stats_gtkui.graphs_tab.graph + g.add_stat('download_rate', color=graph.green) + g.add_stat('upload_rate', color=graph.blue) + g.set_left_axis(formatter=fspeed, min=10240) + + surface = g.draw(900, 150) + file_like = FakeFile() + surface.write_to_png(file_like) + data = b''.join(file_like.data) + with open(tmp_path / 'file_like.png', 'wb') as _file: + _file.write(data) |