[Piglit] [PATCH 3/4] core.py: Allow piglit-summary-junit.py to read zipped main files

Dylan Baker baker.dylan.c at gmail.com
Fri Aug 16 09:09:37 PDT 2013


This patch modifies the loadTestResults function in core to allow it to
load zipped main files. This is essentially the same code that is in
summary.Result

CC: jfonseca at vmware.com
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/core.py | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 108b517..680f3ab 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -39,6 +39,7 @@ from textwrap import dedent
 from threads import ConcurrentTestPool
 from threads import synchronized_self
 import threading
+import zipfile
 
 __all__ = ['Environment',
            'checkDir',
@@ -598,21 +599,30 @@ def loadTestProfile(filename):
 
 
 def loadTestResults(relativepath):
+    """
+    Takes a result file as an argument, opens it, and creates a TestrunResult
+    object out of it, which it returns
+    """
     path = os.path.realpath(relativepath)
-    if os.path.isdir(path):
-        filepath = os.path.join(path, 'main')
-    else:
-        filepath = path
-
     testrun = TestrunResult()
-    try:
-        with open(filepath, 'r') as file:
-            testrun.parseFile(file)
-    except OSError:
-        traceback.print_exc()
-        raise Exception('Could not read tests results')
 
-    assert(testrun.name is not None)
+    try:
+        try:
+            zip = zipfile.ZipFile(os.path.join(path, 'main.zip'), 'r')
+            file = zip.open('main', 'r')
+        except zipfile.BadZipfile:
+            with open(os.path.join(path, 'main')) as f:
+                file = f
+    except IOError:
+        try:
+            zip = zipfile.ZipFile(path, 'r')
+            file = zip.open('main', 'r')
+        except zipfile.BadZipfile:
+            with open(path) as f:
+                file = f
+
+    testrun.parseFile(file)
+    assert(testrun.name)
     return testrun
 
 
-- 
1.8.1.5



More information about the Piglit mailing list