Module: deluge
Branch: master
Commit: 796109649d2d2a505e0ca875620fbe55e54d5549

Author: Damien Churchill <[email protected]>
Date:   Thu Apr 21 10:41:00 2011 +0100

fix the client tests albeit in an ultra hacky way

---

 deluge/tests/test_client.py |   46 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/deluge/tests/test_client.py b/deluge/tests/test_client.py
index 79ff383..1bd0a89 100644
--- a/deluge/tests/test_client.py
+++ b/deluge/tests/test_client.py
@@ -1,6 +1,10 @@
-import tempfile
 import os
+import sys
+import time
 import signal
+import tempfile
+
+from subprocess import Popen, PIPE
 
 import common
 
@@ -8,20 +12,48 @@ from twisted.trial import unittest
 
 from deluge.ui.client import client
 
-# Start a daemon to test with and wait a couple seconds to make sure it's 
started
-config_directory = common.set_tmp_config_dir()
-client.start_daemon(58847, config_directory)
-import time
-time.sleep(2)
+CWD = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+
+DAEMON_SCRIPT = """
+import sys
+import deluge.main
 
+sys.argv.extend(['-d', '-c', '%s', '-Linfo'])
+
+deluge.main.start_daemon()
+"""
 
 class ClientTestCase(unittest.TestCase):
+
+    def setUp(self):
+        config_directory = common.set_tmp_config_dir()
+
+        fp = tempfile.TemporaryFile()
+        fp.write(DAEMON_SCRIPT % config_directory)
+        fp.seek(0)
+
+        self.core = Popen([sys.executable], cwd=CWD,
+                          stdin=fp, stdout=PIPE, stderr=PIPE)
+
+        listening = False
+        while not listening:
+            line = self.core.stderr.readline()
+            if "Factory starting on 58846" in line:
+                listening = True
+                time.sleep(0.1) # Slight pause just incase
+                break
+
+
+    def tearDown(self):
+        self.core.terminate()
+
     def test_connect_no_credentials(self):
-        d = client.connect("localhost", 58847)
+        d = client.connect("localhost", 58846)
         d.addCallback(self.assertEquals, 10)
 
         def on_connect(result):
             self.addCleanup(client.disconnect)
             return result
+
         d.addCallback(on_connect)
         return d

-- 
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.

Reply via email to