7
from optparse import OptionParser
9
from subunit import ProtocolTestCase
11
from launchpadlib.launchpad import Launchpad
14
DEFAULT_CONSUMER_NAME = "Launchpad Results"
15
DEFAULT_SERVICE_ROOT = "http://localhost:8000/api/"
20
def __init__(self, test_run):
21
self.test_run = test_run
23
def startTest(self, test):
26
def stopTest(self, test):
29
def addFailure(self, test, details):
30
self.test_run.addTestResult(test.id(), status="Fail")
32
def addSuccess(self, test, details):
33
self.test_run.addTestResult(test.id(), status="Pass")
36
def parse_stream(project, stream):
37
test_run = project.createTestRun()
39
result = Result(test_run)
40
protocol = ProtocolTestCase(stream)
43
def parse_filename(project, filename):
44
stream = open(filename)
46
parse_stream(project, stream)
50
def parse_filenames(project, filenames):
51
for filename in filenames:
52
parse_filename(project, filename)
55
usage = "Usage: %prog [OPTIONS] PROJECT [FILE...]"
56
parser = OptionParser(usage=usage)
57
parser.add_option("--consumer-name",
58
default=DEFAULT_CONSUMER_NAME,
59
help="The consumer appropriate for this application")
60
parser.add_option("--service-root",
61
default=DEFAULT_SERVICE_ROOT,
62
help="The URL to the root of the web service")
63
(options, args) = parser.parse_args(args)
65
# Get project from the Launchpad service root
67
parser.error("Must provide a project name")
69
launchpad = Launchpad.login_with(options.consumer_name, options.service_root)
70
project = launchpad.projects[args.pop(0)]
73
if not args or (len(args) == 1 and args[0] == "-"):
74
parse_stream(project, sys.stdin)
76
# Or from filenames given as arguments
78
parse_filenames(project, args)
83
if __name__ == "__main__":
84
sys.exit(main(sys.argv[1:]))