def bind(self, heads, expandColumnsTag=None): self.columnBindings = [None] * heads.size() i = 0 while heads: name = heads.text() # strip ' ','\n' name = name.replace(' ', '') name = name.replace('\n', '') sufix = "()" try: if name[-len(sufix):] == sufix: self.columnBindings[i] = \ self.bindMethod(name[:-len(sufix)]) if expandColumnsTag is not None: setattr( self, 'rowspan', 2 ) # added in 2009/08/21, the first row means show test result, second test data style = heads.getStyle() if style is None: style = '' try: heads.addToBody(self.getExpandheads(style)) except AttributeError, e: Log.info('please implement getExpandheads()!') Log.exception(e) else: # name is field self.columnBindings[i] = self.bindField(name)
def runTest(self): Log.debug('start: DcgFixture.runTest') 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 while True: path = 'reports\\' if not os.path.exists(path): os.mkdir(path) dcg = TextFixture() dcg.doTextTest(self.textfilename, path + self.outreportname) endtime = datetime.datetime.now() runTime = (endtime - starttime).seconds 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 except (KeyboardInterrupt, SystemExit), e: print 'user Interrupt test' Log.exception(e) os._exit(0)
def bind (self, heads, expandColumnsTag = None): self.columnBindings = [None] * heads.size() i = 0 while heads: name = heads.text() # strip ' ','\n' name = name.replace(' ', '') name = name.replace('\n','') sufix = "()" try: if name[-len(sufix):] == sufix: self.columnBindings[i] = \ self.bindMethod(name[:-len(sufix)]) if expandColumnsTag is not None: setattr(self, 'rowspan', 2) # added in 2009/08/21, the first row means show test result, second test data style = heads.getStyle() if style is None: style = '' try: heads.addToBody(self.getExpandheads(style)) except AttributeError, e: Log.info('please implement getExpandheads()!') Log.exception(e) else: # name is field self.columnBindings[i] = self.bindField(name)
def __init__(self, argv, multipleInstanceFlag = False): # output-file argv not exists,deafault name :Year-m-d-h-m-sreport.html self.expandColumnsTag = 'colspan=21' if len(argv) < 2: sys.stderr.write("usage: python input-file output-file\n") sys.exit(-1) 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] infilename = self.convertExcelToHtml(argv[1], multipleInstanceFlag) Log.info('html file: ' + infilename) infile = open(infilename,'r') modtime = time.ctime(os.fstat(infile.fileno())[stat.ST_MTIME]) try: self.outfile = open(argv[2],'w') except IOError: os.mkdir('reports\\') 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 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)