summaryrefslogtreecommitdiffstats
path: root/tests/helper
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-03-06 13:36:39 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-03-06 13:36:39 +0100
commit4df2b77fdf42046fe19bd371be7c7255986b5980 (patch)
tree2a7227a0d22e03dc2c085514eaab36a7e5e612c4 /tests/helper
parentssl fix (diff)
downloadpyload-4df2b77fdf42046fe19bd371be7c7255986b5980.tar.xz
renamed hooks to addons, new filemanager and database, many new api methods
you will loose ALL your LINKS, webinterface will NOT work
Diffstat (limited to 'tests/helper')
-rw-r--r--tests/helper/BenchmarkTest.py66
-rw-r--r--tests/helper/Stubs.py11
2 files changed, 73 insertions, 4 deletions
diff --git a/tests/helper/BenchmarkTest.py b/tests/helper/BenchmarkTest.py
new file mode 100644
index 000000000..d28c52959
--- /dev/null
+++ b/tests/helper/BenchmarkTest.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+from time import time
+
+
+class BenchmarkTest:
+
+ bench = []
+ results = {}
+
+ @classmethod
+ def timestamp(cls, name, a):
+ t = time()
+ r = cls.results.get(name, [])
+ r.append((t-a) * 1000)
+ cls.results[name] = r
+
+ @classmethod
+ def benchmark(cls, n=1):
+
+ print "Benchmarking %s" % cls.__name__
+ print
+
+ for i in range(n):
+ cls.collect_results()
+
+ if "setUpClass" in cls.results:
+ cls.bench.insert(0, "setUpClass")
+
+ if "tearDownClass" in cls.results:
+ cls.bench.append("tearDownClass")
+
+ length = str(max([len(k) for k in cls.bench]) + 1)
+ total = 0
+
+ for k in cls.bench:
+ v = cls.results[k]
+
+ if len(v) > 1:
+ print ("%" + length +"s: %s | average: %.2f ms") % (k, ", ".join(["%.2f" % x for x in v]), sum(v)/len(v))
+ total += sum(v)/len(v)
+ else:
+ print ("%" + length +"s: %.2f ms") % (k, v[0])
+ total += v[0]
+
+ print "\ntotal: %.2f ms" % total
+
+
+ @classmethod
+ def collect_results(cls):
+ if hasattr(cls, "setUpClass"):
+ a = time()
+ cls.setUpClass()
+ cls.timestamp("setUpClass", a)
+
+ obj = cls()
+
+ for f in cls.bench:
+ a = time()
+ getattr(obj, "test_" + f)()
+ cls.timestamp(f, a)
+
+ if hasattr(cls, "tearDownClass"):
+ a = time()
+ cls.tearDownClass()
+ cls.timestamp("tearDownClass", a) \ No newline at end of file
diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py
index ade15f0c4..be2f5052b 100644
--- a/tests/helper/Stubs.py
+++ b/tests/helper/Stubs.py
@@ -58,8 +58,8 @@ class Core:
def __init__(self):
self.log = NoLog()
- self.api = self
- self.core = self
+ self.api = self.core = self
+ self.threadManager = self
self.debug = True
self.captcha = True
self.config = ConfigParser()
@@ -67,7 +67,7 @@ class Core:
self.requestFactory = RequestFactory(self)
__builtin__.pyreq = self.requestFactory
self.accountManager = AccountManager()
- self.hookManager = self.eventManager = self.interActionManager = NoopClass()
+ self.addonManager = self.eventManager = self.interActionManager = NoopClass()
self.js = JsEngine()
self.cache = {}
self.packageCache = {}
@@ -86,6 +86,9 @@ class Core:
def updatePackage(self, *args):
pass
+ def processingIds(self, *args):
+ return []
+
def getPackage(self, id):
return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0)
@@ -118,5 +121,5 @@ class Thread(BaseThread):
__builtin__._ = lambda x: x
__builtin__.pypath = abspath(join(dirname(__file__), "..", ".."))
-__builtin__.hookManager = NoopClass()
+__builtin__.addonManager = NoopClass()
__builtin__.pyreq = None