Commits

Marcus von Appen committed 971c36e Merge

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

Fix issue with teeing output into binary stream on Python 3

Comments (0)

Files changed (2)

sdl2/test/util/runtests.py

     validate_args(options)
     if options.logfile:
         openlog = open(options.logfile, 'wb')
+        savedstd = sys.stderr, sys.stdout
         # copy stdout and stderr streams to log file
         sys.stderr = support.TeeOutput(sys.stderr, openlog)
         sys.stdout = support.TeeOutput(sys.stdout, openlog)
             writer.writeline(HEAVYDELIM)
             writer.writeline(fail[1])
     if options.logfile:
+        sys.stderr, sys.stdout = savedstd
         openlog.close()
     if len(errors) > 0 or len(failures) > 0:
         return 1

sdl2/test/util/support.py

 # #
 """Utility functions for the tests."""
 import os
+import sys
+
+PY3K = sys.version_info[0] == 3
 
 class StreamOutput(object):
     def __init__(self, stream):
     # -- methods from sys.stdout / sys.stderr
     def write(self, data):
         for stream in self.outputs:
+            if PY3K:
+                if 'b' in stream.mode:
+                    data = data.encode('utf-8')
             stream.write(data)
 
     def tell(self):