[Piglit] [PATCH 5/9] Combine summary.load_results into core.loadTestResults
Dylan Baker
baker.dylan.c at gmail.com
Tue Oct 15 12:13:27 CEST 2013
This reduces code duplication, since these two functions were very
similar to begin with.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/core.py | 28 +++++++++++++++++-----------
framework/summary.py | 18 +-----------------
2 files changed, 18 insertions(+), 28 deletions(-)
diff --git a/framework/core.py b/framework/core.py
index f003a44..e00392d 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -609,23 +609,29 @@ def loadTestProfile(filename):
return ns['profile']
-def loadTestResults(relativepath):
- path = os.path.realpath(relativepath)
- if os.path.isdir(path):
- filepath = os.path.join(path, 'main')
- else:
- filepath = path
+def loadTestResults(filename):
+ """ Loader function for TestrunResult class
+
+ This function takes a single argument of a results file.
+
+ It makes quite a few assumptions, first it assumes that it has been passed
+ a folder, if that fails then it looks for a plain text json file called
+ "main"
+
+ """
+ filename = os.path.realpath(filename)
try:
- with open(filepath, 'r') as resultfile:
- testrun = TestrunResult(resultfile)
- except OSError:
- traceback.print_exc()
- raise Exception('Could not read tests results')
+ with open(filename, 'r') as resultsfile:
+ testrun = TestrunResult(resultsfile)
+ except IOError:
+ with open(os.path.join(filename, "main"), 'r') as resultsfile:
+ testrun = TestrunResult(resultsfile)
assert(testrun.name is not None)
return testrun
+
# Error messages to be ignored
Test.ignoreErrors = map(re.compile,
["couldn't open libtxc_dxtn.so",
diff --git a/framework/summary.py b/framework/summary.py
index 7afbe7b..30e1fc3 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -35,22 +35,6 @@ __all__ = [
]
-def load_result(resultfile):
- # Run the init from TestrunResult
- result = core.TestrunResult().
-
- # Load the json file, or if that fails assume that the locations given
- # is a folder containing a json file
- try:
- with open(resultfile, 'r') as file:
- result = TestrunResult(file)
- except IOError:
- with open(path.join(resultfile, 'main'), 'r') as file:
- result = TestrunResult(file)
-
- return result
-
-
class HTMLIndex(list):
"""
Builds HTML output to be passed to the index mako template, which will be
@@ -355,7 +339,7 @@ class Summary:
# Create a Result object for each piglit result and append it to the
# results list
- self.results = [load_result(i) for i in resultfiles]
+ self.results = [core.loadTestResults(i) for i in resultfiles]
self.status = {}
self.fractions = {}
--
1.8.1.5
More information about the Piglit
mailing list