Skip to content

Clean-up Tests #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Format for pep8 and linters
Fix max min nameclash
  • Loading branch information
vmuriart committed Jan 31, 2017
commit 8c3fe2b49cccbde90d765dffd3c85fd591e06dca
12 changes: 6 additions & 6 deletions src/tests/leaktest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def end_test(self):
end = System.Environment.WorkingSet
diff = end - start
if diff > 0:
diff = '+%d' % diff
diff = '+{0}'.format(diff)
else:
diff = '%d' % diff
print(" start: %d end: %d diff: %s" % (start, end, diff))
diff = '{0}'.format(diff)
print(" start: {0} end: {1} diff: {2}".format(start, end, diff))
print("")

def run(self):
Expand Down Expand Up @@ -203,10 +203,10 @@ def test_events(self):
testob.PublicEvent -= EventTest.StaticHandler

# Function event handler
dict = {'value': None}
dict_ = {'value': None}

def handler(sender, args, dict=dict):
dict['value'] = args.value
def handler(sender, args, dict_=dict_):
dict_['value'] = args.value

testob.PublicEvent += handler
testob.PublicEvent(testob, TestEventArgs(10))
Expand Down
4 changes: 2 additions & 2 deletions src/tests/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def main():
start = time.clock()

for i in range(50):
print('iteration: %d' % i)
print('iteration: {0:d}'.format(i))
runtests.main()

stop = time.clock()
took = str(stop - start)
print('Total Time: %s' % took)
print('Total Time: {0}'.format(took))

for item in gc.get_objects():
print(item, sys.getrefcount(item))
Expand Down
2 changes: 1 addition & 1 deletion src/tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
def remove_pyc():
path = os.path.dirname(os.path.abspath(__file__))
for name in test_modules:
pyc = os.path.join(path, "%s.pyc" % name)
pyc = os.path.join(path, "{0}.pyc".format(name))
if os.path.isfile(pyc):
os.unlink(pyc)

Expand Down
35 changes: 15 additions & 20 deletions src/tests/stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
import time

from _compat import range, thread


def dprint(msg):
# Debugging helper to trace thread-related tests.
if 1:
print(msg)
from utils import dprint


class StressTest(object):
Expand All @@ -35,47 +30,47 @@ def __init__(self):
self.module = runtests
self.done = []

def markStart(self):
def mark_start(self):
self._start = time.clock()

def markFinish(self):
def mark_finish(self):
self._finish = time.clock()

def elapsed(self):
return self._finish - self._start

def printGCReport(self):
def print_gc_report(self):
for item in gc.get_objects():
print(item, sys.getrefcount(item))

def runThread(self, iterations):
def run_thread(self, iterations):
thread_id = thread.get_ident()
dprint("thread %s starting..." % thread_id)
dprint("thread {0} starting...".format(thread_id))
time.sleep(0.1)
for i in range(iterations):
dprint("thread %s iter %d start" % (thread_id, i))
dprint("thread {0} iter {1} start".format(thread_id, i))
self.module.main()
dprint("thread %s iter %d end" % (thread_id, i))
dprint("thread {0} iter {1} end".format(thread_id, i))
self.done.append(None)
dprint("thread %s done" % thread_id)
dprint("thread {0} done".format(thread_id))

def stressTest(self, iterations=1, threads=1):
def stress_test(self, iterations=1, threads=1):
args = (iterations,)
self.markStart()
self.mark_start()
for _ in range(threads):
thread = threading.Thread(target=self.runThread, args=args)
thread = threading.Thread(target=self.run_thread, args=args)
thread.start()
while len(self.done) < (iterations * threads):
dprint(len(self.done))
time.sleep(0.1)
self.markFinish()
self.mark_finish()
took = self.elapsed()
self.printGCReport()
self.print_gc_report()


def main():
test = StressTest()
test.stressTest(2, 10)
test.stress_test(2, 10)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stresstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main():

stop = time.clock()
took = str(stop - start)
print('Total Time: %s' % took)
print('Total Time: {0}'.format(took))

for i in gc.get_objects():
print(i)
Expand Down
Loading