From 20226f8cc5889efbefa61209e1adf6184d42cd00 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 17 Apr 2015 01:21:41 +0200 Subject: Spare code cosmetics (3) --- tests/test_json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_json.py b/tests/test_json.py index f87a32139..a83ef0a24 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -14,7 +14,7 @@ class TestJson(object): def call(self, name, post=None): if not post: post = {} - post["session"] = self.key + post['session'] = self.key u = urlopen(url % name, data=urlencode(post)) return loads(u.read()) -- cgit v1.2.3 From 938b7e6141e2895c7d41b0e8ef4b9416912e2e9e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 17 Apr 2015 17:28:58 +0200 Subject: Spare code cosmetics (4) --- tests/APIExerciser.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py index 38dd9fceb..7eec6f828 100644 --- a/tests/APIExerciser.py +++ b/tests/APIExerciser.py @@ -34,6 +34,7 @@ def startApiExerciser(core, n): for i in range(n): APIExerciser(core).start() + class APIExerciser(Thread): def __init__(self, core, thrift=False, user=None, pw=None): -- cgit v1.2.3 From 817a3d66e6ddaf90e4649212dae4c240a0847c9c Mon Sep 17 00:00:00 2001 From: fedeG Date: Sun, 7 Dec 2014 17:54:34 -0300 Subject: PEP-8, Python Zen, refactor and reduce code (part 4 in master script). Bash varible $VAR to ${VAR} Conflicts: scripts/clonedigger.sh scripts/code_analysis.sh --- tests/clonedigger.sh | 2 +- tests/code_analysis.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/clonedigger.sh b/tests/clonedigger.sh index 641e7ff64..4c53eab0d 100644 --- a/tests/clonedigger.sh +++ b/tests/clonedigger.sh @@ -1,4 +1,4 @@ #!/bin/sh PYLOAD="../pyload" # Check pyload directory -clonedigger -o cpd.xml --cpd-output --fast --ignore-dir="remote" $PYLOAD +clonedigger -o cpd.xml --cpd-output --fast --ignore-dir="remote" ${PYLOAD} diff --git a/tests/code_analysis.sh b/tests/code_analysis.sh index c4dc8e99a..cba614929 100644 --- a/tests/code_analysis.sh +++ b/tests/code_analysis.sh @@ -4,12 +4,12 @@ PYLOAD="../pyload" # Check pyload directory echo "Running sloccount ..." REPORT="sloccount.sc" -sloccount --duplicates --wide --details $PYLOAD > $REPORT && echo "Done. Report saved to $REPORT" +sloccount --duplicates --wide --details ${PYLOAD} > ${REPORT} && echo "Done. Report saved to $REPORT" echo "Running pep8 ..." REPORT="pep8.txt" -pep8 $PYLOAD > $REPORT && echo "Done. Report saved to $REPORT" +pep8 ${PYLOAD} > ${REPORT} && echo "Done. Report saved to $REPORT" echo "Running pylint ..." REPORT="pylint.txt" -pylint --reports=no $PYLOAD > $REPORT && echo "Done. Report saved to $REPORT" +pylint --reports=no ${PYLOAD} > ${REPORT} && echo "Done. Report saved to $REPORT" -- cgit v1.2.3 From ba3686d499f6df9793989486d178cbc55f1ee4bf Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 17 Apr 2015 20:11:06 +0200 Subject: 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 --- tests/APIExerciser.py | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'tests') 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) -- cgit v1.2.3 From bb5a115533711fd8bb87f53cb32ff7342137208d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 18 Apr 2015 00:29:55 +0200 Subject: Spare code cosmetics (5) --- tests/APIExerciser.py | 11 ++++++++--- tests/test_api.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py index 32a3304c0..d17f81ae2 100644 --- a/tests/APIExerciser.py +++ b/tests/APIExerciser.py @@ -32,11 +32,12 @@ sumCalled = 0 def startApiExerciser(core, n): - for _ in range(n): + for _i in range(n): APIExerciser(core).start() class APIExerciser(Thread): + def __init__(self, core, thrift=False, user=None, pw=None): global idPool @@ -114,9 +115,11 @@ class APIExerciser(Thread): self.api.addPackage(name, urls, choice([Destination.Queue, Destination.Collector])) + def deleteFiles(self): info = self.api.getQueueData() - if not info: return + if not info: + return pack = choice(info) fids = pack.links @@ -125,9 +128,11 @@ 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 + if not info: + return pids = [p.pid for p in info] if pids: diff --git a/tests/test_api.py b/tests/test_api.py index 9c12da51c..13e783d54 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -20,5 +20,5 @@ class TestApi(object): @nottest def test_random(self): - for _ in range(0, 100): + for _i in range(0, 100): self.api.testAPI() -- cgit v1.2.3