Patchwork D2133: py3: replace file() with open() in test-convert-git.t

login
register
mail settings
Submitter phabricator
Date Feb. 11, 2018, 12:42 p.m.
Message ID <differential-rev-PHID-DREV-oeg47bywioy3c3oxaipy-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27548/
State Superseded
Headers show

Comments

phabricator - Feb. 11, 2018, 12:42 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  file() is not present in Python 3.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  tests/test-convert-git.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 11, 2018, 2:07 p.m.
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> test-convert-git.t:423
>    $ git init-db >/dev/null 2>/dev/null
> -  $ $PYTHON -c 'file("b", "wb").write("".join([chr(i) for i in range(256)])*16)'
> +  $ $PYTHON -c 'open("b", "wb").write("".join([chr(i) for i in range(256)])*16)'
>    $ git add b

We'll need b"' and make `chr()` return bytes.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel
phabricator - Feb. 12, 2018, 8:46 a.m.
pulkit added inline comments.

INLINE COMMENTS

> yuja wrote in test-convert-git.t:423
> We'll need b"' and make `chr()` return bytes.

To make chr() return bytes, I did chr().encode('latin-1') but there is `UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128) `error while writing to file. Python 2 also don't have the encoding argument to open which Python 3 has. Looks like need to write a .py file and execute that.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel
phabricator - Feb. 12, 2018, 10:37 a.m.
yuja added inline comments.

INLINE COMMENTS

> pulkit wrote in test-convert-git.t:423
> To make chr() return bytes, I did chr().encode('latin-1') but there is `UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128) `error while writing to file. Python 2 also don't have the encoding argument to open which Python 3 has. Looks like need to write a .py file and execute that.

Maybe we can steal pycompat.bytechr of py3. It should work on both Pythons.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t
--- a/tests/test-convert-git.t
+++ b/tests/test-convert-git.t
@@ -420,7 +420,7 @@ 
   $ mkdir git-repo3
   $ cd git-repo3
   $ git init-db >/dev/null 2>/dev/null
-  $ $PYTHON -c 'file("b", "wb").write("".join([chr(i) for i in range(256)])*16)'
+  $ $PYTHON -c 'open("b", "wb").write("".join([chr(i) for i in range(256)])*16)'
   $ git add b
   $ commit -a -m addbinary
   $ cd ..
@@ -437,7 +437,7 @@ 
   $ cd git-repo3-hg
   $ hg up -C
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ $PYTHON -c 'print len(file("b", "rb").read())'
+  $ $PYTHON -c 'print len(open("b", "rb").read())'
   4096
   $ cd ..