Marcus von Appen avatar Marcus von Appen committed 74e977a Merge

Merged in techtonik/py-sdl2/tests-logfile (pull request #18)

Add --logfile option to save test result to the file in addition

Comments (0)

Files changed (2)

sdl2/test/util/runtests.py

                          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",
     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",
     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:
             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

sdl2/test/util/support.py

             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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.