[Piglit] [PATCH 3/4] core: Add method TestrunResult.__checkFileIsNotInOldFormat

Chad Versace chad at chad-versace.us
Tue Jul 19 12:36:42 PDT 2011


Factor out from TestrunResult.parseFile the code that checks if the file
is in the old format. Place that code into a separate method,
__checkFileIsNotInOldFormat.

Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 framework/core.py |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index ca8fcfc..afc5a28 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -278,6 +278,19 @@ class TestrunResult:
 		self.lspci = None
 		self.tests = {}
 
+	def __checkFileIsNotInOldFormat(self, file):
+		'''
+		If file contains the old, custom format, then raise
+		``ResultFileInOldFormatError``.
+
+		:return: None
+		'''
+		saved_position = file.tell()
+		first_line = file.readline()
+		if first_line.startswith('name:'):
+			raise ResultFileInOldFormatError(file.name)
+		file.seek(saved_position)
+
 	def write(self, file):
 		# Serialize only the keys in serialized_keys.
 		keys = set(self.__dict__.keys()).intersection(self.serialized_keys)
@@ -285,13 +298,7 @@ class TestrunResult:
 		json.dump(raw_dict, file, indent=JSONWriter.INDENT)
 
 	def parseFile(self, file):
-		# If file contains the old, custom format, then raise
-		# an informative error.
-		saved_position = file.tell()
-		first_line = file.readline()
-		if first_line.startswith('name:'):
-			raise ResultFileInOldFormatError(file.name)
-		file.seek(saved_position)
+		self.__checkFileIsNotInOldFormat(file)
 
 		raw_dict = json.load(file)
 
-- 
1.7.6



More information about the Piglit mailing list