git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCHv2 0/3] git-p4: support python3 in the tests
@ 2016-04-26  7:50 Luke Diamand
  2016-04-26  7:50 ` [PATCHv2 1/3] git-p4 tests: cd to / before running python Luke Diamand
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Luke Diamand @ 2016-04-26  7:50 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Lars Schneider, Vitor Antunes, Sam Hocevar,
	Luke Diamand

Updates to my patches to allow the git-p4 tests to work with python3.

Incorporates suggestions from Junio to just switch to "/" and to
use $PYTHON_PATH.

Luke Diamand (3):
  git-p4 tests: cd to / before running python
  git-p4 tests: work with python3 as well as python2
  git-p4 tests: time_in_seconds should use $PYTHON_PATH

 t/lib-git-p4.sh            | 7 ++++---
 t/t9802-git-p4-filetype.sh | 6 +++---
 2 files changed, 7 insertions(+), 6 deletions(-)

-- 
2.8.1.218.gd2cea43.dirty

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCHv2 1/3] git-p4 tests: cd to / before running python
  2016-04-26  7:50 [PATCHv2 0/3] git-p4: support python3 in the tests Luke Diamand
@ 2016-04-26  7:50 ` Luke Diamand
  2016-04-26  7:51 ` [PATCHv2 2/3] git-p4 tests: work with python3 as well as python2 Luke Diamand
  2016-04-26  7:51 ` [PATCHv2 3/3] git-p4 tests: time_in_seconds should use $PYTHON_PATH Luke Diamand
  2 siblings, 0 replies; 6+ messages in thread
From: Luke Diamand @ 2016-04-26  7:50 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Lars Schneider, Vitor Antunes, Sam Hocevar,
	Luke Diamand

The python one-liner for getting the current time prints out
error messages if the current directory is deleted while it is
running if using python3.

Avoid these messages by switching to "/" before running it.

This problem does not arise if using python2.

Signed-off-by: Luke Diamand <luke@diamand.org>
---
 t/lib-git-p4.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index f9ae1d7..724bc43 100644
--- a/t/lib-git-p4.sh
+++ b/t/lib-git-p4.sh
@@ -50,7 +50,7 @@ native_path() {
 # at runtime (e.g. via NTP). The 'clock_gettime(CLOCK_MONOTONIC)'
 # function could fix that but it is not in Python until 3.3.
 time_in_seconds() {
-	python -c 'import time; print int(time.time())'
+	(cd / && python -c 'import time; print(int(time.time()))')
 }
 
 # Try to pick a unique port: guess a large number, then hope
-- 
2.8.1.218.gd2cea43.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCHv2 2/3] git-p4 tests: work with python3 as well as python2
  2016-04-26  7:50 [PATCHv2 0/3] git-p4: support python3 in the tests Luke Diamand
  2016-04-26  7:50 ` [PATCHv2 1/3] git-p4 tests: cd to / before running python Luke Diamand
@ 2016-04-26  7:51 ` Luke Diamand
  2016-04-26 17:48   ` Junio C Hamano
  2016-04-26  7:51 ` [PATCHv2 3/3] git-p4 tests: time_in_seconds should use $PYTHON_PATH Luke Diamand
  2 siblings, 1 reply; 6+ messages in thread
From: Luke Diamand @ 2016-04-26  7:51 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Lars Schneider, Vitor Antunes, Sam Hocevar,
	Luke Diamand

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 724bc43..7393ee2 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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCHv2 3/3] git-p4 tests: time_in_seconds should use $PYTHON_PATH
  2016-04-26  7:50 [PATCHv2 0/3] git-p4: support python3 in the tests Luke Diamand
  2016-04-26  7:50 ` [PATCHv2 1/3] git-p4 tests: cd to / before running python Luke Diamand
  2016-04-26  7:51 ` [PATCHv2 2/3] git-p4 tests: work with python3 as well as python2 Luke Diamand
@ 2016-04-26  7:51 ` Luke Diamand
  2 siblings, 0 replies; 6+ messages in thread
From: Luke Diamand @ 2016-04-26  7:51 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Lars Schneider, Vitor Antunes, Sam Hocevar,
	Luke Diamand

The time_in_seconds script should use $PYTHON_PATH, rather than
just hard-coded python, so that users can override which version
gets used, as is done for other python invocations.

Signed-off-by: Luke Diamand <luke@diamand.org>
---
 t/lib-git-p4.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index 7393ee2..012d40e 100644
--- a/t/lib-git-p4.sh
+++ b/t/lib-git-p4.sh
@@ -50,7 +50,7 @@ native_path() {
 # at runtime (e.g. via NTP). The 'clock_gettime(CLOCK_MONOTONIC)'
 # function could fix that but it is not in Python until 3.3.
 time_in_seconds() {
-	(cd / && python -c 'import time; print(int(time.time()))')
+	(cd / && "$PYTHON_PATH" -c 'import time; print(int(time.time()))')
 }
 
 # Try to pick a unique port: guess a large number, then hope
-- 
2.8.1.218.gd2cea43.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCHv2 2/3] git-p4 tests: work with python3 as well as python2
  2016-04-26  7:51 ` [PATCHv2 2/3] git-p4 tests: work with python3 as well as python2 Luke Diamand
@ 2016-04-26 17:48   ` Junio C Hamano
  2016-04-26 20:03     ` Luke Diamand
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2016-04-26 17:48 UTC (permalink / raw)
  To: Luke Diamand; +Cc: git, Lars Schneider, Vitor Antunes, Sam Hocevar

Luke Diamand <luke@diamand.org> writes:

> 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.

s/braces/parentheses/, I think (can locally tweak if you say so--in
which case no need to resend).

>
> 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 724bc43..7393ee2 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
>  }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCHv2 2/3] git-p4 tests: work with python3 as well as python2
  2016-04-26 17:48   ` Junio C Hamano
@ 2016-04-26 20:03     ` Luke Diamand
  0 siblings, 0 replies; 6+ messages in thread
From: Luke Diamand @ 2016-04-26 20:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Users, Lars Schneider, Vitor Antunes, Sam Hocevar

On 26 April 2016 at 18:48, Junio C Hamano <gitster@pobox.com> wrote:
> Luke Diamand <luke@diamand.org> writes:
>
>> 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.
>
> s/braces/parentheses/, I think (can locally tweak if you say so--in
> which case no need to resend).

Please do so, thanks!

Luke

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-26 20:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-26  7:50 [PATCHv2 0/3] git-p4: support python3 in the tests Luke Diamand
2016-04-26  7:50 ` [PATCHv2 1/3] git-p4 tests: cd to / before running python Luke Diamand
2016-04-26  7:51 ` [PATCHv2 2/3] git-p4 tests: work with python3 as well as python2 Luke Diamand
2016-04-26 17:48   ` Junio C Hamano
2016-04-26 20:03     ` Luke Diamand
2016-04-26  7:51 ` [PATCHv2 3/3] git-p4 tests: time_in_seconds should use $PYTHON_PATH Luke Diamand

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).