Skip to content

Instantly share code, notes, and snippets.

@jonah-williams
Forked from farcaller/tc_proxy.py
Created April 26, 2010 22:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonah-williams/380053 to your computer and use it in GitHub Desktop.
Save jonah-williams/380053 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys, subprocess, re
RX_SUITE_START = re.compile(r"Test Suite '(?P<suitename>\w+)' started at (?P<date>[\d\-]+) (?P<time>[\d\:]+) (?P<tz>[\d\-\+]+)")
RX_SUITE_END = re.compile(r"Test Suite '(?P<suitename>\w+)' finished at (?P<date>[\d\-]+) (?P<time>[\d\:]+) (?P<tz>[\d\-\+]+)")
RX_TEST_START = re.compile(r"Test Case '(?P<testname>[^']+)' started\.")
RX_TEST_END = re.compile(r"Test Case '(?P<testname>[^']+)' passed \((?P<sec>[\d\.]+) seconds\)\.")
RX_TEST_FAIL = re.compile(r"Test Case '(?P<testname>[^']+)' failed \((?P<sec>[\d\.]+) seconds\)\.")
ALL_RE = [
(RX_SUITE_START, "##teamcity[testSuiteStarted name='%(suitename)s' timestamp='%(date)sT%(time)s%(tz)s']", None),
(RX_SUITE_END, "##teamcity[testSuiteFinished name='%(suitename)s' timestamp='%(date)sT%(time)s%(tz)s']", None),
(RX_TEST_START, "##teamcity[testStarted name='%(testname)s' captureStandardOutput='true']", None),
(RX_TEST_END, "##teamcity[testFinished name='%(testname)s' duration='%(dur)s']", lambda d:dict(d,dur=str(float(d['sec'])*1000)) ),
(RX_TEST_FAIL, "##teamcity[testFailed name='%(testname)s' duration='%(dur)s']", lambda d:dict(d,dur=str(float(d['sec'])*1000)) ),
]
def process_line(line):
sline = line.strip()
for rx, trans, proc in ALL_RE:
m = rx.match(sline)
if m:
d = {}
for k,v in m.groupdict().iteritems():
v = v.replace('|', '||').replace("'", "|'").replace('\n', '|n').replace('\r', '|r').replace(']', '|]')
d[k] = v
if proc:
d = proc(d)
return (trans % d) + '\n'
return line
def spawn_xcode():
pop = subprocess.Popen(['xcodebuild', '-target', 'Tests', '-sdk', 'macosx10.6', '-configuration', 'Debug',],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return pop
def process_tests(pop):
while pop.poll() == None:
l = pop.stdout.readline()
print process_line(l),
for l in pop.stdout.readlines():
l = pop.stdout.readline()
print process_line(l),
if __name__ == '__main__':
process_tests(spawn_xcode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment