|
import sys |
|
import argparse |
|
import os |
|
import unittest |
|
import subprocess |
|
|
|
test_dir = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
parser = argparse.ArgumentParser(add_help=False) |
|
parser.add_argument('-s', '--save-result', nargs='?', type=str, default=None) |
|
args, remaining = parser.parse_known_args() |
|
|
|
UNITTEST_ARGS = [sys.argv[0]] + remaining |
|
|
|
|
|
def wait_for_process(p): |
|
try: |
|
return p.wait() |
|
except KeyboardInterrupt: |
|
|
|
|
|
exit_status = p.wait(timeout=5) |
|
if exit_status is not None: |
|
return exit_status |
|
else: |
|
p.kill() |
|
raise |
|
except: |
|
p.kill() |
|
raise |
|
finally: |
|
|
|
p.wait() |
|
|
|
|
|
def shell(command, cwd=None, env=None): |
|
sys.stdout.flush() |
|
sys.stderr.flush() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p = subprocess.Popen(command, universal_newlines=True, cwd=cwd, env=env) |
|
return wait_for_process(p) |
|
|
|
|
|
def run_test(argv=UNITTEST_ARGS): |
|
if args.save_result is not None: |
|
test_report_path = test_dir + "/" + args.save_result |
|
with open(test_report_path, "a") as report_file: |
|
runner = unittest.TextTestRunner(stream=report_file, verbosity=2) |
|
unittest.main(argv=argv, testRunner=runner) |
|
else: |
|
runner = unittest.TextTestRunner(verbosity=2) |
|
unittest.main(argv=argv, testRunner=runner) |
|
|
|
|
|
if __name__ == "__main__": |
|
run_test() |
|
|