summaryrefslogtreecommitdiffstats
path: root/tests/helper/PluginTester.py
diff options
context:
space:
mode:
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