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"))
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 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 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)
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 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 _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): 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 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(self.OriginalHTML, ["td"]) testbed = Fixture() if self.Annotation == "right": testbed.right(parse) if self.Annotation == "wrong": testbed.wrong(parse, self.Text) if self.Annotation == "error": testbed.error(parse, self.Text) if self.Annotation == "info": testbed.info(parse, self.Text) if self.Annotation == "ignore": testbed.ignore(parse) return self.GenerateOutput(parse)
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 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 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 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")
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 test1(self): table = Parse("<table><tr><td>fit.ff.FixtureUnderTest</td>" "<td>r</td>" "</tr></table>\n") Fixture().doTables(table) ParseUtility.printParse(table, "test")
def _loadFixture(self): fixture = Fixture() fixture.loadFixture(self.FixtureName)
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
class HtmlRunner(): ''' run all test cases of html tables support stress test ''' input = None tables = None fixture = Fixture() output = None outfile = None expandColumnsTag = None #expand html table column, like 'colspan=23' outreportname = None def __init__(self, argv): # output-file argv not exists,deafault name :Year-m-d-h-m-sreport.html if len(argv) < 2: sys.stderr.write("usage: python input-file output-file\n") sys.exit(-1) # output-file argv not exists,deafault name :Year-m-d-h-m-sreport.html if len(argv) == 2: self.outreportname = 'reports\\' + time.strftime( '%Y-%m-%d-%H-%M-%S') + 'report.html' argv.append(self.outreportname) elif (len(argv) > 2): self.outreportname = argv[2] 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): self.setUp() self.runTest() self.tearDown() print 'the test report name is: %s, please review' % ( self.outreportname) try: #if have not iteration, open report by automatic if GlobalSetting.ITERATION == 0 and GlobalSetting.RUNTIME == 0: webbrowser.open_new(self.outreportname) # open test report #pass except: pass self.exit() print 'call over' def runTest(self): Log.debug('start: HtmlRunner.runTest') tags = ("html", "table", "tr", "td") print 'now start to test......' starttime = datetime.datetime.now() runTime = 0 try: Log.info('iteration count: ' + str(GlobalSetting.ITERATION)) iterationCount = GlobalSetting.ITERATION if type(iterationCount) != types.IntType: iterationCount = 0 count = 0 while True: self.tables = Parse(self.input, tags) # look for html tag enclosing tables self.fixture.doTables(self.tables.parts, self.expandColumnsTag) self.output.write(str(self.tables)) self.output.flush() self.output.close() endtime = datetime.datetime.now() runTime = (endtime - starttime).seconds #=============================================================================== # if runTime < 10: # print 'run time is less than 10 second, maybe run STAT occur error,system exit' #=============================================================================== print 'run time(seconds) is: ' + str(runTime) try: if GlobalSetting.RUNTIME > 0: if runTime > GlobalSetting.RUNTIME: break elif iterationCount < 1: break except BaseException, e: Log.exception(e) break iterationCount -= 1 if GlobalSetting.NEEDREPORTS: temp = self.outreportname.split('.')[-2] # get file path pathTuple = temp.split('\\') #split file name, path count += 1 if os.path.exists('reports\\') is not True: os.mkdir('reports\\') report = 'reports\\' + pathTuple[-1] + '(' + str( count) + ')' + '.html' self.output = open(report, 'w') except (KeyboardInterrupt, SystemExit), e: print 'user Interrupt test' Log.exception(e) os._exit(0) except BaseException, e: self.exception(e) Log.exception(e) os._exit(0)
def shouldBeFitnesse(self): fix = Fixture() assert fix.isFitNesse()
def shouldAccessRunSymbols(self): FG.RunLevelSymbols["aSymbol"] = "Clang!" fix = Fixture() assert fix.getSymbol("aSymbol") == "Clang!"
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 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 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()