Patchwork D7226: tests: write out file using bytes I/O

login
register
mail settings
Submitter phabricator
Date Nov. 5, 2019, 4:58 a.m.
Message ID <differential-rev-PHID-DREV-xs34zegh7wqruu7htwiw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42743/
State Superseded
Headers show

Comments

phabricator - Nov. 5, 2019, 4:58 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The encoding of sys.stdout varies between Python versions. So
  using a one-liner to write a file from a Unicode string is not
  deterministic.
  
  This commit writes out the file using bytes I/O to ensure we
  have exactly the bytes we want in the file.
  
  This change fixes a test failure in Python 3.5/3.6.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  tests/test-highlight.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-highlight.t b/tests/test-highlight.t
--- a/tests/test-highlight.t
+++ b/tests/test-highlight.t
@@ -966,7 +966,9 @@ 
   $ cd ..
   $ hg init eucjp
   $ cd eucjp
-  $ "$PYTHON" -c 'print("\265\376")' >> eucjp.txt  # Japanese kanji "Kyo"
+  >>> with open('eucjp.txt', 'wb') as fh:
+  ...     # Japanese kanji "Kyo"
+  ...     fh.write(u'\265\376'.encode('utf-8')) and None
   $ hg ci -Ama
   adding eucjp.txt
   $ hgserveget () {