git-p4 tests: work with python3 as well as python2

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>

Luke Diamand committed Apr 26, 2016 at 08:51 UTC 84096814a82eeb9c23bfc2b8ad7709d2c616b07d
2 files changed +6 -5
t/lib-git-p4.sh
+3 -2
@@ -198,9 +198,10 @@ marshal_dump() {
198 cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
199 import marshal
200 import sys
201 + instream = getattr(sys.stdin, 'buffer', sys.stdin)
202 for i in range($line):
202 - d = marshal.load(sys.stdin)
203 - print d['$what']
203 + d = marshal.load(instream)
204 + print(d[b'$what'].decode('utf-8'))
205 EOF
206 "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
207 }
t/t9802-git-p4-filetype.sh
+3 -3
@@ -223,12 +223,12 @@ build_gendouble() {
223 import sys
224 import struct
225
226 - s = struct.pack(">LL18s",
226 + s = struct.pack(b">LL18s",
227 0x00051607, # AppleDouble
228 0x00020000, # version 2
229 - "" # pad to 26 bytes
229 + b"" # pad to 26 bytes
230 )
231 - sys.stdout.write(s)
231 + getattr(sys.stdout, 'buffer', sys.stdout).write(s)
232 EOF
233 }
234