diff options
| -rwxr-xr-x | tests/autopilot/bin/run_autopilot | 46 | ||||
| -rwxr-xr-x | tools/run_autopilot | 108 |
2 files changed, 108 insertions, 46 deletions
diff --git a/tests/autopilot/bin/run_autopilot b/tests/autopilot/bin/run_autopilot deleted file mode 100755 index 030692438..000000000 --- a/tests/autopilot/bin/run_autopilot +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import junitxml -from argparse import ArgumentParser -from unittest.loader import TestLoader -from unittest.runner import TextTestRunner - - -if __name__ == "__main__": - parser = ArgumentParser() - parser.add_argument('-o', "--output", required=False, - help='Write test result report to file. Defaults to stdout') - parser.add_argument('-f', "--format", choices=['text', 'xml'], default='text', - required=False, help='Specify desired output format. Default is "text".') - args = parser.parse_args() - - if args.output == None: - results_stream = sys.stdout - else: - try: - path = os.path.dirname(args.output) - if path != '' and not os.path.exists(path): - os.makedirs(path) - results_stream = open(args.output, 'w') - except: - results_stream = sys.stdout - - loader = TestLoader() - test_suite = loader.discover('autopilot.tests') - - if args.format == "xml": - result = junitxml.JUnitXmlResult(results_stream) - result.startTestRun() - test_suite.run(result) - result.stopTestRun() - results_stream.close() - if not result.wasSuccessful: - exit(1) - elif args.format == "text": - runner = TextTestRunner(stream=results_stream) - success = runner.run(test_suite).wasSuccessful() - if not success: - exit(1) - diff --git a/tools/run_autopilot b/tools/run_autopilot new file mode 100755 index 000000000..6bb93bf00 --- /dev/null +++ b/tools/run_autopilot @@ -0,0 +1,108 @@ +#!/usr/bin/env python + +from imp import find_module +import os +import os.path +import sys +from textwrap import dedent +import junitxml +from argparse import ArgumentParser +from unittest.loader import TestLoader +from unittest.runner import TextTestRunner + + +# list autopilot depends here, with the form: +# ('python module name', 'ubuntu package name'), +DEPENDS = [ + ('compizconfig', 'python-compizconfig'), + ('dbus', 'python-dbus'), + ('gobject', 'python-gobject'), + ('gtk', 'python-gtk2'), + ('ibus', 'python-ibus'), + ('testscenarios', 'python-testscenarios'), + ('testtools', 'python-testtools'), + ('Xlib', 'python-xlib'), +] + + +def check_depends(): + """Check for required dependancies, and print a helpful message if any are + missing. + + If all required modules are present, return True, False otherwise. + """ + missing = [] + for module_name, package_name in DEPENDS: + try: + find_module(module_name) + except ImportError: + missing.append(package_name) + if missing: + print dedent("""\ + You are missing one or more packages required to run autopilot. They + are: + + %s + + Please install these packages and re-run this script. + """ % (' '.join(missing)) + ) + return False + return True + + +def ensure_autopilot_is_importable(): + """Patch sys.path with the local autopilot directory if it's not already + importable. + """ + try: + find_module("autopilot") + except ImportError: + ap_dir = os.path.join(os.path.dirname(__file__), + "../tests/autopilot") + ap_dir = os.path.realpath(ap_dir) + sys.path.append(ap_dir) + print "Patching sys.path to include local autopilot folder '%s'" % ap_dir + + +def main(): + parser = ArgumentParser() + parser.add_argument('-o', "--output", required=False, + help='Write test result report to file. Defaults to stdout') + parser.add_argument('-f', "--format", choices=['text', 'xml'], default='text', + required=False, help='Specify desired output format. Default is "text".') + args = parser.parse_args() + + if args.output == None: + results_stream = sys.stdout + else: + try: + path = os.path.dirname(args.output) + if path != '' and not os.path.exists(path): + os.makedirs(path) + results_stream = open(args.output, 'w') + except: + results_stream = sys.stdout + + loader = TestLoader() + test_suite = loader.discover('autopilot.tests') + + if args.format == "xml": + result = junitxml.JUnitXmlResult(results_stream) + result.startTestRun() + test_suite.run(result) + result.stopTestRun() + results_stream.close() + if not result.wasSuccessful: + exit(1) + elif args.format == "text": + runner = TextTestRunner(stream=results_stream) + success = runner.run(test_suite).wasSuccessful() + if not success: + exit(1) + +if __name__ == "__main__": + if not check_depends(): + exit(1) + ensure_autopilot_is_importable() + main() |
