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

Chad Versace chad at chad-versace.us
Tue Jul 26 15:51:52 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.

CC: Ian Romanick <ian.d.romanick at intel.com>
Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 framework/core.py |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 3c959e7..c025311 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -278,21 +278,27 @@ class TestrunResult:
 		self.lspci = None
 		self.tests = {}
 
-	def write(self, file):
-		# Serialize only the keys in serialized_keys.
-		keys = set(self.__dict__.keys()).intersection(self.serialized_keys)
-		raw_dict = dict([(k, self.__dict__[k]) for k in keys])
-		json.dump(raw_dict, file, indent=JSONWriter.INDENT)
+	def __checkFileIsNotInOldFormat(self, file):
+		'''
+		If file contains the old, custom format, then raise
+		``ResultFileInOldFormatError``.
 
-	def parseFile(self, file):
-		# If file contains the old, custom format, then raise
-		# an informative error.
+		: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)
+		raw_dict = dict([(k, self.__dict__[k]) for k in keys])
+		json.dump(raw_dict, file, indent=JSONWriter.INDENT)
+
+	def parseFile(self, file):
+		self.__checkFileIsNotInOldFormat(file)
 		raw_dict = json.load(file)
 
 		# Check that only expected keys were unserialized.
-- 
1.7.6



More information about the Piglit mailing list