From 612971a8c416ad1bcc42cd7c46b60afe153527be Mon Sep 17 00:00:00 2001 From: Jonathan Cairns Date: Sun, 6 May 2012 18:00:36 +0100 Subject: [PATCH] Started on Python line parser --- plugin/cakephp.py | 58 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/plugin/cakephp.py b/plugin/cakephp.py index 4154f66..533a80a 100644 --- a/plugin/cakephp.py +++ b/plugin/cakephp.py @@ -10,19 +10,59 @@ def parse_test_output( ): k = 0 firsterr = -1 numfails = 0 + parser = TestOutputParser() for line in fd: - if k == firsterr: - parsing = True - if parsing: - print line if found == True: - p = re.compile('There (?:were|was) ([0-9]*) failure',line) - m = p.match(line) - numfails = m.group(1) - firsterr = k+2 - break + parser.parseLine(line) if "Time: " in line: found = True k = k + 1 + +class TestError: + type = "E" + def __init__(self,message,file,line): + self.message = message + self.file = file + self.line = line + +class TestFailure(TestError): + def __init__(self,message,file,line): + TestError.__init__(self,message,file,line) + self.type = "F" + + +class TestErrorManager: + def __init__(self): + self.errors = [] + self.failures = [] + + def addError(self,error): + self.errors.add(error) + + def addFailure(self,failure): + self.failures.add(failure) + +class TestOutputParser: + parsingErrors = False + parsingFailures = False + + def __init__(self): + self.errors = TestErrorManager() + + def parseLine(self,line): + + matchObj = re.match('There (?:were|was) ([0-9]*) (error|failure)',line,re.M) + if matchObj: + numfails = matchObj.group(1) + type = matchObj.group(2) + if type == "error": + self.parsingErrors = True + print "Parsing errors" + else: + self.parsingFailures = True + print "Parsing failures" + else: + print "No match" + print line