mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-07 05:42:42 +00:00
Refactor system tests to live together in one package.
This commit is contained in:
+30
-11
@@ -1,9 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/local/bin/python
|
||||
|
||||
import glob
|
||||
import importlib
|
||||
import os
|
||||
import inspect
|
||||
import sys
|
||||
|
||||
from lib import BaseTest
|
||||
from termcolor import colored
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
@@ -11,29 +16,43 @@ def run():
|
||||
"""
|
||||
tests = glob.glob("t*_*")
|
||||
fails = []
|
||||
numTests = numFailed = 0
|
||||
|
||||
for test in tests:
|
||||
sys.stdout.write("%s..." % (test, ))
|
||||
|
||||
testModule = importlib.import_module(test)
|
||||
t = testModule.Test()
|
||||
|
||||
try:
|
||||
t.test()
|
||||
except BaseException, e:
|
||||
fails.append((test, t, e, testModule))
|
||||
sys.stdout.write("FAIL\n")
|
||||
else:
|
||||
sys.stdout.write("OK\n")
|
||||
for name in dir(testModule):
|
||||
o = getattr(testModule, name)
|
||||
|
||||
if not (inspect.isclass(o) and issubclass(o, BaseTest) and o is not BaseTest):
|
||||
continue
|
||||
|
||||
t = o()
|
||||
numTests += 1
|
||||
|
||||
sys.stdout.write("%s:%s... " % (test, o.__name__))
|
||||
|
||||
try:
|
||||
t.test()
|
||||
except BaseException, e:
|
||||
numFailed += 1
|
||||
fails.append((test, t, e, testModule))
|
||||
sys.stdout.write("FAIL\n")
|
||||
else:
|
||||
sys.stdout.write(colored("OK\n", color="green"))
|
||||
|
||||
print "TESTS: %d SUCCESS: %d FAIL: %d" % (numTests, numTests - numFailed, numFailed)
|
||||
|
||||
if len(fails) > 0:
|
||||
print "\nFAILURES (%d):" % (len(fails), )
|
||||
|
||||
for (test, t, e, testModule) in fails:
|
||||
print "%s: %s" % (test, testModule.__doc__.strip())
|
||||
print "%s:%s %s" % (test, t.__class__.__name__, testModule.__doc__.strip() + ": " + t.__doc__.strip())
|
||||
print "ERROR: %s" % (e, )
|
||||
print "=" * 60
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.realpath(os.path.dirname(sys.argv[0])))
|
||||
run()
|
||||
|
||||
Reference in New Issue
Block a user