~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to test_on_merge.py

  • Committer: Stuart Bishop
  • Date: 2006-03-22 14:16:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3321.
  • Revision ID: stuart.bishop@canonical.com-20060322141607-0a237d0cb3b6b634
Make test_on_merge.py do incremental output

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import tabnanny
9
9
from StringIO import StringIO
10
10
import psycopg
11
 
from subprocess import Popen, PIPE
 
11
from subprocess import Popen, PIPE, STDOUT
12
12
from signal import SIGKILL, SIGTERM
13
13
from select import select
14
14
 
144
144
    os.chdir(here)
145
145
    cmd = [sys.executable, 'test.py'] + sys.argv[1:]
146
146
    print ' '.join(cmd)
147
 
    # This would be simpler if we set stderr=STDOUT to combine the streams
148
 
    proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
 
147
    proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
149
148
    proc.stdin.close()
150
149
 
151
150
    # Do proc.communicate(), but timeout if there's no activity on stdout or
152
151
    # stderr for too long.
153
 
    out =  [] # stdout from tests
154
 
    err = [] # stderr from tests
155
 
    open_readers = set([proc.stderr, proc.stdout])
156
 
    while open_readers:
 
152
    open_readers = set([proc.stdout])
 
153
    while True:
157
154
        rlist, wlist, xlist = select(open_readers, [], [], TIMEOUT)
158
155
 
159
156
        if len(rlist) == 0:
168
165
            break
169
166
 
170
167
        if proc.stdout in rlist:
171
 
            out.append(os.read(proc.stdout.fileno(), 1024))
172
 
            if out[-1] == "":
173
 
                open_readers.remove(proc.stdout)
174
 
        if proc.stderr in rlist:
175
 
            err.append(os.read(proc.stderr.fileno(), 1024))
176
 
            if err[-1] == "":
177
 
                open_readers.remove(proc.stderr)
178
 
 
179
 
    test_ok = (proc.wait() == 0)
180
 
 
181
 
    out = ''.join(out)
182
 
    err = ''.join(err)
183
 
 
184
 
    if test_ok:
185
 
        for line in err.split('\n'):
186
 
            if re.match('^Ran\s\d+\stest(s)?\sin\s[\d\.]+s$', line):
187
 
                print line
188
 
        return 0
 
168
            chunk = os.read(proc.stdout.fileno(), 1024)
 
169
            if chunk == "":
 
170
                continue
 
171
            print chunk,
 
172
 
 
173
    rv == proc.wait()
 
174
    if rv == 0:
 
175
        print '\nSuccessfully run tests.'
189
176
    else:
190
 
        print '---- test stdout ----'
191
 
        print out
192
 
        print '---- end test stdout ----'
193
 
 
194
 
        print '---- test stderr ----'
195
 
        print err
196
 
        print '---- end test stderr ----'
197
 
        return 1
 
177
        print '\nTests failed (exit code %d)' % rv
 
178
 
 
179
    return rv
 
180
 
198
181
 
199
182
def killem(pid, signal):
200
183
    """Kill the process group leader identified by pid and other group members