<div dir="ltr">Actually, this patch breaks a bunch of stuff. I'll rework this and send it out later. The rest of the patches are fine.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 16, 2013 at 9:09 AM, 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">This patch removes the Result class from Summary, and the<br>
loadTestResults function from core. It does this by integrating the<br>
functionality into TestrunResult.<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 | 62 ++++++++++++++++++++++++-------------------------<br>
framework/summary.py | 34 +++------------------------<br>
piglit-summary-junit.py | 2 +-<br>
3 files changed, 34 insertions(+), 64 deletions(-)<br>
<br>
diff --git a/framework/core.py b/framework/core.py<br>
index 680f3ab..2714bbf 100644<br>
--- a/framework/core.py<br>
+++ b/framework/core.py<br>
@@ -261,7 +261,7 @@ class GroupResult(dict):<br>
<br>
<br>
class TestrunResult:<br>
- def __init__(self):<br>
+ def __init__(self, file):<br>
self.serialized_keys = ['options',<br>
'name',<br>
'tests',<br>
@@ -275,6 +275,32 @@ class TestrunResult:<br>
self.time_elapsed = None<br>
self.tests = {}<br>
<br>
+ self._load(file)<br>
+ self._parseFile()<br>
+<br>
+ def _load(self, result):<br>
+ """<br>
+ Private: Load a result file, and store that file object as an<br>
+ attribute.<br>
+ """<br>
+ # First assume that result is a main.zip file, if that fails assume<br>
+ # that it is a main file. If that fails, try the same file order, but<br>
+ # looking in a directory<br>
+ try:<br>
+ try:<br>
+ zip = zipfile.ZipFile(result, 'r')<br>
+ self.file = zip.open('main', 'r')<br>
+ except zipfile.BadZipfile:<br>
+ with open(result, 'r') as file:<br>
+ self.file = file<br>
+ except IOError:<br>
+ try:<br>
+ zip = zipfile.ZipFile(os.path.join(result, 'main.zip'), 'r')<br>
+ self.file = zip.open('main', 'r')<br>
+ except zipfile.BadZipfile:<br>
+ with open(os.path.join(result, 'main'), 'r') as file:<br>
+ self.file = file<br>
+<br>
def __repairFile(self, file):<br>
'''<br>
Reapair JSON file if necessary<br>
@@ -343,13 +369,13 @@ class TestrunResult:<br>
raw_dict = dict([(k, self.__dict__[k]) for k in keys])<br>
json.dump(raw_dict, file, indent=JSONWriter.INDENT)<br>
<br>
- def parseFile(self, file):<br>
+ def _parseFile(self):<br>
# Attempt to open the json file normally, if it fails then attempt to<br>
# repair it.<br>
try:<br>
- raw_dict = json.load(file)<br>
+ raw_dict = json.load(self.file)<br>
except ValueError:<br>
- raw_dict = json.load(self.__repairFile(file))<br>
+ raw_dict = json.load(self.__repairFile(self.file))<br>
<br>
# Check that only expected keys were unserialized.<br>
for key in raw_dict:<br>
@@ -598,34 +624,6 @@ def loadTestProfile(filename):<br>
return ns['profile']<br>
<br>
<br>
-def loadTestResults(relativepath):<br>
- """<br>
- Takes a result file as an argument, opens it, and creates a TestrunResult<br>
- object out of it, which it returns<br>
- """<br>
- path = os.path.realpath(relativepath)<br>
- testrun = TestrunResult()<br>
-<br>
- try:<br>
- try:<br>
- zip = zipfile.ZipFile(os.path.join(path, 'main.zip'), 'r')<br>
- file = zip.open('main', 'r')<br>
- except zipfile.BadZipfile:<br>
- with open(os.path.join(path, 'main')) as f:<br>
- file = f<br>
- except IOError:<br>
- try:<br>
- zip = zipfile.ZipFile(path, 'r')<br>
- file = zip.open('main', 'r')<br>
- except zipfile.BadZipfile:<br>
- with open(path) as f:<br>
- file = f<br>
-<br>
- testrun.parseFile(file)<br>
- assert(<a href="http://testrun.name" target="_blank">testrun.name</a>)<br>
- return testrun<br>
-<br>
-<br>
# Error messages to be ignored<br>
Test.ignoreErrors = map(re.compile,<br>
["couldn't open libtxc_dxtn.so",<br>
diff --git a/framework/summary.py b/framework/summary.py<br>
index 49b53b9..8e4871a 100644<br>
--- a/framework/summary.py<br>
+++ b/framework/summary.py<br>
@@ -22,7 +22,6 @@<br>
import os<br>
import os.path as path<br>
import string<br>
-import zipfile<br>
from itertools import izip_longest<br>
from shutil import copy<br>
from json import loads<br>
@@ -35,33 +34,6 @@ __all__ = [<br>
]<br>
<br>
<br>
-class Result(core.TestrunResult):<br>
- """<br>
- Object that opens, reads, and stores the data in a resultfile.<br>
- """<br>
- def __init__(self, resultfile):<br>
- # Run the init from TestrunResult<br>
- core.TestrunResult.__init__(self)<br>
-<br>
- # Attempt to load the json file, first looke for a zipped version, and<br>
- # if that doesn't exist look for an unziped version. Assume first that<br>
- # a directory was prvided, and then that a file was provided<br>
- try:<br>
- try:<br>
- zip = zipfile.ZipFile(resultfile)<br>
- result = self.parseFile(zip.open('main', 'r'))<br>
- except zipfile.BadZipfile:<br>
- with open(resultfile, 'r') as file:<br>
- result = self.parseFile(file)<br>
- except IOError:<br>
- try:<br>
- zip = zipfile.ZipFile(path.join(resultfile, 'main.zip'))<br>
- result = self.parseFile(zip.open('main', 'r'))<br>
- except IOError:<br>
- with open(path.join(resultfile, 'main'), 'r') as file:<br>
- result = self.parseFile(file)<br>
-<br>
-<br>
class HTMLIndex(list):<br>
"""<br>
Builds HTML output to be passed to the index mako template, which will be<br>
@@ -387,9 +359,9 @@ class Summary:<br>
<br>
return counts, status<br>
<br>
- # Create a Result object for each piglit result and append it to the<br>
- # results list<br>
- self.results = [Result(i) for i in resultfiles]<br>
+ # Create a TestrunResult object for each piglit result and append it to<br>
+ # the results list<br>
+ self.results = [core.TestrunResult(i) for i in resultfiles]<br>
<br>
self.status = {}<br>
self.fractions = {}<br>
diff --git a/piglit-summary-junit.py b/piglit-summary-junit.py<br>
index d9e4b9c..247de9b 100755<br>
--- a/piglit-summary-junit.py<br>
+++ b/piglit-summary-junit.py<br>
@@ -267,7 +267,7 @@ class Writer:<br>
self.path = []<br>
<br>
def write(self, arg):<br>
- results = [core.loadTestResults(arg)]<br>
+ results = [core.TestrunResult(arg)]<br>
summary = Summary(results)<br>
<br>
self.report.start()<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.5<br>
<br>
</font></span></blockquote></div><br></div>