From c3247396f7fa13e1d42937dd54cf1cbc19d5dc22 Mon Sep 17 00:00:00 2001 From: bendikro Date: Tue, 19 Apr 2016 16:18:51 +0200 Subject: [PATCH] [Stats] Fix to tests and deleted .test.py --- .../Stats/deluge/plugins/stats/gtkui.py | 4 +- .../Stats/deluge/plugins/stats/tests/.test.py | 108 ------------------ .../deluge/plugins/stats/tests/test_stats.py | 52 ++++++++- setup.py | 7 +- tox.ini | 11 +- 5 files changed, 69 insertions(+), 113 deletions(-) delete mode 100644 deluge/plugins/Stats/deluge/plugins/stats/tests/.test.py diff --git a/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py b/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py index 5104501d5..fa108b914 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py @@ -131,8 +131,9 @@ class GraphsTab(Tab): def _update_complete(result): self.graph_widget.queue_draw() + return result d1.addCallback(_update_complete) - return True + return d1 def clear(self): pass @@ -213,6 +214,7 @@ class GraphsTab(Tab): class GtkUI(GtkPluginBase): + def enable(self): log.debug("Stats plugin enable called") self.config = deluge.configmanager.ConfigManager("stats.gtkui.conf", DEFAULT_CONF) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/tests/.test.py b/deluge/plugins/Stats/deluge/plugins/stats/tests/.test.py deleted file mode 100644 index 12e2f3775..000000000 --- a/deluge/plugins/Stats/deluge/plugins/stats/tests/.test.py +++ /dev/null @@ -1,108 +0,0 @@ -from __future__ import print_function - -import deluge -from deluge.ui.client import aclient, sclient - -from . import graph - -sclient.set_core_uri() - - -def test_sync(): - - upload = sclient.graph_get_upload() - download = sclient.graph_get_download() - print(upload) - print(download) - - """ - upload = [66804, 66915, 66974, 67447, 67540, 67318, 67320, 67249, 66659, 66489, 67027, 66914, 66802, 67303, - 67654, 67643, 67763, 67528, 67523, 67431, 67214, 66939, 67316, 67020, 66881, 67103, 67377, 67141, - 67366, 67492, 67375, 67203, 67056, 67010, 67029, 66741, 66695, 66868, 66805, 66264, 66249, 66317, - 66459, 66306, 66681, 66954, 66662, 66278, 65921, 65695, 65681, 65942, 66000, 66140, 66424, 66480, - 66257, 66271, 66145, 65854, 65568, 65268, 65112, 65050, 65027, 64676, 64655, 64178, 64386, 63979, - 63271, 62746, 62337, 62297, 62496, 62902, 63801, 64121, 62957, 62921, 63051, 62644, 63240, 64107, - 63968, 63987, 63644, 63263, 63153, 62999, 62843, 62777, 63101, 63078, 63178, 63126, 63401, 62630, - 62451, 62505, 62254, 61485, 61264, 60937, 60568, 61011, 61109, 60325, 60196, 59640, 59619, 59514, - 60813, 60572, 61632, 61689, 63365, 64583, 66396, 67179, 68209, 68295, 67674, 67559, 67195, 66178, - 65632, 66124, 66456, 66676, 67183, 67620, 66960, 66347, 65925, 65907, 65896, 66738, 66703, 67060, - 67004, 67007, 66329, 65304, 52002, 38969, 25433, 12426, 0, 0] - download = [42926, 43853, 43157, 45470, 44254, 46272, 45083, 47344, 46716, 51963, 50112, 52334, 55525, 57545, - 53691, 51637, 49574, 49836, 48295, 49843, 52878, 56014, 56966, 56938, 60065, 60461, 56542, 59526, - 58678, 54424, 51862, 55109, 52132, 53783, 51687, 56567, 52182, 50758, 46714, 50511, 48161, 50920, - 48694, 50528, 55074, 55420, 55882, 59268, 59958, 57938, 57115, 51424, 51180, 53184, 52879, 51177, - 54417, 51097, 47901, 49870, 55865, 61118, 61476, 63498, 58878, 49630, 45975, 45632, 45892, 44855, - 49495, 48304, 45829, 42152, 39403, 37574, 32384, 34933, 34901, 33492, 31953, 36271, 33826, 34515, - 36408, 41106, 43054, 44110, 40810, 41383, 37267, 35881, 38660, 37525, 34857, 36718, 36842, 34281, - 39528, 41854, 42952, 40021, 41722, 41045, 42917, 39287, 38672, 32824, 28765, 22686, 18490, 15714, - 15268, 14793, 15305, 16354, 16720, 17502, 17857, 16622, 18447, 19929, 31138, 36965, 36158, 32795, - 30445, 21997, 18100, 22491, 27227, 29317, 32436, 35700, 39140, 36258, 33697, 24751, 20354, 8211, - 3836, 1560, 834, 2034, 1744, 1637, 1637, 1637, 0, 0] - """ - - from .graph import NetworkGraph - n = NetworkGraph() - n.savedUpSpeeds = upload - n.savedDownSpeeds = download - - n.draw(800, 200) - n.surface.write_to_png('output_sync.png') - - -def test_async(): - g = graph.Graph() - g.add_stat('download_rate', color=graph.green) - g.add_stat('upload_rate', color=graph.blue) - g.set_left_axis(formatter=deluge.common.fspeed, min=10240) - g.async_request() - aclient.force_call(True) - surface = g.draw(600, 300) - surface.write_to_png('output_async.png') - - -def test_dht(): - """'boring graph, but testing if it works'""" - - g = graph.Graph() - g.add_stat('dht_nodes', color=graph.orange) - g.add_stat('dht_cache_nodes', color=graph.blue) - g.add_stat('dht_torrents', color=graph.green) - g.add_stat('num_connections', color=graph.darkred) # testing : non dht - g.set_left_axis(formatter=str, min=10) - g.async_request() - aclient.force_call(True) - surface = g.draw(600, 300) - surface.write_to_png('output_dht.png') - - -def test_write(): - """ - writing to a file-like object; need this for webui. - """ - class FakeFile: - def __init__(self): - self.data = [] - - def write(self, string): - self.data.append(string) - - g = graph.Graph() - g.add_stat('download_rate', color=graph.green) - g.add_stat('upload_rate', color=graph.blue) - g.set_left_axis(formatter=deluge.common.fspeed, min=10240) - g.async_request() - aclient.force_call(True) - surface = g.draw(900, 150) - - file_like = FakeFile() - surface.write_to_png(file_like) - data = "".join(file_like.data) - - f = open("file_like.png", "wb") - f.write(data) - f.close() - -# test_sync() -test_async() -test_dht() -# test_write() diff --git a/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py b/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py index bf501d486..3134f9ec2 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py @@ -6,11 +6,12 @@ # from __future__ import print_function +import pytest from twisted.internet import defer from twisted.trial import unittest import deluge.component as component -from deluge.common import fsize +from deluge.common import fsize, fspeed from deluge.tests import common as tests_common from deluge.tests.basetest import BaseTestCase from deluge.ui.client import client @@ -63,3 +64,52 @@ class StatsTestCase(BaseTestCase): self.assertEquals(totals['total_payload_download'], 0) self.assertEquals(totals['total_download'], 0) # print_totals(totals) + + @pytest.mark.gtkui + @defer.inlineCallbacks + def test_write(self): + """ + writing to a file-like object; need this for webui. + + Not strictly a unit test, but tests if calls do not fail... + """ + from deluge.ui.gtkui.gtkui import DEFAULT_PREFS + from deluge.ui.gtkui.preferences import Preferences + from deluge.ui.gtkui.mainwindow import MainWindow + from deluge.configmanager import ConfigManager + from deluge.ui.gtkui.pluginmanager import PluginManager + from deluge.ui.gtkui.torrentdetails import TorrentDetails + from deluge.ui.gtkui.torrentview import TorrentView + from deluge.plugins.Stats.deluge.plugins.stats import graph, gtkui + + ConfigManager("gtkui.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 = "".join(file_like.data) + f = open("file_like.png", "wb") + f.write(data) + f.close() diff --git a/setup.py b/setup.py index 382149b5d..6630e82cb 100755 --- a/setup.py +++ b/setup.py @@ -225,7 +225,12 @@ class CleanPlugins(cmd.Command): # Delete the .eggs if path[-4:] == '.egg': - print('Deleting %s' % path) + print("Deleting egg file '%s'" % path) + os.remove(path) + + # Delete the .egg-link + if path[-9:] == '.egg-link': + print("Deleting egg link '%s'" % path) os.remove(path) egg_info_dir_path = 'deluge/plugins/*/*.egg-info' diff --git a/tox.ini b/tox.ini index 5cf421e8c..401f18a09 100644 --- a/tox.ini +++ b/tox.ini @@ -61,9 +61,16 @@ whitelist_externals = trial commands = trial --reporter=deluge-reporter deluge/tests [testenv:plugins] +setenv = PYTHONPATH = {env:PWD}:{env:PWD}/deluge/plugins commands = - python setup.py egg_info_plugins - py.test deluge/plugins + python setup.py build_plugins --develop --install-dir={env:PWD}/deluge/plugins/ + py.test -v -s -m "not gtkui" deluge/plugins + +[testenv:pluginsgtkui] +setenv = PYTHONPATH = {env:PWD}:{env:PWD}/deluge/plugins +commands = + python setup.py build_plugins --develop --install-dir={env:PWD}/deluge/plugins/ + py.test -v -s deluge/plugins [testenv:py26] basepython = python2.6