summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-17 20:11:06 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-17 20:11:06 +0200
commitba3686d499f6df9793989486d178cbc55f1ee4bf (patch)
tree90108f9a81005509a99bbec53c6b73b7952e52a0
parentPEP-8, Python Zen, refactor and reduce code (part 5 in master module/cli) (diff)
downloadpyload-ba3686d499f6df9793989486d178cbc55f1ee4bf.tar.xz
PEP-8, Python Zen, refactor and reduce code (part 6 in master module/common)
Conflicts: locale/pavement.py module/common/ImportDebugger.py module/common/JsEngine.py module/common/json_layer.py module/common/packagetools.py tests/APIExerciser.py tests/test_api.py tests/test_json.py
-rw-r--r--pyload/utils/pylgettext.py3
-rw-r--r--tests/APIExerciser.py36
2 files changed, 16 insertions, 23 deletions
diff --git a/pyload/utils/pylgettext.py b/pyload/utils/pylgettext.py
index 1f31cf42d..86cfc586a 100644
--- a/pyload/utils/pylgettext.py
+++ b/pyload/utils/pylgettext.py
@@ -48,7 +48,8 @@ def find(domain, localedir=None, languages=None, all=False):
results = filter(lambda x: x is not None, results)
if len(results) == 0:
return None
- return results[0]
+ else:
+ return results[0]
else:
return results
diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py
index 7eec6f828..32a3304c0 100644
--- a/tests/APIExerciser.py
+++ b/tests/APIExerciser.py
@@ -3,15 +3,15 @@
import string
from threading import Thread
-from random import choice, random, sample, randint
-from time import time, sleep
+from random import choice, sample, randint
+from time import time
from math import floor
import gc
-
from traceback import print_exc, format_exc
from pyload.remote.thriftbackend.ThriftClient import ThriftClient, Destination
+
def createURLs():
""" create some urls, some may fail """
urls = []
@@ -24,6 +24,7 @@ def createURLs():
return urls
+
AVOID = (0, 3, 8)
idPool = 0
@@ -31,12 +32,11 @@ sumCalled = 0
def startApiExerciser(core, n):
- for i in range(n):
+ for _ in range(n):
APIExerciser(core).start()
class APIExerciser(Thread):
-
def __init__(self, core, thrift=False, user=None, pw=None):
global idPool
@@ -46,17 +46,13 @@ class APIExerciser(Thread):
self.count = 0 #: number of methods
self.time = time()
- if thrift:
- self.api = ThriftClient(user=user, password=pw)
- else:
- self.api = core.api
-
+ self.api = ThriftClient(user=user, password=pw) if thrift else core.api
self.id = idPool
idPool += 1
- #self.start()
+ # self.start()
def run(self):
@@ -64,7 +60,7 @@ class APIExerciser(Thread):
self.core.log.info("API Excerciser started %d" % self.id)
out = open("error.log", "ab")
- #core errors are not logged of course
+ # core errors are not logged of course
out.write("\n" + "Starting\n")
out.flush()
@@ -88,9 +84,7 @@ class APIExerciser(Thread):
self.core.log.info("Approx. %.2f calls per second." % persec)
self.core.log.info("Approx. %.2f ms per call." % (1000 / persec))
self.core.log.info("Collected garbage: %d" % gc.collect())
-
-
- #sleep(random() / 500)
+ # sleep(random() / 500)
def testAPI(self):
@@ -98,10 +92,10 @@ class APIExerciser(Thread):
m = ["statusDownloads", "statusServer", "addPackage", "getPackageData", "getFileData", "deleteFiles",
"deletePackages", "getQueue", "getCollector", "getQueueData", "getCollectorData", "isCaptchaWaiting",
- "getCaptchaTask", "stopAllDownloads", "getAllInfo", "getServices" , "getAccounts", "getAllUserData"]
+ "getCaptchaTask", "stopAllDownloads", "getAllInfo", "getServices", "getAccounts", "getAllUserData"]
method = choice(m)
- #print "Testing:", method
+ # print "Testing:", method
if hasattr(self, method):
res = getattr(self, method)()
@@ -111,7 +105,7 @@ class APIExerciser(Thread):
self.count += 1
sumCalled += 1
- #print res
+ # print res
def addPackage(self):
@@ -120,7 +114,6 @@ class APIExerciser(Thread):
self.api.addPackage(name, urls, choice([Destination.Queue, Destination.Collector]))
-
def deleteFiles(self):
info = self.api.getQueueData()
if not info: return
@@ -132,14 +125,13 @@ class APIExerciser(Thread):
fids = [f.fid for f in sample(fids, randint(1, max(len(fids) / 2, 1)))]
self.api.deleteFiles(fids)
-
def deletePackages(self):
info = choice([self.api.getQueue(), self.api.getCollector()])
if not info: return
pids = [p.pid for p in info]
- if len(pids):
- pids = sample(pids, randint(1, max(floor(len(pids) / 2.5), 1)))
+ if pids:
+ pids = sample(pids, randint(1, max(floor(len(pids) / 2.5), 1)))
self.api.deletePackages(pids)