[Piglit] [PATCH v2 2/3] framework: print a summary line after a run has finished

Thomas Wood thomas.wood at intel.com
Thu Mar 27 08:52:48 PDT 2014


v2: split output writing into a private method (Dylan Baker)

Signed-off-by: Thomas Wood <thomas.wood at intel.com>
---
 framework/core.py |  2 ++
 framework/log.py  | 44 +++++++++++++++++++++++++++-----------------
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 5f5cf86..391fa5e 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -598,6 +598,8 @@ class TestProfile(object):
         multi.join()
         single.join()
 
+        log.summary()
+
     def filter_tests(self, function):
         """Filter out tests that return false from the supplied function
 
diff --git a/framework/log.py b/framework/log.py
index f6e46b9..d045847 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -47,6 +47,24 @@ class Log(object):
         if verbose:
             self.__output = "{result} :: {name}\n" + self.__output
 
+        self.__summary_output = "[{percent}] {summary}\n"
+
+    def _write_output(self, output):
+        """ write the output to stdout, ensuring any previous line is cleared """
+
+        length = len(output)
+        if self.__lastlength > length:
+            output = "{0}{1}{2}".format(output[:-1],
+                                        " " * (self.__lastlength - length),
+                                        output[-1])
+
+        self.__lastlength = length
+
+        sys.stdout.write(output)
+
+        # Need to flush explicitly, otherwise it all gets buffered without a
+        # newline.
+        sys.stdout.flush()
 
     def _summary(self):
         """ return a summary of the statuses """
@@ -65,23 +83,11 @@ class Log(object):
 
     def __print(self, name, result):
         """ Do the actual printing """
-        output = self.__output.format(**{'percent': self._percent(),
-                                         'running': self._running(),
-                                         'summary': self._summary(),
-                                         'name': name,
-                                         'result': result})
-        length = len(output)
-        if self.__lastlength > length:
-            output = "{0}{1}\r".format(output[:-1],
-                                       " " * (self.__lastlength - length))
-
-        self.__lastlength = length
-
-        sys.stdout.write(output)
-
-        # Need to flush explicitly, otherwise it all gets buffered without a
-        # newline.
-        sys.stdout.flush()
+        self._write_output(self.__output.format(**{'percent': self._percent(),
+                                                   'running': self._running(),
+                                                   'summary': self._summary(),
+                                                   'name': name,
+                                                   'result': result}))
 
     @synchronized_self
     def post_log(self, value, result):
@@ -131,3 +137,7 @@ class Log(object):
         x = self.__generator.next()
         self.__running.append(x)
         return x
+
+    def summary(self):
+        self._write_output(self.__summary_output.format(**{'percent': self._percent(),
+                                                           'summary': self._summary()}))
-- 
1.9.0



More information about the Piglit mailing list