OSDN Git Service

git-p4 tests: work with python3 as well as python2
authorLuke Diamand <luke@diamand.org>
Tue, 26 Apr 2016 07:51:00 +0000 (08:51 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Apr 2016 17:48:13 +0000 (10:48 -0700)
Update the git-p4 tests so that they work with both
Python2 and Python3.

We have to be explicit about the difference between
Unicode text strings (Python3 default) and raw binary
strings which will be exchanged with Perforce.

Additionally, print always takes parentheses in Python3.

Signed-off-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/lib-git-p4.sh
t/t9802-git-p4-filetype.sh

index 724bc43..7393ee2 100644 (file)
@@ -198,9 +198,10 @@ marshal_dump() {
        cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
        import marshal
        import sys
+       instream = getattr(sys.stdin, 'buffer', sys.stdin)
        for i in range($line):
-           d = marshal.load(sys.stdin)
-       print d['$what']
+           d = marshal.load(instream)
+       print(d[b'$what'].decode('utf-8'))
        EOF
        "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
 }
index 66d3fc9..eb9a8ed 100755 (executable)
@@ -223,12 +223,12 @@ build_gendouble() {
        import sys
        import struct
 
-       s = struct.pack(">LL18s",
+       s = struct.pack(b">LL18s",
                        0x00051607,  # AppleDouble
                        0x00020000,  # version 2
-                       ""           # pad to 26 bytes
+                       b""          # pad to 26 bytes
        )
-       sys.stdout.write(s)
+       getattr(sys.stdout, 'buffer', sys.stdout).write(s)
        EOF
 }