def test_extract_tracebacks(): """ Test extract_tracebacks. """ # first off, extract_tracebacks should be able to handle \r\n... tb_txt = read_file_rn('simple_tb.txt') ok_(tb_txt) extracted_tb = extract_tracebacks(tb_txt) ok_(extracted_tb) eq_strip_(extracted_tb, [read_file('simple_tb_extracted.txt')]) tb_txt = read_file_rn('simple_tb_2.txt') ok_(tb_txt) extracted_tb = extract_tracebacks(tb_txt) ok_(extracted_tb) eq_strip_(extracted_tb, [read_file('simple_tb_2_extracted.txt')]) tb_w_context_txt = read_file_rn('contextual_tb.txt') extracted_tb_w_context = extract_tracebacks(tb_w_context_txt) ok_(extracted_tb_w_context) eq_strip_(extracted_tb_w_context, [read_file('contextual_tb_extracted.txt')]) not_a_tb_txt = read_file_rn('not_a_tb.txt') eq_strip_([], extract_tracebacks(not_a_tb_txt)) # second of all, we should be able to handle multiples tbs per # txt. tb_txt = read_file('simple_tb.txt') tb_2_txt = read_file('simple_tb_2.txt') tb_w_context_txt = read_file('contextual_tb.txt') two_tb_txt = "%s\n\n%s\n\n%s\n\n%s" % (tb_txt, not_a_tb_txt, tb_w_context_txt, tb_2_txt) tbs = extract_tracebacks(two_tb_txt) eq_(3, len(tbs)) tbs = [tb.strip() for tb in tbs] ok_(read_file('simple_tb_extracted.txt').strip() in tbs) ok_(read_file('contextual_tb_extracted.txt').strip() in tbs) ok_(read_file('simple_tb_2_extracted.txt').strip() in tbs)
def _bugs_with_tbs(config, options): """ Return (bug, tbs) for only those bugs having tbs. """ bugs_with_tbs = [] with db.init(config['profile'], config['bugdbs'], options=options) as bugsdb: for bug in bugsdb.bugs(): tbs = extract_tracebacks(bug['text']) if tbs: bugs_with_tbs.append((bug, tbs)) return bugs_with_tbs
def whack(traceback_txt, config, options): """ Extract any traceback from traceback_txt and attempt to match it to a bug. """ _ensure_tracewhack_data_dir() tbs = extract_tracebacks(traceback_txt) if not tbs: err = "Could not extract a traceback" log.error(err) raise ValueError(err) bugs_with_tbs = _bugs_with_tbs(config, options) bug_and_scores = _score_bugs(tbs, bugs_with_tbs) print "Displaying best matches:" for (match_i, (bug, score)) in enumerate(bug_and_scores): if match_i >= options['num_results']: break print _fmt_bug(bug, score)