<div dir="ltr"><div style>NAK this. I just noticed the problem still exists with this patch</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 31, 2013 at 4:51 PM, Dylan Baker <span dir="ltr"><<a href="mailto:baker.dylan.c@gmail.com" target="_blank">baker.dylan.c@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The checking in TestrunResult to determine if a file was proper json or<br>
not is very fragile: it assumes that the last line of the file will be<br>
}. Sometimes this triggers and rebuilds a valid json file, dropping the<br>
last test and resulting in python overhead.<br>
<br>
This patch replaces that check with a try/except block. This block<br>
attempts to load the json file with json.loads, and on failure attempts<br>
to fix the json.<br>
<br>
Signed-off-by: Dylan Baker <<a href="mailto:baker.dylan.c@gmail.com">baker.dylan.c@gmail.com</a>><br>
---<br>
framework/core.py | 42 ++++++++++++++++++++++++------------------<br>
1 file changed, 24 insertions(+), 18 deletions(-)<br>
<br>
diff --git a/framework/core.py b/framework/core.py<br>
index 14a8161..2c06d5e 100644<br>
--- a/framework/core.py<br>
+++ b/framework/core.py<br>
@@ -301,11 +301,6 @@ class TestrunResult:<br>
lines = file.readlines()<br>
file.seek(saved_position)<br>
<br>
- if lines[-1] == '}':<br>
- # JSON object was closed properly. No repair is<br>
- # necessary.<br>
- return file<br>
-<br>
# JSON object was not closed properly.<br>
#<br>
# To repair the file, we execute these steps:<br>
@@ -353,19 +348,30 @@ class TestrunResult:<br>
json.dump(raw_dict, file, indent=JSONWriter.INDENT)<br>
<br>
def parseFile(self, file):<br>
- file = self.__repairFile(file)<br>
- raw_dict = json.load(file)<br>
-<br>
- # Check that only expected keys were unserialized.<br>
- for key in raw_dict:<br>
- if key not in self.serialized_keys:<br>
- raise Exception('unexpected key in results file: ' + str(key))<br>
-<br>
- self.__dict__.update(raw_dict)<br>
-<br>
- # Replace each raw dict in self.tests with a TestResult.<br>
- for (path, result) in self.tests.items():<br>
- self.tests[path] = TestResult(result)<br>
+ # Attempt to open the json file raw, if it fails then attempt to repair<br>
+ # it.<br>
+ try:<br>
+ results = json.loads(file)<br>
+ <a href="http://self.name" target="_blank">self.name</a> = <a href="http://results.name" target="_blank">results.name</a><br>
+ self.glxinfo = results.glxinfo<br>
+ self.lspci = results.lspci<br>
+ self.time_elapsed = results.time_elapsed<br>
+ self.tests = results.tests<br>
+ except TypeError:<br>
+ file = self.__repairFile(file)<br>
+ raw_dict = json.load(file)<br>
+<br>
+ # Check that only expected keys were unserialized.<br>
+ for key in raw_dict:<br>
+ if key not in self.serialized_keys:<br>
+ raise Exception('unexpected key in results file: ',<br>
+ str(key))<br>
+<br>
+ self.__dict__.update(raw_dict)<br>
+<br>
+ # Replace each raw dict in self.tests with a TestResult.<br>
+ for (path, result) in self.tests.items():<br>
+ self.tests[path] = TestResult(result)<br>
<br>
#############################################################################<br>
##### Generic Test classes<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.4<br>
<br>
</font></span></blockquote></div><br></div>