def endOfAllTests(self): suiteCount = Counts() textList = [ '<?xml version="1.0"?>\n', "<testResults>\n", " <host>%s:%s</host>\n" % (self._netName, self._port), " <rootPath>%s</rootPath>\n" % self._suiteName, ] for pageName, counts, summary in self._pageList: textList.append(" <result>\n") textList.append(" <relativePageName>\n") textList.append(" %s\n" % pageName) textList.append(" </relativePageName>\n") textList.append(" <counts>\n") self._countsToXML(counts, textList, " ") textList.append(" </counts>\n") self._summaryToXML(summary, textList) textList.append(" </result>\n") suiteCount.tallyPageCounts(counts) textList.append(" <finalCounts>\n") self._countsToXML(suiteCount, textList, " ") textList.append(" </finalCounts>\n") textList.append("</testResults>\n") self._text = "".join(textList) return self._text
def shouldTallyPageCounts(self): accum = Counts() assert not accum.isSummaryCount() ex1 = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions") accum.tallyPageCounts(ex1) assert accum.isSummaryCount() assert str(accum) == "0 right, 0 wrong, 0 ignored, 1 exceptions" ex2 = Counts("1 right, 0 wrong, 15 ignored, 0 exceptions") accum.tallyPageCounts(ex2) assert str(accum) == "1 right, 0 wrong, 0 ignored, 1 exceptions" ex3 = Counts("0 right, 0 wrong, 15 ignored, 0 exceptions") accum.tallyPageCounts(ex3) assert str(accum) == "1 right, 0 wrong, 1 ignored, 1 exceptions" ex4 = Counts("5 right, 1 wrong, 15 ignored, 0 exceptions") accum.tallyPageCounts(ex4) assert str(accum) == "1 right, 1 wrong, 1 ignored, 1 exceptions"
def endOfAllTests(self): suiteCount = Counts() textList = ['<?xml version="1.0"?>\n', "<testResults>\n", " <host>%s:%s</host>\n" % (self._netName, self._port), " <rootPath>%s</rootPath>\n" % self._suiteName, ] for pageName, counts, summary in self._pageList: textList.append(" <result>\n") textList.append(" <relativePageName>\n") textList.append(" %s\n" % pageName) textList.append(" </relativePageName>\n") textList.append(" <counts>\n") self._countsToXML(counts, textList, " ") textList.append(" </counts>\n") self._summaryToXML(summary, textList) textList.append(" </result>\n") suiteCount.tallyPageCounts(counts) textList.append(" <finalCounts>\n") self._countsToXML(suiteCount, textList, " ") textList.append(" </finalCounts>\n") textList.append("</testResults>\n") self._text = "".join(textList) return self._text
class StandardResultHandler(object): _pageCounts = Counts() currentSuite = "" def __init__(self, fullPageName, host, port): # self.options = options self.fullPageName = fullPageName self.host = host self.port = port self._pageCounts = Counts() def acceptResult(self, result): opts = FG.Options counts = result.counts() self._pageCounts.tallyPageCounts(counts) if opts.verbose: if opts.onlyError is False or counts.isError(): pageDescription = result.fullPageName() parts = pageDescription.split(".") left = ".".join(parts[:-1]) right = parts[-1] if left != self.currentSuite: self.currentSuite = left conMsg.rmsg("processing Suite: %s\n" % self.currentSuite) conMsg.rmsg("%s %s\n" % (str(counts), right)) if opts.onlyError is False or counts.isError(): if opts.rawOutput: rawOutputFileName = self.writeRawOutput(result) elif opts.HTMLOutput and opts.useFormattingOptions: rawOutputFileName = self.writeRawOutputToTempFile(result) else: rawOutputFileName = "" if opts.HTMLOutput: self.writeHTMLOutput(result, rawOutputFileName) def _pageDescription(self, result): description = result.title() if description == "": description = "The test" return description def writeRawOutput(self, result): middle = self._pageDescription(result) pathOut = FG.fsa.join(FG.Options.outputDir, middle + ".raw.txt") self._writeRawOutput(result, pathOut) return pathOut def writeRawOutputToTempFile(self, result): pathOut = FG.fsa.join(FG.Options.outputDir, "Temp File.raw.txt") self._writeRawOutput(result, pathOut) return pathOut def _writeRawOutput(self, result, pathOut): text = result.toString().replace("\r", "") rawText = "%010i%s%010i%010i%010i%010i%010i" % ( len(text), text, 0, result.counts().right, result.counts().wrong, result.counts().ignores, result.counts().exceptions) self._writeOutput(pathOut, rawText, mode="wb") return def writeHTMLOutput(self, result, rawOutputFileName): title = self._pageDescription(result) pathOut = FG.fsa.join(FG.Options.outputDir, title + ".html") if FG.Options.useFormattingOptions: self._invokeFormattingOption(rawOutputFileName, "html", pathOut, self.host, self.port, result.fullPageName()) return cssStuff = self.cssStyleTag text = (u"<html><head><title>%s</title>\n" u'<meta http-equiv="content-type" ' u'content="text/html; charset=UTF-8">\n' u"%s</head><body>\n<h1>%s</h1>\n" u"%s\n</body></html>" % (title, cssStuff, title, result.content())) self._writeOutput(pathOut, text) fitLink = '<link rel="stylesheet" href="%s" type="text/css">\n' cssStyleTag = """<style> <!-- .pass { background-color: #AAFFAA; } .fail { background-color: #FFAAAA; } .error { background-color: #FFFFAA; } .ignore { background-color: #CCCCCC; } .fit_stacktrace { font-size: 0.7em; } .fit_label { font-style: italic; color: #C08080; } .fit_grey { color: #808080; } --> </style>\n """ def _invokeFormattingOption(self, pathIn, format, pathOut, host, port, fullPageName): cwd = FG.fsa.getcwd() fullPathIn = FG.fsa.join(cwd, pathIn) fullPathOut = FG.fsa.join(cwd, pathOut) # XXX adjust path for .jar cmd = ("java -cp c:/fitnesse/fitnesse.jar " 'fitnesse.runner.FormattingOption "%s" %s "%s" %s %s %s' % (fullPathIn, format, fullPathOut, host, port, fullPageName)) os.system(cmd) def _writeOutput(self, pathOut, text, mode="w"): if type(text) == type(u""): text = text.encode("utf-8") theFile = FG.fsa.open(pathOut, mode) theFile.write(text) theFile.close() def acceptFinalCount(self, count): conMsg.rmsg("Test Pages: %s\n" % self._pageCounts) conMsg.rmsg("Assertions: %s\n" % count) ## def getByteCount(self): ## return 0 ## ## def getResultStream(self): ## return None def cleanUp(self): return None
class StandardResultHandler(object): _pageCounts = Counts() currentSuite = "" def __init__(self, fullPageName, host, port): # self.options = options self.fullPageName = fullPageName self.host = host self.port = port self._pageCounts = Counts() def acceptResult(self, result): opts = FG.Options counts = result.counts() self._pageCounts.tallyPageCounts(counts) if opts.verbose: if opts.onlyError is False or counts.isError(): pageDescription = result.fullPageName() parts = pageDescription.split(".") left = ".".join(parts[:-1]) right = parts[-1] if left != self.currentSuite: self.currentSuite = left conMsg.rmsg("processing Suite: %s\n" % self.currentSuite) conMsg.rmsg("%s %s\n" % (str(counts), right)) if opts.onlyError is False or counts.isError(): if opts.rawOutput: rawOutputFileName = self.writeRawOutput(result) elif opts.HTMLOutput and opts.useFormattingOptions: rawOutputFileName = self.writeRawOutputToTempFile(result) else: rawOutputFileName = "" if opts.HTMLOutput: self.writeHTMLOutput(result, rawOutputFileName) def _pageDescription(self, result): description = result.title() if description == "": description = "The test" return description def writeRawOutput(self, result): middle = self._pageDescription(result) pathOut = FG.fsa.join(FG.Options.outputDir, middle + ".raw.txt") self._writeRawOutput(result, pathOut) return pathOut def writeRawOutputToTempFile(self, result): pathOut = FG.fsa.join(FG.Options.outputDir, "Temp File.raw.txt") self._writeRawOutput(result, pathOut) return pathOut def _writeRawOutput(self, result, pathOut): text = result.toString().replace("\r", "") rawText = "%010i%s%010i%010i%010i%010i%010i" % (len(text), text, 0, result.counts().right, result.counts().wrong, result.counts().ignores, result.counts().exceptions) self._writeOutput(pathOut, rawText, mode="wb") return def writeHTMLOutput(self, result, rawOutputFileName): title = self._pageDescription(result) pathOut = FG.fsa.join(FG.Options.outputDir, title + ".html") if FG.Options.useFormattingOptions: self._invokeFormattingOption(rawOutputFileName, "html", pathOut, self.host, self.port, result.fullPageName()) return cssStuff = self.cssStyleTag text = (u"<html><head><title>%s</title>\n" u'<meta http-equiv="content-type" ' u'content="text/html; charset=UTF-8">\n' u"%s</head><body>\n<h1>%s</h1>\n" u"%s\n</body></html>" % ( title, cssStuff, title, result.content())) self._writeOutput(pathOut, text) fitLink = '<link rel="stylesheet" href="%s" type="text/css">\n' cssStyleTag = """<style> <!-- .pass { background-color: #AAFFAA; } .fail { background-color: #FFAAAA; } .error { background-color: #FFFFAA; } .ignore { background-color: #CCCCCC; } .fit_stacktrace { font-size: 0.7em; } .fit_label { font-style: italic; color: #C08080; } .fit_grey { color: #808080; } --> </style>\n """ def _invokeFormattingOption(self, pathIn, format, pathOut, host, port, fullPageName): cwd = FG.fsa.getcwd() fullPathIn = FG.fsa.join(cwd, pathIn) fullPathOut = FG.fsa.join(cwd, pathOut) # XXX adjust path for .jar cmd = ("java -cp c:/fitnesse/fitnesse.jar " 'fitnesse.runner.FormattingOption "%s" %s "%s" %s %s %s' % (fullPathIn, format, fullPathOut, host, port, fullPageName)) os.system(cmd) def _writeOutput(self, pathOut, text, mode="w"): if type(text) == type(u""): text = text.encode("utf-8") theFile = FG.fsa.open(pathOut, mode) theFile.write(text) theFile.close() def acceptFinalCount(self, count): conMsg.rmsg("Test Pages: %s\n" % self._pageCounts) conMsg.rmsg("Assertions: %s\n" % count) ## def getByteCount(self): ## return 0 ## ## def getResultStream(self): ## return None def cleanUp(self): return None