Add some deprecation warnin...
Content-type: text/plain
Author: andar
Revision: 5541
Log:
Fix up some docstrings
Add some deprecation warnings
Add more tests for core
Diff:
Modified: trunk/deluge/core/core.py
===================================================================
--- trunk/deluge/core/core.py 2009-07-23 04:23:41 UTC (rev 5540)
+++ trunk/deluge/core/core.py 2009-07-23 21:19:01 UTC (rev 5541)
@@ -39,7 +39,9 @@
import shutil
import threading
import pkg_resources
+import warnings
+
from twisted.internet import reactor, defer
from twisted.internet.task import LoopingCall
import twisted.web.client
@@ -58,6 +60,7 @@
import deluge.common
import deluge.component as component
from deluge.event import *
+from deluge.error import *
from deluge.core.torrentmanager import TorrentManager
from deluge.core.pluginmanager import PluginManager
from deluge.core.alertmanager import AlertManager
@@ -325,16 +328,25 @@
:type torrent_id: string
:param remove_data: if True, remove the data associated with this
torrent
:type remove_data: boolean
+ :returns: True if removed successfully
+ :rtype: bool
+ :raises InvalidTorrentError: if the torrent_id does not exist in the
session
+
"""
log.debug("Removing torrent %s from the core.", torrent_id)
- self.torrentmanager.remove(torrent_id, remove_data)
+ if torrent_id not in self.torrentmanager.torrents:
+ raise InvalidTorrentError("torrent_id not in session")
+
+ return self.torrentmanager.remove(torrent_id, remove_data)
@export
def get_stats(self):
"""
- document me!!!
+ Deprecated: please use get_session_status()
+
"""
+ warnings.warn("Use get_session_status()", DeprecationWarning)
stats = self.get_session_status(["payload_download_rate",
"payload_upload_rate",
"dht_nodes", "has_incoming_connections", "download_rate",
"upload_rate"])
@@ -353,7 +365,8 @@
@export
def get_session_status(self, keys):
"""
- Gets the session status values for 'keys'
+ Gets the session status values for 'keys', these keys are taking
+ from libtorrent's session status.
:param keys: the keys for which we want values
:type keys: list
@@ -537,16 +550,19 @@
@export
def get_dht_nodes(self):
"""Returns the number of dht nodes"""
+ warnings.warn("Use get_session_status().", DeprecationWarning)
return self.session.status().dht_nodes
@export
def get_download_rate(self):
"""Returns the payload download rate"""
+ warnings.warn("Use get_session_status().", DeprecationWarning)
return self.session.status().payload_download_rate
@export
def get_upload_rate(self):
"""Returns the payload upload rate"""
+ warnings.warn("Use get_session_status().", DeprecationWarning)
return self.session.status().payload_upload_rate
@export
@@ -649,6 +665,7 @@
@export
def get_health(self):
"""Returns True if we have established incoming connections"""
+ warnings.warn("Use get_session_status().", DeprecationWarning)
return self.session.status().has_incoming_connections
@export
Modified: trunk/tests/test_core.py
===================================================================
--- trunk/tests/test_core.py 2009-07-23 04:23:41 UTC (rev 5540)
+++ trunk/tests/test_core.py 2009-07-23 21:19:01 UTC (rev 5541)
@@ -38,7 +38,7 @@
self.assertEquals(torrent_id, info_hash)
def test_add_torrent_url(self):
- url =
"http://torrent.ubuntu.com:6969/file?info_hash=%60%D5%D8%23%28%B4Tu%11%FD%EA%C9%BFM%01%12%DA%A0%CE%00"
+ url = "http://deluge-torrent.org/ubuntu-9.04-desktop-i386.iso.torrent"
options = {}
info_hash = "60d5d82328b4547511fdeac9bf4d0112daa0ce00"
@@ -75,8 +75,22 @@
import base64
torrent_id = self.core.add_torrent_file(filename,
base64.encodestring(open(filename).read()), options)
- self.core.remove_torrent(torrent_id, True)
+ import deluge.error
+ self.assertRaises(deluge.error.InvalidTorrentError,
self.core.remove_torrent, "torrentidthatdoesntexist", True)
+ ret = self.core.remove_torrent(torrent_id, True)
+
+ self.assertTrue(ret)
self.assertEquals(len(self.core.get_session_state()), 0)
+ def test_get_session_status(self):
+ status = self.core.get_session_status(["upload_rate", "download_rate"])
+ self.assertEquals(type(status), dict)
+ self.assertEquals(status["upload_rate"], 0.0)
+ def test_get_cache_status(self):
+ status = self.core.get_cache_status()
+ self.assertEquals(type(status), dict)
+ self.assertEquals(status["write_hit_ratio"], 0.0)
+ self.assertEquals(status["read_hit_ratio"], 0.0)
+
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---