git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] A simple python script to parse the results from the testcases

From
Sverre Rabbelier <srabbelier@gmail.com>
Date
May 12, 2008, 09:33 UTC
Message-ID
<1210584832-16402-3-git-send-email-srabbelier@gmail.com>
In-Reply-To
<1210584832-16402-1-git-send-email-srabbelier@gmail.com>

This is a simple script that aggregates key:value pairs in a file. I am sure this can be done better with a 'grep | sed | awk' combination, my skills with awk / your program of choice is not as profound. This script serves more as a demonstration on how to use the testcase output.

Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
---
 t/key_value_parser.py |   78 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)
 create mode 100755 t/key_value_parser.py
diff --git a/t/key_value_parser.py b/t/key_value_parser.py
new file mode 100755
index 0000000..e172df1
--- /dev/null
+++ b/t/key_value_parser.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+"""Module for parsing files with 'key value' pairs.
+
+Usage summary: key_value_parser.py "path/to/file"
+"""
+
+def parseFile(path):
+	"""Parses a file containing pair value couples.
+	
+	The values are expected to be integers.
+	If more than one value for a pair is found, these values are aggregated.
+	The size of the longest key is stored in '__maxsize'.
+	A dictionairy with only '__maxsize:0' is returned if an error occured.
+	"""
+
+	dict = {"__maxsize" : 0}
+
+	try:
+		file = open(path)
+		for line in file:
+			if line == '\n':
+				continue
+
+			pos = line.index(' ')
+			key = line[:pos]
+			
+			# Skip the space and the trailing newline
+			value = line[pos+1:-1] 
+			intvalue = int(value)
+
+			if key in dict:
+				dict[key] = intvalue + dict[key]
+			else:
+				dict[key] = intvalue
+
+			if len(key) > dict["__maxsize"]:
+				dict["__maxsize"] = len(key)
+
+	except IOError:
+		print("Cannot open or read from file " + path)
+	except ValueError:
+		print("Malformed line in file ")
+
+	return dict
+
+def main(argv):
+	""" Invokes parseFile on the path specified as argument.
+	
+	If no argument is specified, a default of 
+	'/tmp/git-test-results' is used.
+
+	The resulting dictionary is printed, ignoring keys starting with '__'.
+	All output is left justified to the size of the largest key.
+	"""
+	path = "/tmp/git-test-results"
+	
+	# If a path was specified as argument, use that
+	if len(argv) > 1:
+		path = argv[1]
+
+	# Parse the file
+	dict = parseFile(path)
+
+	# Retreive the max size and add one space for readability
+	maxsize = dict["__maxsize"] + 1
+
+	# Print the result
+	for key,value in dict.iteritems():
+		# Don't print meta-data
+		if key.startswith("__"):
+			continue
+
+		print(key.ljust(maxsize) + str(value))
+
+if __name__ == '__main__':
+	import sys
+	main(sys.argv)
-- 
1.5.5.1.178.g1f811
Previous: Vegard NossumNext: Jakub Narebski
Message 4 of 21 in “Aggregate testcase results”
  1. 0/3 Aggregate testcase resultsSverre Rabbelier, May 12, 2008
  2. 1/3 Modified test-lib.sh to output stats to /tmp/git-test-resultsSverre Rabbelier, May 12, 2008
  3. Vegard NossumMay 12, 2008
  4. 2/3 A simple python script to parse the results from the testcasesSverre Rabbelier, May 12, 2008
  5. Jakub NarebskiMay 12, 2008
  6. Sverre RabbelierMay 12, 2008
  7. Johannes SchindelinMay 12, 2008
  8. Sverre RabbelierMay 12, 2008
  9. Johannes SchindelinMay 12, 2008
  10. A simple script to parse the results from the testcasesMiklos Vajna, Jun 8, 2008
  11. Sverre RabbelierJun 8, 2008
  12. Miklos VajnaJun 8, 2008
  13. Sverre RabbelierJun 8, 2008
  14. Miklos VajnaJun 8, 2008
  15. Sverre RabbelierJun 8, 2008
  16. Johannes SchindelinJun 8, 2008
  17. Sverre RabbelierJun 8, 2008
  18. Mikael MagnussonJun 8, 2008
  19. Sverre RabbelierJun 8, 2008
  20. 3/3 Hook up the result aggregation in the test makefile.Sverre Rabbelier, May 12, 2008
  21. Vegard NossumMay 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.