git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] git-p4 tests: work with python3 as well as python2

From
Luke Diamand <luke@diamand.org>
Date
Apr 23, 2016, 14:13 UTC
Message-ID
<1461420826-4416-3-git-send-email-luke@diamand.org>
In-Reply-To
<1461420826-4416-1-git-send-email-luke@diamand.org>

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 braces in Python3.
Signed-off-by: Luke Diamand <luke@diamand.org>
---
 t/lib-git-p4.sh            | 5 +++--
 t/t9802-git-p4-filetype.sh | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index 77802fe..b97d27c 100644
--- a/t/lib-git-p4.sh
+++ b/t/lib-git-p4.sh
@@ -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"
 }
diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh
index 66d3fc9..eb9a8ed 100755
--- a/t/t9802-git-p4-filetype.sh
+++ b/t/t9802-git-p4-filetype.sh
@@ -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
 }
 
-- 
2.8.1.218.gd2cea43.dirty
Previous: Luke DiamandNext: Junio C Hamano
Message 3 of 5 in “git-p4: support python3 in the tests”
  1. 0/2 git-p4: support python3 in the testsLuke Diamand, Apr 23, 2016
  2. 1/2 git-p4 tests: cd to testdir before running pythonLuke Diamand, Apr 23, 2016
  3. 2/2 git-p4 tests: work with python3 as well as python2Luke Diamand, Apr 23, 2016
  4. Junio C HamanoApr 25, 2016
  5. Luke DiamandApr 26, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.