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)
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)
class ExampleTests(ColumnFixture): fileName = "" wiki = 0 _typeDict = { "fileName": "String", "file.renameTo": "fileName", "wiki": "Boolean" } def __init__(self): ColumnFixture.__init__(self) self.fileName = "" self.wiki = 0 self.input = "" self.tables = None self.fixture = None self.runCounts = Counts() self.footnote = None self.fileCell = None def run(self): newFileName = "fat/Documents/" + self.fileName inFile = open(newFileName, 'r') theTest = inFile.read() inFile.close() self.fixture = Fixture() self.footnote = None if self.wiki: self.tables = Parse(text=theTest, tags=("wiki", "table", "tr", "td")) else: self.tables = Parse(text=theTest, tags=("table", "tr", "td")) self.fixture.doTables(self.tables) self.runCounts.tally(self.fixture.counts) self.summary["counts run"] = self.runCounts _typeDict["right_"] = "Int" _typeDict["right.renameTo"] = "right_" def right_(self): self.run() return self.fixture.counts.right _typeDict["wrong_"] = "Int" _typeDict["wrong.renameTo"] = "wrong_" def wrong_(self): return self.fixture.counts.wrong _typeDict["ignores"] = "Int" def ignores(self): return self.fixture.counts.ignores _typeDict["exceptions"] = "Int" def exceptions(self): return self.fixture.counts.exceptions def doRow(self, row): self.fileCell = row.leaf() ColumnFixture.doRow(self, row) def wrong(self, cell, actual=None, escape=True): # super(ExampleTests, self) ColumnFixture.wrong(self, cell, actual=actual, escape=escape) if self.footnote == None: self.footnote = self.tables.footnote() self.fileCell.addToBody(self.footnote)
class TestFixtureInStandardsMode(TestCase): def setUp(self): print '%s %s' % (self.id(), self.shortDescription()) setupFitGlobalForTests("Batch", ["+e"]) self.options = Options(["FileRunner", "+v", "+e", "foo", "bar"], BatchBase.parmDict) self.fixture = Fixture() self.fixture.fixtureLoader = MockFixtureLoader() def tearDown(self): setupFitGlobalForTests("Batch") def setMockFixture(self, fixtureName, fixture): self.fixture.fixtureLoader._fixtureTable[fixtureName] = fixture def createParseTree(self, aString): lBracket = aString[0] rBracket = aString[1] cellSep = aString[2] restOfString = aString[3:] result = self._createTables(lBracket, rBracket, cellSep, restOfString) return result def _createTables(self, lBracket, rBracket, cellSep, aString): theRows, restOfString = self._createRows(lBracket, rBracket, cellSep, aString[1:]) nextTableBracket = restOfString.find(lBracket) if nextTableBracket == -1: nextTable = None else: nextTable = self._createTables(lBracket, rBracket, cellSep, restOfString[nextTableBracket:]) return Parse(tag="table", parts=theRows, more=nextTable) def _createRows(self, lBracket, rBracket, cellSep, aString): firstRow, restOfString = self._createRow(lBracket, rBracket, cellSep, aString[1:]) lastRow = firstRow while True: nextRowIndex = restOfString.find(lBracket) endOfTableIndex = restOfString.find(rBracket) if nextRowIndex == -1 or nextRowIndex > endOfTableIndex: break nextRow, restOfString = self._createRow(lBracket, rBracket, cellSep, restOfString[1:]) lastRow.more = nextRow lastRow = nextRow return firstRow, restOfString[1:] def _createRow(self, unused, rBracket, cellSep, aString): # lBracket endOfRowIndex = aString.find(rBracket) beginningOfCellIndex = 0 placeHolder = Parse(tag="td") lastCell = placeHolder while True: endOfCellIndex = aString.find(cellSep, beginningOfCellIndex) if endOfCellIndex == -1 or endOfCellIndex > endOfRowIndex: break nextCell = Parse(tag="td", body=aString[beginningOfCellIndex:endOfCellIndex]) beginningOfCellIndex = endOfCellIndex + 1 lastCell.more = nextCell lastCell = nextCell nextCell = Parse(tag="td", body=aString[beginningOfCellIndex:endOfRowIndex]) lastCell.more = nextCell theRow = Parse(tag="tr", parts=placeHolder.more) return theRow, aString[endOfRowIndex+1:] def testDoRowNotInvokedForSingleRowTable(self): htmlTree = self.createParseTree("[]|[[test.fixture1]]") self.setMockFixture("test.fixture1", MockFixture1) self.fixture.doTables(htmlTree) assert MockFixture1.collector["inDoRow"] is False def testDoCellsInvokedForTwoRowTable(self): htmlTree = self.createParseTree("[]|[[test.fixture1][Hi There!]]") self.setMockFixture("test.fixture1", MockFixture1) self.fixture.doTables(htmlTree) resultHTML = str(htmlTree) assert resultHTML.find(Fixture.greenColor) > -1 def testInterpretTablesOverridesStandardLoop(self): htmlTree = self.createParseTree( "[]|[[test.interpretTablesFixture]]" "[[Hi There!]]" "[[Nice Day, isn't it?]]") self.setMockFixture("test.interpretTablesFixture", MockDoFixture) self.fixture.doTables(htmlTree) assert htmlTree.at(0, 0, 0).tag.find(Fixture.redColor) > -1 assert htmlTree.at(1, 0, 0).tag.find(Fixture.redColor) > -1 assert htmlTree.at(2, 0, 0).tag.find(Fixture.redColor) > -1 tree1 = ("[]|[[test.interpretTablesFixture]]" "[[GreenFixture]]" "[[GreenFixture]]") def testExceptionInInterpretTablesOverride(self): htmlTree = self.createParseTree(self.tree1) self.setMockFixture("interpretTablesFixture", MockDoExceptionFixture) self.setMockFixture("GreenFixture", MockFixture1) self.fixture.doTables(htmlTree) assert htmlTree.at(0, 0, 0).tag.find(Fixture.yellowColor) > -1 assert htmlTree.at(1, 0, 0).tag.find("bgcolor") == -1 assert htmlTree.at(2, 0, 0).tag.find("bgcolor") == -1 def testExceptionInInterpretTablesDoTableOverride(self): htmlTree = self.createParseTree(self.tree1) self.setMockFixture("interpretTablesFixture", MockDoExceptionFixture2) self.setMockFixture("GreenFixture", MockFixture1) self.fixture.doTables(htmlTree) assert htmlTree.at(0, 0, 0).tag.find(Fixture.yellowColor) > -1 assert htmlTree.at(1, 0, 0).tag.find("bgcolor") == -1 assert htmlTree.at(2, 0, 0).tag.find("bgcolor") == -1 def testExceptionInInterpretTablesNoOverrideDoTable(self): htmlTree = self.createParseTree(self.tree1) self.setMockFixture("interpretTablesFixture", MockDoTableExceptionFixture) self.setMockFixture("GreenFixture", MockFixture1) self.fixture.doTables(htmlTree) assert htmlTree.at(0, 0, 0).tag.find(Fixture.yellowColor) > -1 assert htmlTree.at(1, 0, 0).tag.find("bgcolor") == -1 assert htmlTree.at(2, 0, 0).tag.find("bgcolor") == -1
class ExampleTests(ColumnFixture): fileName = "" wiki = 0 _typeDict = {"fileName": "String", "file.renameTo": "fileName", "wiki": "Boolean"} def __init__(self): ColumnFixture.__init__(self) self.fileName = "" self.wiki = 0 self.input = "" self.tables = None self.fixture = None self.runCounts = Counts() self.footnote = None self.fileCell = None def run(self): newFileName = "fat/Documents/" + self.fileName inFile = open(newFileName, 'r') theTest = inFile.read() inFile.close() self.fixture = Fixture() self.footnote = None if self.wiki: self.tables = Parse(text=theTest, tags=("wiki", "table", "tr", "td")) else: self.tables = Parse(text=theTest, tags=("table", "tr", "td")) self.fixture.doTables(self.tables) self.runCounts.tally(self.fixture.counts) self.summary["counts run"] = self.runCounts _typeDict["right_"] = "Int" _typeDict["right.renameTo"] = "right_" def right_(self): self.run() return self.fixture.counts.right _typeDict["wrong_"] = "Int" _typeDict["wrong.renameTo"] = "wrong_" def wrong_(self): return self.fixture.counts.wrong _typeDict["ignores"] = "Int" def ignores(self): return self.fixture.counts.ignores _typeDict["exceptions"] = "Int" def exceptions(self): return self.fixture.counts.exceptions def doRow(self, row): self.fileCell = row.leaf() ColumnFixture.doRow(self, row) def wrong(self, cell, actual = None, escape=True): # super(ExampleTests, self) ColumnFixture.wrong(self, cell, actual = actual, escape = escape) if self.footnote == None: self.footnote = self.tables.footnote() self.fileCell.addToBody(self.footnote)