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
예제 #2
0
    def init(self, testTotals, summaryTotals, file, recursion):
        self.testTotals = testTotals # "y", "e", "n"
        self.summaryTotals = summaryTotals # "f", "t", "n"
        self.runType = file # "h", "d", "l", "r"
        if self.runType == "d":
            if recursion is True:
                self.runType = "r"
        # let's have some sanity here...
        if self.runType == "h":
            self.summaryTotals = "n"
        elif self.runType == "d":
            if self.summaryTotals == "f":
                self.summaryTotals = "t"
        elif self.runType == "r":
            if self.summaryTotals == "t":
                self.summaryTotals = "f"
        conMsg.notes("Result print level in effect. "
                    "Files: '%s' Summaries: '%s'\n" %
                   (self.testTotals, self.summaryTotals))
        self.currDir = None
        self.dirCounts = None
        self.finalCounts = Counts()

        self.lastPrintedDirectoryCounts = None
        self.dirHeaderPrinted = False
        self.newDirectory = True

        self.directorySummariesNeeded = False
        if (self.runType in ("r", "l") and
            self.summaryTotals == "f"):
            self.directorySummariesNeeded = True
예제 #3
0
 def testTwoEndsOfPage(self):
     obj = fsi.StatsHandler("outputDir", "SuiteName", "localhost", 80)
     obj.endOfATest("pageTitle", Counts(), {})
     obj.endOfATest("secondPage", Counts(), {})
     assert len(obj._pageList) == 2
     assert obj._pageList[0][0] == "pageTitle"
     assert obj._pageList[1][0] == "secondPage"
예제 #4
0
 def shouldRaiseErrorOnWrongTypeToTabulateCount(self):
     count1 = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions")
     #        count2 = Counts(right=4, wrong=6, ignored=2, exceptions=5)
     try:
         count1.tabulateCount(3.14)
     except:
         return
     self.fail("Expected exception not received")
예제 #5
0
 def testGeneratedXML(self):
     obj = fsi.StatsHandler("outputDir", "SuiteName", "localhost", 80)
     obj.endOfATest("pageTitle", Counts(5, 0, 0, 0), {"fee": "fi"})
     obj.endOfATest("secondPage", Counts(6, 2, 0, 0), {"fo": "fum"})
     text = obj.endOfAllTests()
     assert text.startswith('<?xml version="1.0"?>')
     assert text.count("<right>") == 3
     print text
예제 #6
0
    def shouldRaiseErrorOnWrongTypeToTabulateCount(self):
        count1 = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions")
#        count2 = Counts(right=4, wrong=6, ignored=2, exceptions=5)
        try:
            count1.tabulateCount(3.14)
        except:
            return
        self.fail("Expected exception not received")
예제 #7
0
 def shouldCompareToAnotherCounts(self):
     count1 = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions")
     count2 = Counts(right=4, wrong=6, ignored=2, exceptions=5)
     assert count1 != count2
     assert not (count1 == count2)
     assert not count1.equals(count2)  # depreciated!!!
     assert count1 == "1 right, 0 wrong, 15 ignored, 8 exceptions"
     assert not (count1 == 45)
     assert not (count1 != 45)
예제 #8
0
 def shouldCompareToAnotherCounts(self):
     count1 = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions")
     count2 = Counts(right=4, wrong=6, ignored=2, exceptions=5)
     assert count1 != count2
     assert not (count1 == count2)
     assert not count1.equals(count2) # depreciated!!!
     assert count1 == "1 right, 0 wrong, 15 ignored, 8 exceptions"
     assert not (count1 == 45)
     assert not (count1 != 45)
예제 #9
0
 def _captureSummaryCounts(self, path, testCounts):
     if testCounts is None:
         testCounts = Counts(0, 0, 1, 0)
     self.finalCounts.summarize(testCounts)
     dirName, fileName = FG.fsa.split(path)
     if self.currDir != dirName:
         self._printDirectoryTotal()
         self.dirCounts = Counts()
         self.currDir = dirName
         self.dirHeaderPrinted = False
         self.newDirectory = True
     self.dirCounts.summarize(testCounts)
class TestRunnerFixtureListener(object):
    counts = Counts()
    _atStartOfResult = True
    _currentPageResult = None  # PageResult
    _runner = None  # TestRunner instance

    def __init__(self, runner):
        self._runner = runner
        self._atStartOfResult = True
        self.counts = Counts()

    def createPage(self, table):
        indexOfFirstLineBreak = table.leader.find("\n")
        pageTitle = table.leader[:indexOfFirstLineBreak]
        table.leader = table.leader[indexOfFirstLineBreak + 1:]
        self._currentPageResult = PageResult(pageTitle)
        self._atStartOfResult = False

    def tablesStarted(self, table):
        pass
##        if self._atStartOfResult:
##            indexOfFirstLineBreak = table.leader.find("\n")
##            pageTitle = table.leader[:indexOfFirstLineBreak]
##            table.leader = table.leader[indexOfFirstLineBreak + 1:]
##            self._currentPageResult = PageResult(pageTitle)
##            self._atStartOfResult = False

    def tableFinished(self, table):
        data = table.oneHTMLTagToString().encode("UTF-8")
        self._currentPageResult.append(data)
##        type, info, tb = sys.exc_info()
##        traceList = traceback.format_exception(type, info, tb)
##        conMsg.tmsg("".join(traceList))

    def tablesFinished(self, count):
        self._currentPageResult.setCounts(count)
        self._runner.acceptResults(self._currentPageResult)
        self.counts.tally(count)
        self._atStartOfResult = True
##            type, info, tb = sys.exc_info()
##            traceList = traceback.format_exception(type, info, tb)
##            conMsg.tmsg("".join(traceList))

##    def getPageName(self):
##        parts = self._currentPageResult.fullPageName().split(".")
##        return ".".join(parts[-2:])

# this is for FitServer, it should be silent for TestRunner

    def writeCounts(self, counts, verbose):
        return
예제 #11
0
class TestRunnerFixtureListener(object):
    counts = Counts()
    _atStartOfResult = True
    _currentPageResult = None # PageResult
    _runner = None # TestRunner instance

    def __init__(self, runner):
        self._runner = runner
        self._atStartOfResult = True
        self.counts = Counts()

    def createPage(self, table):
        indexOfFirstLineBreak = table.leader.find("\n")
        pageTitle = table.leader[:indexOfFirstLineBreak]
        table.leader = table.leader[indexOfFirstLineBreak + 1:]
        self._currentPageResult = PageResult(pageTitle)
        self._atStartOfResult = False

    def tablesStarted(self, table):
        pass
##        if self._atStartOfResult:
##            indexOfFirstLineBreak = table.leader.find("\n")
##            pageTitle = table.leader[:indexOfFirstLineBreak]
##            table.leader = table.leader[indexOfFirstLineBreak + 1:]
##            self._currentPageResult = PageResult(pageTitle)
##            self._atStartOfResult = False

    def tableFinished(self, table):
        data = table.oneHTMLTagToString().encode("UTF-8")
        self._currentPageResult.append(data)
##        type, info, tb = sys.exc_info()
##        traceList = traceback.format_exception(type, info, tb)
##        conMsg.tmsg("".join(traceList))

    def tablesFinished(self, count):
        self._currentPageResult.setCounts(count)
        self._runner.acceptResults(self._currentPageResult)
        self.counts.tally(count)
        self._atStartOfResult = True
##            type, info, tb = sys.exc_info()
##            traceList = traceback.format_exception(type, info, tb)
##            conMsg.tmsg("".join(traceList))

##    def getPageName(self):
##        parts = self._currentPageResult.fullPageName().split(".")
##        return ".".join(parts[-2:])

    # this is for FitServer, it should be silent for TestRunner
    def writeCounts(self, counts, verbose):
        return
예제 #12
0
 def shouldMarkIncorrectSymbolReferenceAsWrong(self):
     table = Parse("<table><tr><td>fit.RowFixture</td></tr>"
                   "<tr><td>c1</td><td>c2</td><td>c3=</td></tr>"
                   "<tr><td>Three</td><td>Blind</td><td>a</td></tr>"
                   "<tr><td>Lord</td><td>Lova</td><td>b</td></tr>"
                   "<tr><td>Larry</td><td>Moe</td><td>c</td></tr>"
                   "</table>")
     coll = [
         ProcObj("Three", "Blind", "Mice"),
         ProcObj("Lord", "Lova", "Duck"), {
             "c1": "Larry",
             "c2": "Moe",
             "c3": "Curly"
         }
     ]
     metaData = {"c1": "String", "c2": "String", "c3": "String"}
     fix = RowFixture(coll, metaData)
     fix.setSymbol("a", "Mice")
     fix.setSymbol("b", "Duck")
     fix.setSymbol("c", "Laurel")
     fix.doTable(table)
     ##        label1 = table.parts.more.parts
     ##        em("\n%s" % table.toNodeList())
     ##        cell = table.parts.more.more.more.more.parts.more.more
     ##        em("tag: %s body: %s" % (cell.tag, cell.body))
     assert fix.counts == Counts(8, 1)
예제 #13
0
    def init(self, testTotals, summaryTotals, file, recursion):
        self.testTotals = testTotals # "y", "e", "n"
        self.summaryTotals = summaryTotals # "f", "t", "n"
        self.runType = file # "h", "d", "l", "r"
        if self.runType == "d":
            if recursion is True:
                self.runType = "r"
        # let's have some sanity here...
        if self.runType == "h":
            self.summaryTotals = "n"
        elif self.runType == "d":
            if self.summaryTotals == "f":
                self.summaryTotals = "t"
        elif self.runType == "r":
            if self.summaryTotals == "t":
                self.summaryTotals = "f"
        conMsg.notes("Result print level in effect. "
                    "Files: '%s' Summaries: '%s'\n" %
                   (self.testTotals, self.summaryTotals))
        self.currDir = None
        self.dirCounts = None
        self.finalCounts = Counts()

        self.lastPrintedDirectoryCounts = None
        self.dirHeaderPrinted = False
        self.newDirectory = True

        self.directorySummariesNeeded = False
        if (self.runType in ("r", "l") and
            self.summaryTotals == "f"):
            self.directorySummariesNeeded = True
예제 #14
0
 def shouldAccumulateCountEnumerations(self):
     count = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions")
     count += Count("right")
     count += Count("wrong")
     count += Count("ignored")
     count += Count("exception")
     assert str(count) == "2 right, 1 wrong, 16 ignored, 9 exceptions"
예제 #15
0
 def shouldPutMessageInCellForUnprintableAttributeInSurplusRow(self):
     table = Parse("<table><tr><td>fit.RowFixture</td></tr>"
                   "<tr><td>c1</td><td>Huh</td><td>c3</td></tr>"
                   "<tr><td>Three</td><td>Blind</td><td>Mice</td></tr>"
                   "<tr><td>Lord</td><td>Lova</td><td>Duck</td></tr>"
                   "<tr><td>Larry</td><td>Moe</td><td>Curly</td></tr>"
                   "</table>")
     coll = [
         ProcObj("Three", "Blind", "Mice"),
         ProcObj("Lord", "Lova", "Duck"), {
             "c1": "Larry",
             "Huh": "Moe",
             "c3": "Curly"
         }, {
             "c1": "Larry",
             "Huh": u"\u00a1",
             "c3": "Curly"
         }
     ]
     coll[0].Huh = "Blind"
     coll[1].Huh = "says to"
     metaData = {"c1": "String", "c2": "String", "c3": "String"}
     fix = RowFixture(coll, metaData)
     fix.doTable(table)
     ##        em("\n%s" % table.toNodeList())
     cell = table.parts.more.more.more.more.more.parts.more
     ##        em("tag: %s body: %s" % (cell.tag, cell.body))
     assert cell.body.find("[error extracting value]") > -1
     assert fix.counts == Counts(8, 2, 0, 1)
예제 #16
0
파일: Tests.py 프로젝트: radiocutfm/pyfit
 def count(self, data):
     counts = Counts()
     while (data != None):
         if   data.tagIsRight():   counts.right += 1
         elif data.tagIsWrong():   counts.wrong += 1
         elif data.tagIsError():   counts.exceptions += 1
         elif data.tagIsIgnored(): counts.ignores += 1
         data = data.more
     return counts
예제 #17
0
 def shouldTakeStringConstructor(self):
     count = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions")
     assert str(count) == "1 right, 0 wrong, 15 ignored, 8 exceptions"
     assert str(count) == count.toString()  # depreciated!
     assert count.totalCounts() == 24
     assert count.isError()
     assert count.numErrors() == 8
     assert not count.isSummaryCount()
예제 #18
0
 def __init__(self):
     # most of these are updated by dependency injection either
     # in one of the runners or in the recursive invocation in doTables.
     self.counts = Counts()
     self.summary = {}
     self.args = []
     self.argCells = []
     #        self._symbols = {}
     self.listener = NullFixtureListener()
     self.fixtureLoader = FixtureLoader()
class FitNesseTestExecutor(object):

    input = ""
    tables = None  # table
    counts = Counts()
    options = None  #Option object from Options or TestRunner

    def __init__(self, listener, options):
        self.fixtureListener = listener
        self._renameFileName = ""
        self.options = options
        self.counts = Counts()

    def process(self, renamesFile=""):
        self._renameFileName = renamesFile
        self.fixture = Fixture()
        self.fixture.listener = self.fixtureListener
        self.fixture.listener.runner = self
        try:
            while True:
                try:
                    self._newFixture()
                    size = FitProtocol.readSize(netIn)
                    if not size: break
                    conMsg.tmsg("processing document of size: %s \n" % size)
                    document = FitProtocol.readDocument(netIn, size)
                    firstSep = document.find("\n")
                    if firstSep > -1:
                        docName = document[:firstSep]
                    else:
                        conMsg.emsg("Malformed Document received!. Exiting!")
                        raise Exception("Malformed Document received!")
                    conMsg.tmsg("new document: '%s'" % docName)
                    tables = Parse(document)
                    shouldExecute = FG.appConfigInterface(
                        "beforeTestExecution", docName, tables)
                    if shouldExecute is not False:
                        ##                        outDir = getattr(self.options, "outputDir", None)
                        ##                        if outDir:
                        ##                            docName = docName or "The Test"
                        ##                            FG.outFileName = (
                        ##                                "%s/%s.html" % (outDir, docName))
                        self.fixture.listener.createPage(tables)
                        self.fixture.doTables(tables)
                        self.fixture.listener.writeCounts(
                            self.fixture.counts, self.options.verbose)
                        self.counts += self.fixture.counts
                        FG.appConfigInterface("afterTestExecution",
                                              self.fixture.counts,
                                              self.fixture.summary)
                except ParseException, e:
                    self.handleParseException(e, docName)
            conMsg.tmsg("completion signal received\n")
        except Exception, e:
            self.exception(e)
예제 #20
0
 def interpretTables(self, tables):
     embeddedTables = self.makeEmbeddedTables(tables)
     fixture = Fixture()
     self.injectDependenciesIntoFixture(fixture, tables)
     fixture.counts = Counts()
     #        fixture.counts = self.embeddedCounts
     fixture.summary = self.embeddedSummary
     fixture.listener = NullFixtureListener()
     fixture.doTables(embeddedTables)
     self.checkMarkingsOfTables(tables, embeddedTables)
     self.signalTables(tables)
예제 #21
0
 def run(self):
     FG.inFileName = FG.fsa.abspath(self.inFileName)
     FG.outFileName = FG.fsa.abspath(self.outFileName)
     head, tail = FG.fsa.split(self.inFileName)
     try:
         stack.push(head)
         self.parseTree = self.getParseTree(self.inFileName)
         self.parseTree = stack.wrapParseTree(self.parseTree)
         stack.pop()
     except Exception, e:
         FG.appConfigInterface("beforeTestExecution",
                                     FG.inFileName, e)
         conMsg.err("Unexpected Exception in parsing %s" % FG.inFileName)
         print "Unexpected Exception in parsing %s" % FG.inFileName
         exType, exInfo, exTrace = sys.exc_info()
         traceback.print_exception(exType, exInfo, exTrace,
                                   None, sys.stdout)
         traceback.print_exception(exType, exInfo, exTrace,
                                   None, conMsg)
         conTotal.fileResult(self.inFileName, Counts(0,0,0,1))
         return Counts(0,0,0,1)
예제 #22
0
 def _captureSummaryCounts(self, path, testCounts):
     if testCounts is None:
         testCounts = Counts(0, 0, 1, 0)
     self.finalCounts.summarize(testCounts)
     dirName, fileName = FG.fsa.split(path)
     if self.currDir != dirName:
         self._printDirectoryTotal()
         self.dirCounts = Counts()
         self.currDir = dirName
         self.dirHeaderPrinted = False
         self.newDirectory = True
     self.dirCounts.summarize(testCounts)
예제 #23
0
 def shouldTakeStringConstructor(self):
     count = Counts("1 right, 0 wrong, 15 ignored, 8 exceptions")
     assert str(count) == "1 right, 0 wrong, 15 ignored, 8 exceptions"
     assert str(count) == count.toString() # depreciated!
     assert count.totalCounts() == 24
     assert count.isError()
     assert count.numErrors() == 8
     assert not count.isSummaryCount()
예제 #24
0
 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
예제 #25
0
 def shouldHandleUndefinedAttributeInCollectionElement(self):
     table = Parse("<table><tr><td>fit.RowFixture</td></tr>"
                   "<tr><td>c1</td><td>c2</td><td>c3</td></tr>"
                   "<tr><td>Three</td><td>Blind</td><td>Mice</td></tr>"
                   "<tr><td>Lord</td><td>Lova</td><td>Duck</td></tr>"
                   "<tr><td>Lord</td><td>Lova</td><td>Duck</td></tr>"
                   "<tr><td>Larry</td><td>Moe</td><td>Curly</td></tr>"
                   "</table>")
     coll = [
         ProcObj("Three", "Blind", "Mice"),
         ProcObj("Lord", "Lova", "Duck"), {
             "missing": "Larry",
             "c2": "Moe",
             "c3": "Curly"
         }
     ]
     metaData = {"c1": "String", "c2": "String", "c3": "String"}
     fix = RowFixture(coll, metaData)
     fix.doTable(table)
     assert fix.counts == Counts(6, 3)
예제 #26
0
 def shouldHandleMissingSymbolInPartitionStep(self):
     table = Parse("<table><tr><td>fit.RowFixture</td></tr>"
                   "<tr><td>c1=</td><td>c2</td><td>c3</td></tr>"
                   "<tr><td>a</td><td>Blind</td><td>Mice</td></tr>"
                   "<tr><td>b</td><td>Lova</td><td>Duck</td></tr>"
                   "<tr><td>c</td><td>Moe</td><td>Curly</td></tr>"
                   "</table>")
     coll = [
         ProcObj("Three", "Blind", "Mice"),
         ProcObj("Lord", "Lova", "Duck"), {
             "c1": "Larry",
             "c2": "Moe",
             "c3": "Curly"
         }
     ]
     metaData = {"c1": "String", "c2": "String", "c3": "String"}
     fix = RowFixture(coll, metaData)
     fix.setSymbol("b", "Lord")
     fix.setSymbol("c", "Larry")
     fix.doTable(table)
     assert fix.counts == Counts(6, 1, 2, 1)
예제 #27
0
 def shouldHandleSymbolicReferencesInLastColumn(self):
     table = Parse("<table><tr><td>fit.RowFixture</td></tr>"
                   "<tr><td>c1</td><td>c2</td><td>c3=</td></tr>"
                   "<tr><td>Three</td><td>Blind</td><td>a</td></tr>"
                   "<tr><td>Lord</td><td>Lova</td><td>b</td></tr>"
                   "<tr><td>Larry</td><td>Moe</td><td>c</td></tr>"
                   "</table>")
     coll = [
         ProcObj("Three", "Blind", "Mice"),
         ProcObj("Lord", "Lova", "Duck"), {
             "c1": "Larry",
             "c2": "Moe",
             "c3": "Curly"
         }
     ]
     metaData = {"c1": "String", "c2": "String", "c3": "String"}
     fix = RowFixture(coll, metaData)
     fix.setSymbol("a", "Mice")
     fix.setSymbol("b", "Duck")
     fix.setSymbol("c", "Curly")
     fix.doTable(table)
     #        label1 = table.parts.more.parts
     assert fix.counts == Counts(9)
예제 #28
0
 def shouldMarkShortRowAsMissingWithException(self):
     table = Parse("<table><tr><td>fit.RowFixture</td></tr>"
                   "<tr><td>c1</td><td>c2</td><td>c3</td></tr>"
                   "<tr><td>Three</td><td>Blind</td><td>Mice</td></tr>"
                   "<tr><td>Lord</td><td>Lova</td></tr>"
                   "<tr><td>Larry</td><td>Moe</td><td>Curly</td></tr>"
                   "</table>")
     coll = [
         ProcObj("Three", "Blind", "Mice"),
         ProcObj("Lord", "Lova", "Duck"), {
             "c1": "Larry",
             "c2": "Moe",
             "c3": "Curly"
         }
     ]
     metaData = {"c1": "String", "c2": "String", "c3": "String"}
     fix = RowFixture(coll, metaData)
     fix.doTable(table)
     ##        em("\n%s" % table.toNodeList())
     ##        label1 = table.parts.more.parts
     ##        em("tag: %s body: %s" % (label1.tag, label1.body))
     ##        cell = table.parts.more.more.more.parts
     ##        em("tag: %s body: %s" % (cell.tag, cell.body))
     assert fix.counts == Counts(6, 1, 0, 1)
예제 #29
0
 def shouldHandleUndefinedColumnWithStringMismatch(self):
     table = Parse("<table><tr><td>fit.RowFixture</td></tr>"
                   "<tr><td>c1</td><td>Huh</td><td>c3</td></tr>"
                   "<tr><td>Three</td><td>Blind</td><td>Mice</td></tr>"
                   "<tr><td>Lord</td><td>Lova</td><td>Duck</td></tr>"
                   "<tr><td>Larry</td><td>Moe</td><td>Curly</td></tr>"
                   "</table>")
     coll = [
         ProcObj("Three", "Blind", "Mice"),
         ProcObj("Lord", "Lova", "Duck"), {
             "c1": "Larry",
             "Huh": "Moe",
             "c3": "Curly"
         }
     ]
     coll[0].Huh = "Blind"
     coll[1].Huh = "says to"
     metaData = {"c1": "String", "c2": "String", "c3": "String"}
     fix = RowFixture(coll, metaData)
     fix.doTable(table)
     ##        em("\n%s" % table.toNodeList())
     ##        cell = table.parts.more.parts.more
     ##        em("tag: %s body: %s" % (cell.tag, cell.body))
     assert fix.counts == Counts(8, 1, 0, 1)
예제 #30
0
    def __init__(self, fullPageName, host, port):
#        self.options = options
        self.fullPageName = fullPageName
        self.host = host
        self.port = port
        self._pageCounts = Counts()
예제 #31
0
 def __init__(self, runner):
     self._runner = runner
     self._atStartOfResult = True
     self.counts = Counts()
class FitServer(ServerBase):

    input = ""
    tables = None  # table
    counts = Counts()
    options = None  #Option object from Options
    socketToken = 0

    def __init__(self):
        self.host = "localhost"
        self.port = 80
        self.fixtureListener = TablePrintingFixtureListener()
        self._renameFileName = ""
        FG.Environment = "FitNesse"
        FG.inFileName = ""
        FG.outFileName = ""
        Variations.returnVariation()
        conMsg.setEnvironment("FitServer")

    def run(self, argv):
        result = self.args(argv)
        if not result:
            return result
        self.establishCommonTopLevelOptions(self.options,
                                            self._addToPythonPath)
        self.establishConnection(self._makeHttpRequest(), self.host, self.port)
        self.validateConnection()
        FG.appConfigInterface("beforeRunExecution")
        self.executor = FitNesseTestExecutor(TablePrintingFixtureListener(),
                                             self.options)
        self.counts = self.executor.process(self._renameFileName)
        FG.appConfigInterface("afterRunExecution", self.counts)
        self.closeConnection()
        self.exit()
        return self.exitCode()

    def args(self, argv):
        self.options = Options(argv, SiteOptions.FitServer.parmDict)
        FG.CommandOptions = self.options
        opts = self.options
        errMsgs = opts.eMsgs
        vMsgs = opts.vMsgs
        pos = opts.posParms
        if not opts.isValid:
            for aMsg in errMsgs:
                conMsg.emsg(aMsg)
            self.usage()
            return False

        numIOArgs = net.getNumArgs()  # may be testing mock.
        self._renameFileName = ""
        self._addToPythonPath = []
        if len(pos) == numIOArgs + 1:
            self._addToPythonPath, self._renameFileName = (
                self.extractPythonPath(pos[0], opts))
            pos = pos[1:]
        if len(pos) != numIOArgs:
            conMsg.emsg("wrong number of positional parameters")
            self.usage()
            return False
        fitnesseParmStatus, self.host, self.port, self.socketToken = net.extractParameters(
            pos)
        if fitnesseParmStatus is False:
            self.usage()
            return False
        conMsg.setVerbose(opts.verbose)
        if opts.verbose:
            for aMsg in vMsgs:
                conMsg.smsg(aMsg)
        return True

    # !!! code duplication with SiteOptions.FitServer.parmDict
    def usage(self):
        conMsg.emsg(
            "usage: python FitServer [-v] [PythonPath] host port socketTicket\n"
        )
        conMsg.emsg("\t-v - verbose\n")
        conMsg.emsg("\tThis only runs from the FitNesse server!\n")
        conMsg.emsg("\tIt does not run from the command line\n")

    def exit(self):
        conMsg.smsg("exiting\n")
        conMsg.smsg(str(self.counts))

    def exitCode(self):
        return self.counts.numErrors()

    def _makeHttpRequest(self):
        return ("GET /?responder=socketCatcher&ticket=%s HTTP/1.1\r\n\r\n" %
                self.socketToken)
예제 #33
0
 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"
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
 def __init__(self, fullPageName, host, port):
     #        self.options = options
     self.fullPageName = fullPageName
     self.host = host
     self.port = port
     self._pageCounts = Counts()
예제 #36
0
class ConsoleTotals(object):
    def __init__(self):
        self.testTotals = "n"
        self.summaryTotals = "n"
        self.runType = "h"
        
    def init(self, testTotals, summaryTotals, file, recursion):
        self.testTotals = testTotals # "y", "e", "n"
        self.summaryTotals = summaryTotals # "f", "t", "n"
        self.runType = file # "h", "d", "l", "r"
        if self.runType == "d":
            if recursion is True:
                self.runType = "r"
        # let's have some sanity here...
        if self.runType == "h":
            self.summaryTotals = "n"
        elif self.runType == "d":
            if self.summaryTotals == "f":
                self.summaryTotals = "t"
        elif self.runType == "r":
            if self.summaryTotals == "t":
                self.summaryTotals = "f"
        conMsg.notes("Result print level in effect. "
                    "Files: '%s' Summaries: '%s'\n" %
                   (self.testTotals, self.summaryTotals))
        self.currDir = None
        self.dirCounts = None
        self.finalCounts = Counts()

        self.lastPrintedDirectoryCounts = None
        self.dirHeaderPrinted = False
        self.newDirectory = True

        self.directorySummariesNeeded = False
        if (self.runType in ("r", "l") and
            self.summaryTotals == "f"):
            self.directorySummariesNeeded = True

    def _captureSummaryCounts(self, path, testCounts):
        if testCounts is None:
            testCounts = Counts(0, 0, 1, 0)
        self.finalCounts.summarize(testCounts)
        dirName, fileName = FG.fsa.split(path)
        if self.currDir != dirName:
            self._printDirectoryTotal()
            self.dirCounts = Counts()
            self.currDir = dirName
            self.dirHeaderPrinted = False
            self.newDirectory = True
        self.dirCounts.summarize(testCounts)

    def _printDirectoryTotal(self):
        if self.dirHeaderPrinted:
            conMsg.stats("Total this Directory: %s"
                     % str(self.lastPrintedDirectoryCounts))
            self.dirHeaderPrinted = False

    def _doDirectoryLines(self, path):
        if not self.directorySummariesNeeded:
            return
        dirName, fileName = FG.fsa.split(path)
        if self.newDirectory:
            head, dirName = FG.fsa.split(dirName)
            conMsg.stats("Processing Directory: %s" % dirName)
            self.lastPrintedDirectoryCounts = self.dirCounts
            self.dirHeaderPrinted = True
            self.newDirectory = False

    def fileResult(self, fileName, counts):
        self._captureSummaryCounts(fileName, counts)
        if self.testTotals == "n":
            return
        if self.testTotals == "e":
            if counts is None:
                return
            if not counts.isError():
                return

        self._doDirectoryLines(fileName)
        if self.runType == 'h':
            fileMsg = ""
        else:
            fileMsg = FG.fsa.basename(fileName)
        if counts is None:
            countMsg = "Run Suppressed by Application Exit"
        else:
            countMsg = str(counts)
        conMsg.stats("%s %s" % (countMsg, fileMsg))

    def finalTotal(self):
        self._printDirectoryTotal()
        if self.summaryTotals != "n":
            conMsg.stats("Total tests Processed: %s" %
                         str(self.finalCounts))
        return self.finalCounts
예제 #37
0
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
예제 #38
0
class HTMLRunner(object):
    def __init__(self, inFileName, outFileName, options):
        self.inFileName = inFileName
        self.outFileName = outFileName
        self.options = options

#
# --------- phase 2 --- verify that the files exist.
#

    def verify(self):
        error = False        
        if not FG.fsa.isfile(self.inFileName):
            conMsg.err("%s does not exist!\n" % self.inFileName)
            error = True
        if FG.fsa.isdir(self.outFileName):
            head, tail = FG.fsa.split(self.inFileName)
            self.outFileName = FG.fsa.join(self.outFileName, tail)
        else:
            head, tail = FG.fsa.split(self.outFileName)
            if not FG.fsa.isdir(head):
                conMsg.err("%s is not a directory!" % head)
                error = True
        return not error

#
# -------- Phase 3 - Run the test.
#

    def run(self):
        FG.inFileName = FG.fsa.abspath(self.inFileName)
        FG.outFileName = FG.fsa.abspath(self.outFileName)
        head, tail = FG.fsa.split(self.inFileName)
        try:
            stack.push(head)
            self.parseTree = self.getParseTree(self.inFileName)
            self.parseTree = stack.wrapParseTree(self.parseTree)
            stack.pop()
        except Exception, e:
            FG.appConfigInterface("beforeTestExecution",
                                        FG.inFileName, e)
            conMsg.err("Unexpected Exception in parsing %s" % FG.inFileName)
            print "Unexpected Exception in parsing %s" % FG.inFileName
            exType, exInfo, exTrace = sys.exc_info()
            traceback.print_exception(exType, exInfo, exTrace,
                                      None, sys.stdout)
            traceback.print_exception(exType, exInfo, exTrace,
                                      None, conMsg)
            conTotal.fileResult(self.inFileName, Counts(0,0,0,1))
            return Counts(0,0,0,1)

        shouldExecute = FG.appConfigInterface("beforeTestExecution",
                                        FG.inFileName, self.parseTree)
        if shouldExecute in (True, None):
            self.fixture = Fixture()
            self.fixture.summary["input file"] = FG.inFileName
            self.fixture.summary["input update"] = FG.fsa.timeUpdated(self.inFileName)
            self.fixture.summary["output file"] = FG.outFileName
            self.fixture.doTables(self.parseTree)
            if self.options.outputEncodingForce:
                self.encoding = self.options.outputEncodingForce
                self.encodingType = "OutputOverride"
            if self.options.useCSS:
                outDir, foo = FG.fsa.split(FG.outFileName)
                self._createFitCSSFile(outDir)
                self._addCSSStuffToHeader(self.parseTree)
            self._fixMetaTag(self.parseTree, self.encoding, self.encodingType)
            textOut = self.parseTree.toString()
            self.write(textOut, self.encoding)
            FG.appConfigInterface("afterTestExecution",
                                         self.fixture.counts,
                                         self.fixture.summary)
            conTotal.fileResult(self.inFileName, self.fixture.counts)
            stats.reportStats(FG.inFileName, self.fixture.counts,
                              self.fixture.summary)
            return self.fixture.counts
        else:
            counts = Counts(0,0,1)
            summary = {}
            summary["input file"] = FG.inFileName
            summary["input update"] = FG.fsa.timeUpdated(self.inFileName)
            summary["output file"] = FG.outFileName
            stats.reportStats(FG.inFileName, None, summary)
            conTotal.fileResult(FG.inFileName, None)
            return counts
 def __init__(self, listener, options):
     self.fixtureListener = listener
     self._renameFileName = ""
     self.options = options
     self.counts = Counts()
 def __init__(self, runner):
     self._runner = runner
     self._atStartOfResult = True
     self.counts = Counts()
예제 #41
0
 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"
예제 #42
0
class ConsoleTotals(object):
    def __init__(self):
        self.testTotals = "n"
        self.summaryTotals = "n"
        self.runType = "h"
        
    def init(self, testTotals, summaryTotals, file, recursion):
        self.testTotals = testTotals # "y", "e", "n"
        self.summaryTotals = summaryTotals # "f", "t", "n"
        self.runType = file # "h", "d", "l", "r"
        if self.runType == "d":
            if recursion is True:
                self.runType = "r"
        # let's have some sanity here...
        if self.runType == "h":
            self.summaryTotals = "n"
        elif self.runType == "d":
            if self.summaryTotals == "f":
                self.summaryTotals = "t"
        elif self.runType == "r":
            if self.summaryTotals == "t":
                self.summaryTotals = "f"
        conMsg.notes("Result print level in effect. "
                    "Files: '%s' Summaries: '%s'\n" %
                   (self.testTotals, self.summaryTotals))
        self.currDir = None
        self.dirCounts = None
        self.finalCounts = Counts()

        self.lastPrintedDirectoryCounts = None
        self.dirHeaderPrinted = False
        self.newDirectory = True

        self.directorySummariesNeeded = False
        if (self.runType in ("r", "l") and
            self.summaryTotals == "f"):
            self.directorySummariesNeeded = True

    def _captureSummaryCounts(self, path, testCounts):
        if testCounts is None:
            testCounts = Counts(0, 0, 1, 0)
        self.finalCounts.summarize(testCounts)
        dirName, fileName = FG.fsa.split(path)
        if self.currDir != dirName:
            self._printDirectoryTotal()
            self.dirCounts = Counts()
            self.currDir = dirName
            self.dirHeaderPrinted = False
            self.newDirectory = True
        self.dirCounts.summarize(testCounts)

    def _printDirectoryTotal(self):
        if self.dirHeaderPrinted:
            conMsg.stats("Total this Directory: %s"
                     % str(self.lastPrintedDirectoryCounts))
            self.dirHeaderPrinted = False

    def _doDirectoryLines(self, path):
        if not self.directorySummariesNeeded:
            return
        dirName, fileName = FG.fsa.split(path)
        if self.newDirectory:
            head, dirName = FG.fsa.split(dirName)
            conMsg.stats("Processing Directory: %s" % dirName)
            self.lastPrintedDirectoryCounts = self.dirCounts
            self.dirHeaderPrinted = True
            self.newDirectory = False

    def fileResult(self, fileName, counts):
        self._captureSummaryCounts(fileName, counts)
        if self.testTotals == "n":
            return
        if self.testTotals == "e":
            if counts is None:
                return
            if not counts.isError():
                return

        self._doDirectoryLines(fileName)
        if self.runType == 'h':
            fileMsg = ""
        else:
            fileMsg = FG.fsa.basename(fileName)
        if counts is None:
            countMsg = "Run Suppressed by Application Exit"
        else:
            countMsg = str(counts)
        conMsg.stats("%s %s" % (countMsg, fileMsg))

    def finalTotal(self):
        self._printDirectoryTotal()
        if self.summaryTotals != "n":
            conMsg.stats("Total tests Processed: %s" %
                         str(self.finalCounts))
        return self.finalCounts