summaryrefslogtreecommitdiffstats
path: root/tests/helper/PluginTester.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-13 23:24:21 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-13 23:24:21 +0100
commitc7ad1cc5b4a5d190a060e3ddd9274c3065da6708 (patch)
tree639062525ddde3b8c785f26a0f4091ec10d9e204 /tests/helper/PluginTester.py
parentfixed pyflakes and sloccount (diff)
downloadpyload-c7ad1cc5b4a5d190a060e3ddd9274c3065da6708.tar.xz
plugin unit test, closed #499, #500
Diffstat (limited to 'tests/helper/PluginTester.py')
-rw-r--r--tests/helper/PluginTester.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py
new file mode 100644
index 000000000..997a0923f
--- /dev/null
+++ b/tests/helper/PluginTester.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+from unittest import TestCase
+from os.path import abspath
+from sys import exc_clear, exc_info
+from logging import log, DEBUG
+from time import sleep, time
+
+from Stubs import Thread, Core, noop
+
+from module.plugins.Hoster import Hoster, Abort, Fail
+
+def _wait(self):
+ """ waits the time previously set """
+ self.waiting = True
+
+ waittime = self.pyfile.waitUntil - time()
+ log(DEBUG, "waiting %ss" % waittime)
+
+ if self.wantReconnect:
+ raise Fail("Would wait for reconnect %ss" % waittime )
+ if self.wantReconnect or waittime > 300:
+ raise Fail("Would wait %ss" % waittime )
+
+ while self.pyfile.waitUntil > time():
+ sleep(1)
+ if self.pyfile.abort: raise Abort
+
+ self.waiting = False
+ self.pyfile.setStatus("starting")
+
+Hoster.wait = _wait
+
+Hoster.checkForSameFiles = noop
+
+class PluginTester(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.core = Core()
+
+ def setUp(self):
+ self.thread = Thread(self.core)
+ exc_clear()
+
+ def tearDown(self):
+ exc = exc_info()
+ if exc != (None, None, None):
+ debug = self.thread.writeDebugReport()
+ log(DEBUG, debug)
+ # generate attachment
+ print "\n[[ATTACHMENT|%s]]\n" % abspath(debug) \ No newline at end of file