~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to buildout-templates/bin/jstest.in

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-15 20:25:35 UTC
  • mfrom: (13447.1.3 rm-old-tools)
  • Revision ID: launchpad@pqm.canonical.com-20110715202535-mpzonuqa8mdwir8u
[rs=sinzui][no-qa] Removed spidermonkey-bin,
 pocketlint does js linting. Removed windmill utilities that do not
 run since the test layer was removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!${buildout:executable} -S
2
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
3
 
# GNU Affero General Public License version 3 (see the file LICENSE).
4
 
 
5
 
"""
6
 
A script for running all of the windmill JavaScript integration test suites
7
 
in Launchpad.  Aggregates the result of running each suite into a global
8
 
pass or fail value.
9
 
 
10
 
The script exit codes are:
11
 
    0: suite success
12
 
    1: suite error
13
 
    2: suite failure
14
 
 
15
 
"""
16
 
 
17
 
# Initialize our paths.
18
 
${python-relative-path-setup}
19
 
import sys
20
 
sys.path.insert(0, ${scripts:parts-directory|path-repr})
21
 
import site
22
 
 
23
 
import subprocess
24
 
import os
25
 
from lp.scripts.utilities.lpwindmill import runLaunchpad
26
 
 
27
 
 
28
 
# Test runner configuration hash
29
 
runner_config = {
30
 
    'runner':  'bin/windmill',
31
 
    'port':    8085,
32
 
    'browser': 'firefox',
33
 
}
34
 
 
35
 
# A hash of test suites to run.  Each key has two parts: the path to the test
36
 
# suite root directory (relative to the test root directory) and the domain
37
 
# that the test runner must use during suite execution.
38
 
test_suites = {
39
 
    'registry': {
40
 
        'suite_dir': 'lib/canonical/launchpad/windmill/tests/test_registry',
41
 
        'domain':    'launchpad.dev'
42
 
    },
43
 
    'bugs': {
44
 
        'suite_dir': 'lib/lp/bugs/windmill',
45
 
        'domain':    'bugs.launchpad.dev'
46
 
    },
47
 
    'code': {
48
 
        'suite_dir': 'lib/lp/code/windmill',
49
 
        'domain':    'code.launchpad.dev'
50
 
    },
51
 
    'soyuz': {
52
 
        'suite_dir': 'lib/lp/soyuz/windmill',
53
 
        'domain':    'launchpad.dev'
54
 
    },
55
 
    'translations': {
56
 
        'suite_dir': 'lib/lp/translations/windmill',
57
 
        'domain':    'translations.launchpad.dev'
58
 
    },
59
 
}
60
 
 
61
 
 
62
 
def run_suite(suite_config):
63
 
    """Run a JavaScript test suite using the given suite configuration."""
64
 
    config = runner_config.copy()
65
 
    config['url'] = 'http://%s:%s' % (
66
 
        suite_config['domain'],
67
 
        runner_config['port'])
68
 
    config['suite'] = suite_config['suite_dir']
69
 
 
70
 
    # Do we have a test runner?
71
 
    if not os.path.exists(config['runner']):
72
 
        sys.stderr.write(
73
 
            "Error: Couldn't find the testrunner executable: %s\n" % (
74
 
                config['runner']))
75
 
        sys.exit(1)
76
 
 
77
 
    # Do we have a test suite?
78
 
    if not os.path.exists(config['suite']):
79
 
        sys.stderr.write(
80
 
            "Error: Couldn't find the test suite: %s\n" % config['suite'])
81
 
        sys.exit(1)
82
 
 
83
 
    # The final test runner call.
84
 
    # Should be something like: windmill -e test=foo/bar firefox http://blah
85
 
    # Pass '-e' to the runner so it exits after suite completion.
86
 
    test_command = [
87
 
        config['runner'],
88
 
        "-e",
89
 
        "test=%s" % config['suite'],
90
 
        config['browser'],
91
 
        config['url'],
92
 
    ]
93
 
 
94
 
    try:
95
 
        return subprocess.call(test_command)
96
 
    except OSError, e:
97
 
        sys.stderr.write(
98
 
            "Error: Test command failed to execute: " + test_command + "\n")
99
 
        sys.stderr.write("Exiting\n")
100
 
        sys.exit(1)
101
 
 
102
 
 
103
 
def run_all_windmills():
104
 
    """Run all of the available test suites.
105
 
 
106
 
    Returns the number of test suites that failed.
107
 
    """
108
 
    # Set up the launchpad instance, and install the atexit handlers that
109
 
    # will clean everything up when this script exits.
110
 
    runLaunchpad()
111
 
 
112
 
    failures = 0
113
 
 
114
 
    for suite_name, suite_config in test_suites.items():
115
 
        print "Running the %s test suite" % suite_name
116
 
 
117
 
        exit_status = run_suite(suite_config)
118
 
 
119
 
        if exit_status != 0:
120
 
            print "Failure: Test failures in the %s test suite" % suite_name
121
 
            print
122
 
            failures += 1
123
 
 
124
 
    return failures
125
 
 
126
 
 
127
 
if __name__ == '__main__':
128
 
    failures = run_all_windmills()
129
 
    if failures != 0:
130
 
        print "Failed: %d test suites failed" % failures
131
 
        sys.exit(2)
132
 
    else:
133
 
        print "Success: all suites passed"
134
 
        sys.exit(0)