changeset 139:fa7d2db6797c tests-logfile

Add --logfile option to save test result to the file in addition to screen output.
author anatoly techtonik <techtonik@gmail.com>
date Fri, 03 Jan 2014 23:08:26 +0300
parents fce4c7cd5bf8
children 74e977a37b77 080b25a36aa5
files sdl2/test/util/runtests.py sdl2/test/util/support.py
diffstat 2 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sdl2/test/util/runtests.py	Mon Dec 30 12:49:34 2013 +0100
+++ b/sdl2/test/util/runtests.py	Fri Jan 03 23:08:26 2014 +0300
@@ -89,7 +89,7 @@
                          help="Timout for subprocesses before being killed "
                          "(default: 70s per file)")
     optparser.add_option("-v", "--verbose", action="store_true", default=False,
-                         help="be verbose adnd print anything instantly")
+                         help="be verbose and print anything instantly")
     optparser.add_option("-r", "--random", action="store_true", default=False,
                          help="randomize the order of tests")
     optparser.add_option("-S", "--seed", type="int",
@@ -105,6 +105,8 @@
     optparser.add_option("-l", "--listtags", action="callback",
                          callback=list_tags,
                          help="lists all available tags and exits")
+    optparser.add_option("--logfile", type="string",
+                         help="save output to log file")
     optkeys = ["filename",
                "subprocess",
                "timeout",
@@ -191,6 +193,11 @@
     optparser, optkeys = create_options()
     options, args = optparser.parse_args()
     validate_args(options)
+    if options.logfile:
+        openlog = open(options.logfile, 'wb')
+        # copy stdout and stderr streams to log file
+        sys.stderr = support.TeeOutput(sys.stderr, openlog)
+        sys.stdout = support.TeeOutput(sys.stdout, openlog)
     writer = support.StreamOutput(sys.stdout)
 
     if options.verbose and not options.subprocess:
@@ -314,6 +321,8 @@
             writer.writeline("FAILURE: %s" % fail[0])
             writer.writeline(HEAVYDELIM)
             writer.writeline(fail[1])
+    if options.logfile:
+        openlog.close()
     if len(errors) > 0 or len(failures) > 0:
         return 1
     return 0
--- a/sdl2/test/util/support.py	Mon Dec 30 12:49:34 2013 +0100
+++ b/sdl2/test/util/support.py	Fri Jan 03 23:08:26 2014 +0300
@@ -36,3 +36,20 @@
             self.stream.write("%s\r" % data)
         self.curoffset = len(data)
         self.stream.flush()
+
+class TeeOutput(object):
+    def __init__(self, stream1, stream2):
+        self.outputs = [stream1, stream2]
+
+    # -- methods from sys.stdout / sys.stderr
+    def write(self, data):
+        for stream in self.outputs:
+            stream.write(data)
+
+    def tell(self):
+        raise IOError
+
+    def flush(self):
+        for stream in self.outputs:
+            stream.flush()
+    # --/ sys.stdout