Skip to content

Commit 8409681

Browse files
luked99gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d1deaf4 commit 8409681

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

t/lib-git-p4.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ marshal_dump() {
198198
cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
199199
import marshal
200200
import sys
201+
instream = getattr(sys.stdin, 'buffer', sys.stdin)
201202
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'))
204205
EOF
205206
"$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
206207
}

t/t9802-git-p4-filetype.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ build_gendouble() {
223223
import sys
224224
import struct
225225
226-
s = struct.pack(">LL18s",
226+
s = struct.pack(b">LL18s",
227227
0x00051607, # AppleDouble
228228
0x00020000, # version 2
229-
"" # pad to 26 bytes
229+
b"" # pad to 26 bytes
230230
)
231-
sys.stdout.write(s)
231+
getattr(sys.stdout, 'buffer', sys.stdout).write(s)
232232
EOF
233233
}
234234

0 commit comments

Comments
 (0)