summaryrefslogtreecommitdiff
path: root/tools
diff options
authorThomi Richards <thomi.richards@canonical.com>2012-02-29 11:17:07 +1300
committerThomi Richards <thomi.richards@canonical.com>2012-02-29 11:17:07 +1300
commitf300be1cfc3ab4467bbe2708d21fddbc26e2f523 (patch)
tree1f15ae345395f65649c96f7a218e5bb2d582573c /tools
parent204a4f6a740577014dd1d0d6eb25bdc342376592 (diff)
Moved run_autopilot script, made it report missing dependancies, and made it patch sys.path if needed.
(bzr r2035.2.1)
Diffstat (limited to 'tools')
-rwxr-xr-xtools/run_autopilot108
1 files changed, 108 insertions, 0 deletions
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()