Commit 713ef0e7 authored by zhifan huang's avatar zhifan huang

add enter-point for unittest at setup;;add test runner script

parent e83b20d6
import sys
import os
import unittest
import time
from StringIO import StringIO
import json
from re6st.tests import *
class TestResult(unittest.TextTestResult):
def startTestRun(self):
self.start = time.time()
def stopTestRun(self):
""" custom report dict"""
self.end = time.time()
self.report = dict(test_count = self.testsRun,
error_count = len(self.errors),
failure_count = len(self.failures),
skip_count = len(self.skipped),
duration = round(self.end - self.start, 2),
date = time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(self.start))
)
class runner(unittest.TextTestRunner):
def _makeResult(self):
return TestResult(self.stream, self.descriptions, self.verbosity)
def load_test():
test_module = [(name,mod) for name, mod in globals().items() if name.split('_',1)[0] == 'test']
test_case = {}
for name, mod in test_module:
if hasattr(mod, "__all__"):
test_module += \
[( name+ "." + sub_mod, getattr(mod, sub_mod)) for sub_mod in mod.__all__ ]
else:
test_case[name] = unittest.TestLoader().loadTestsFromModule(mod)
return test_case
def main():
test_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(test_dir)
test_case = load_test()
result = {}
for case, suite in test_case.items():
err = StringIO()
result[case] = runner(stream=err, verbosity=3).run(suite).report
sys.stderr.write("\n-------%s start--------\n" % case)
sys.stderr.write(err.getvalue())
sys.stderr.write(json.dumps(result[case]) + '\n')
sys.stderr.write("\n-------%s end--------\n" % case)
result[case]['stderr'] = err.getvalue()
err.close()
print json.dumps(result)
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -81,6 +81,7 @@ setup(
're6st-conf=re6st.cli.conf:main',
're6stnet=re6st.cli.node:main',
're6st-registry=re6st.cli.registry:main',
're6st-testrunner=re6st.tests.runner:main'
],
},
package_data = {
......@@ -94,10 +95,12 @@ setup(
install_requires = ['pyOpenSSL >= 0.13', 'miniupnpc'],
extras_require = {
'geoip': ['geoip2'],
'test': ['mock', 'pathlib2']
},
#dependency_links = [
# "http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.7.20120714.tar.gz#egg=miniupnpc-1.7",
# ],
zip_safe = False,
cmdclass=dict(build_py=build_py, sdist=sdist),
test_suite="tests",
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment