def shouldRecognizeFitFailureException(self): fix = Fixture() cell = Parse(tag="td", body="Oops.") fix.exception(cell, FitFailureException("What the heck?")) assert cell.body.find("What the heck?") > -1 assert cell.tagIsError() assert fix.counts.exceptions == 1
def shouldBeAbleToColorExceptionAsWrong(self): fix = Fixture() cell = Parse(tag="td", body="Oops.") fix.exception(cell, "What the heck?", color="wrong") assert cell.body.find("What the heck?") > -1 assert cell.tagIsWrong() assert fix.counts.wrong == 1
def shouldHandleStringAsExceptionParameter(self): fix = Fixture() cell = Parse(tag="td", body="Oops.") fix.exception(cell, "What the heck?") assert cell.body.find("What the heck?") > -1 assert cell.tagIsError() assert fix.counts.exceptions == 1
def shouldAnnotateOnErrorCall(self): fix = Fixture() cell = Parse(tag="td", body="Oops.") fix.error(cell, "Not good!") assert cell.body.find("Not good!") > -1 assert cell.tagIsError() assert fix.counts.exceptions == 1
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 _newFixture(self): fixture = Fixture() fixture.listener = self.fixtureListener fixture.listener.runner = self self._loadRenameFile(fixture, "FixtureRenames.txt") self._loadRenameFile(fixture, self._renameFileName) self.fixture = fixture return fixture
def __init__(self): Fixture.__init__(self) self.__url = "" self.__headers = None self.__params = None self.__data = None self.status = "" self.result = "" self.actual = ""
def __init__(self): Fixture.__init__(self) self._url = "" self._header = {} self._params = None self._data = None self._expect_result = None self._diff_by = "" self._diff_result = "" self._actual_result = ""
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 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
def testEscape(self): junk = "!@#$%^*()_-+={|[]\\:\";',./?`" self.assertEquals(junk, Fixture().escape(junk)) self.assertEquals("", Fixture().escape("")) self.assertEquals("<", Fixture().escape("<")) self.assertEquals("<<", Fixture().escape("<<")) self.assertEquals("x<", Fixture().escape("x<")) self.assertEquals("&", Fixture().escape("&")) self.assertEquals("<&<", Fixture().escape("<&<")) self.assertEquals("&<&", Fixture().escape("&<&")) self.assertEquals("a < b && c < d", Fixture().escape("a < b && c < d"))
class FileRunner: input = None tables = None fixture = Fixture() output = None outfile = None def __init__(self, argv): if len(argv) != 3: sys.stderr.write( "usage: python FileRunner.py input-file output-file\n") sys.exit(-1) infile = open(argv[1], 'r') modtime = time.ctime(os.fstat(infile.fileno())[stat.ST_MTIME]) self.outfile = open(argv[2], 'w') self.fixture.summary["input file"] = os.path.abspath(argv[1]) self.fixture.summary["input update"] = modtime self.fixture.summary["output file"] = os.path.abspath(argv[2]) self.input = infile.read() infile.close() self.output = self.outfile def __call__(self): try: self.tables = Parse(self.input) self.fixture.doTables(self.tables) except Exception, e: self.exception(e) self.output.write(str(self.tables)) self.exit() sys.exit(self.fixture.counts.wrong + self.fixture.counts.exceptions)
def doRows(self, rows): #this.table = new Parse ("table", null, copy(rows), null); #// evaluate the rest of the table like a runner #(new Fixture()).doTables(this.table); table = Parse(tag="table", body="", parts=self.copy(rows), more=None) self.setSymbol("Table", table) Fixture().doTables(table)
def __init__(self): self._parseTree = None self.fixture = Fixture() self.command = "FileRunner" FG.Environment = "Batch" self.inDir = "" self.inFile = "" self.outDir = ""
def doFiles(self, row, files): for fileName in files: cells = self.td(fileName, self.td("", None)) row.more = self.tr(cells, row.more) row = row.more fixture = Fixture() self.run(fileName, fixture, cells) self.summarize(fixture, fileName)
def doTable(self, table): actual = table.parts.more.parts.parts expectedCell = table.parts.more.more.parts expected = expectedCell.parts Fixture().doTables(actual) if self.reportsEqual(actual, expected): self.right(expectedCell) else: self.wrong(expectedCell) ParseUtility.printParse(actual, "actual")
def check(self, eList, cList): # called either when both sizes are one, or we've run out of columns # to compare. The first set of tests stops the recursion. if not eList: self.surplus.extend(cList) return if not cList: self.missing.extend(eList) return # There is at least one in each list. Process the first one, # and then recurse on the shorter lists row = eList.pop(0) cell = row.parts obj = cList.pop(0) for a in self.columnBindings: a.target = obj if a != None: a.target = obj Fixture.check(self, cell, a) cell = cell.more self.check(eList, cList)
def doFiles(self): row = self.startingRow for filename in self.filenames: path = os.path.join(self.directory, filename) cells = self.td(self.makeLinkTo(filename), self.td("", None)) row.more = self.tr(cells, row.more) row = row.more # row = row.more = self.tr(cells, row.more) fixture = Fixture() # fixture = ErrorHandlingFixture() # embedded class self.run(path, fixture, cells) self.summarize(fixture)
def check (self, eList, cList): # called either when both sizes are one, or we've run out of columns # to compare. The first set of tests stops the recursion. if not eList: self.surplus.extend(cList) return if not cList: self.missing.extend(eList) return # There is at least one in each list. Process the first one, # and then recurse on the shorter lists row = eList.pop(0) cell = row.parts obj = cList.pop(0) for a in self.columnBindings: a.target = obj if a != None: a.target = obj Fixture.check(self, cell, a) cell = cell.more self.check(eList, cList)
def testFixtureArguments(self): prefix = "<table><tr><td>fit.Fixture</td>" suffix = "</tr></table>" f = Fixture() table = Parse(prefix + "<td>1</td>" + suffix) f.getArgsForTable(table) args = f.getArgs() self.assertEquals(1, len(args)) self.assertEquals("1", args[0]) table = Parse(prefix + "" + suffix) f.getArgsForTable(table) args = f.getArgs() self.assertEquals(0, len(args)) table = Parse(prefix + "<td>1</td><td>2</td>" + suffix) f.getArgsForTable(table) args = f.getArgs() self.assertEquals(2, len(args)) self.assertEquals("1", args[0]) self.assertEquals("2", args[1])
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)
def Output(self): parse = Parse(tag="td", body=self.OriginalCell) hack = Fixture() if self.Type == "none": pass elif self.Type == "right": hack.right(parse) elif self.Type == "wrong": hack.wrong(parse, self.Text) elif self.Type == "error": return "not implemented" elif self.Type == "ignore": hack.ignore(parse) elif self.Type == "unchecked": return "not implemented" else: return "unknown type: " + self.Type return self._GenerateOutput(parse)
def exception(self,e): tables = Parse(tag="body", body="Unable to parse input. Input ignored.", parts=None, more=None) Fixture.exception(self.fixture, tables, e)
def __init__(self, i): __pychecker__ = 'no-override' Fixture.__init__(self, i)
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
def doRows(self, rows): Fixture.doRows(self, rows.more)
def shouldCreateExpectedAndActualLabelInGreen(self): fix = Fixture() cell = Parse(tag="td", body="Oops.") cell.addToBody(fix.greenlabel("That's all right.")) assert cell.body.find("That's all right") > -1 assert cell.infoIsRight()
def shouldCreateExpectedAndActualLabelInRed(self): fix = Fixture() cell = Parse(tag="td", body="Oops.") cell.addToBody(fix.label("It's dead, Jim.")) assert cell.body.find("It's dead, Jim") > -1 assert cell.infoIsWrong()
def shouldAccessRunSymbols(self): FG.RunLevelSymbols["aSymbol"] = "Clang!" fix = Fixture() assert fix.getSymbol("aSymbol") == "Clang!"
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)
def doTable(self, table): print "in doTable. table: '%s'" % table Fixture.doTable(self, table)
def shouldBeFitnesse(self): fix = Fixture() assert fix.isFitNesse()
def doRow(self, row): self.row = row Fixture.doRow(self, row)
def CellOutput(self): cell = Parse(tag="td") cell.leader = "" cell.body = Fixture.escape(self, self._unescape(self.Text)) return self._GenerateOutput(cell)
def _loadFixture(self): fixture = Fixture() fixture.loadFixture(self.FixtureName)
def __init__(self, sut=None): Fixture.__init__(self) # first superclass with an init method. self.setSystemUnderTest(sut) self.map = {}
def shouldAddTextOnInfo(self): fix = Fixture() cell = Parse(tag="td", body="It's cold out there.") fix.info(cell, "Well, dress warmly.") assert cell.body.find("Well, dress warmly.") > -1 assert cell.infoIsIgnored()
def shouldGetTheInfoText(self): fix = Fixture() cell = Parse(tag="td", body="It's cold out there.") cell.addToBody(fix.info("Well, dress warmly.")) assert cell.body.find("Well, dress warmly.") > -1 assert cell.infoIsIgnored()
def check_(self): text = self.camel(self.cells.more.text()) adapter = adapterOnMethod(self.actor, text) Fixture.check(self, self.cells.more.more, adapter)
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 doRow(self, row): Fixture.doRow(self, row) self.actualRow = self.actualRow.more
def test1(self): table = Parse("<table><tr><td>fit.ff.FixtureUnderTest</td>" "<td>r</td>" "</tr></table>\n") Fixture().doTables(table) ParseUtility.printParse(table, "test")
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)