diff tests/test-hgweb-no-path-info.t @ 40161:3eea8e83c261

py3: tweak stdout writing in test-hgweb-no-path-info.t We want to write bytes for convenience. This requires sys.stdout.buffer. But using sys.stdout.buffer introducing buffered output. So we sprinkle code with sys.stdout.flush() to force immediate writes. After all that, Python 3 was emitting b'' prefixed output for errors. So we only print errors if there were some. There aren't, so b'' don't come into play and output is identical in Python 2 and 3. Differential Revision: https://phab.mercurial-scm.org/D4972
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 11 Oct 2018 23:07:23 +0200
parents 5abc47d4ca6b
children f80f7a67e176
line wrap: on
line diff
--- a/tests/test-hgweb-no-path-info.t	Thu Oct 11 22:53:44 2018 +0200
+++ b/tests/test-hgweb-no-path-info.t	Thu Oct 11 23:07:23 2018 +0200
@@ -36,6 +36,7 @@
   >     print('---- HEADERS')
   >     print([i for i in headers if i[0] != 'ETag'])
   >     print('---- DATA')
+  >     sys.stdout.flush()
   >     return output.write
   > 
   > env = {
@@ -55,12 +56,19 @@
   > }
   > 
   > def process(app):
+  >     try:
+  >         stdout = sys.stdout.buffer
+  >     except AttributeError:
+  >         stdout = sys.stdout
   >     content = app(env, startrsp)
-  >     sys.stdout.write(output.getvalue())
-  >     sys.stdout.write(''.join(content))
+  >     stdout.write(output.getvalue())
+  >     stdout.write(b''.join(content))
+  >     stdout.flush()
   >     getattr(content, 'close', lambda : None)()
-  >     print('---- ERRORS')
-  >     print(errors.getvalue())
+  >     if errors.getvalue():
+  >         print('---- ERRORS')
+  >         print(errors.getvalue())
+  >     sys.stdout.flush()
   > 
   > output = stringio()
   > env['QUERY_STRING'] = 'style=atom'
@@ -130,8 +138,6 @@
    </entry>
   
   </feed>
-  ---- ERRORS
-  
   ---- STATUS
   200 Script output follows
   ---- HEADERS
@@ -140,7 +146,5 @@
   
   /repo/
   
-  ---- ERRORS
-  
 
   $ cd ..