D4972: py3: tweak stdout writing in test-hgweb-no-path-info.t

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Oct 12 08:10:01 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4972

AFFECTED FILES
  tests/test-hgweb-no-path-info.t

CHANGE DETAILS

diff --git a/tests/test-hgweb-no-path-info.t b/tests/test-hgweb-no-path-info.t
--- a/tests/test-hgweb-no-path-info.t
+++ b/tests/test-hgweb-no-path-info.t
@@ -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,17 +138,13 @@
    </entry>
   
   </feed>
-  ---- ERRORS
-  
   ---- STATUS
   200 Script output follows
   ---- HEADERS
   [('Content-Type', 'text/plain; charset=ascii')]
   ---- DATA
   
   /repo/
   
-  ---- ERRORS
-  
 
   $ cd ..



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list