def test_tbgrep(): extractor = TracebackGrep() for variation in variations: found = False for line in variation.split('\n'): tb = extractor.process(line + '\n') if tb: found = True assert tb == traceback, repr(tb) assert found, "Couldn't extract traceback from: " + repr(variation)
def tbgrep(self, irc, msg, args, optlist, optlog): """[--options] <logfile> Display tracebacks from a specific logfile. """ # first, lower optlog to match. optlog = optlog.lower() # next handle optlist. lines, showlast = 10, False # defaults. if optlist: for (k, v) in optlist: if k == 'last': showlast = True if k == 'n': if v > 50: irc.reply("Sorry, I won't display more than 50 lines.") elif v < 1: irc.reply("Sorry, I need a positive integer here.") else: # under 50 so lets go. lines = v # next, grab our list of logs. ll = self._listlogs() if not ll: irc.reply("ERROR: No logs found to display.") return else: # found logs. verify it works. if optlog not in ll: # we didn't find. display a list. irc.reply( "ERROR: '{0}' is not a valid log. These are: {1}".format( optlog, " | ".join([i for i in ll.keys()]))) return # we're here if things worked. tbo = [] # now lets use TracebackGrep. extractor = TracebackGrep() for line in file(ll[optlog]): tb = extractor.process(line) if tb: # if we find any, add. tbo.append(tb) #irc.reply(type(tb)) # now lets output if we find anything. if len(tbo) == 0: irc.reply("I did not find any Tracebacks in {0}'s logfile.".format( optlog)) else: # found some. how to handle. if showlast: irc.reply("{0}".format(tbo[-1])) else: for each in tbo[-(lines):]: irc.reply(each)
def tbgrep(self, irc, msg, args, optlist, optlog): """[--options] <logfile> Display tracebacks from a specific logfile. """ # first, lower optlog to match. optlog = optlog.lower() # next handle optlist. lines, showlast = 10, False # defaults. if optlist: for (k, v) in optlist: if k == 'last': showlast = True if k == 'n': if v > 50: irc.reply("Sorry, I won't display more than 50 lines.") elif v < 1: irc.reply("Sorry, I need a positive integer here.") else: # under 50 so lets go. lines = v # next, grab our list of logs. ll = self._listlogs() if not ll: irc.reply("ERROR: No logs found to display.") return else: # found logs. verify it works. if optlog not in ll: # we didn't find. display a list. irc.reply("ERROR: '{0}' is not a valid log. These are: {1}".format(optlog, " | ".join([i for i in ll.keys()]))) return # we're here if things worked. tbo = [] # now lets use TracebackGrep. extractor = TracebackGrep() for line in file(ll[optlog]): tb = extractor.process(line) if tb: # if we find any, add. tbo.append(tb) #irc.reply(type(tb)) # now lets output if we find anything. if len(tbo) == 0: irc.reply("I did not find any Tracebacks in {0}'s logfile.".format(optlog)) else: # found some. how to handle. if showlast: irc.reply("{0}".format(tbo[-1])) else: for each in tbo[-(lines):]: irc.reply(each)
def test_tbgrep_stats(): extractor = TracebackGrep(stats=True) for variation in variations: for line in variation.split('\n'): extractor.process(line + '\n') stats = extractor.get_stats() assert len(stats) == 1, stats assert stats[0][1] == 3, stats[0][1] sys.stdout = StringIO() extractor.print_stats() assert '1 unique traceback extracted' in sys.stdout.getvalue() sys.stdout = sys.__stdout__