Skip to content

Instantly share code, notes, and snippets.

@galderz
Created August 20, 2012 08:29
Show Gist options
  • Save galderz/3402229 to your computer and use it in GitHub Desktop.
Save galderz/3402229 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import itertools
# A script that greps log file for failed tests and
# creates individual files for individual failed tests.
#
# It needs a lot of polishing but for the time being works :)
# TODO: Make get lines return a single list, and make it include start and end lines
def get_lines(file, start_mark, end_mark):
print "Get lines from file %s, with start mark '%s' and end mark '%s'" % (file, start_mark, end_mark)
for line in file:
if start_mark in line:
yield list(itertools.takewhile(
lambda s: end_mark not in s, file))
def main():
failed_markers = []
# 1. Locate all failed or skipped tests
for line in open("/Users/g/Varia/mvn/infinispan.log"):
# TODO: Use regex !!
if "Test failed" in line or "Test skipped" in line:
failed_markers.append(line)
# 2. Process each failed or skipped test
counter = 0
for failed_marker in failed_markers:
failed_test = failed_marker.split(" ")[9]
print "Processing test %s" % failed_test
test_log_lines = get_lines(open("/Users/g/Varia/mvn/infinispan.log"),
"Starting test %s" % failed_test, failed_marker)
# Retrieve test name and dump log lines into file
test_name = failed_test.split("(")[0]
output = open("/Users/g/Varia/mvn/%s-%d.log" % (test_name, counter), 'wb')
for group in test_log_lines:
for line in group:
output.write("%s" % line)
counter += 1
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment