From 1e4378d636e035c293d76cc436083dd9c9fa087e Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Sat, 21 Jan 2017 11:22:49 +0100 Subject: [PATCH 1/5] Run python2 or python3 depending on what's used On a system with dependencies installed for python3 but not for python2, we have to make sure python3 is used everywhere since 'python' might be running the python2 interpreter. This helps with some problems in #2400, but doesn't fix the issue completely. --- test/test_convert.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_convert.py b/test/test_convert.py index 2a32e51e7..fe74b0b73 100644 --- a/test/test_convert.py +++ b/test/test_convert.py @@ -15,6 +15,7 @@ from __future__ import division, absolute_import, print_function +import sys import re import os.path import unittest @@ -39,7 +40,7 @@ class TestHelper(helper.TestHelper): # A Python script that copies the file and appends a tag. stub = os.path.join(_common.RSRC, b'convert_stub.py').decode('utf-8') - return u"python '{}' $source $dest {}".format(stub, tag) + return u"python{} '{}' $source $dest {}".format(sys.version_info.major, stub, tag) def assertFileTag(self, path, tag): # noqa """Assert that the path is a file and the files content ends with `tag`. From 42b4e54391e362f4dd144d0ed5bd48f1fcca5d97 Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Sun, 22 Jan 2017 11:45:45 +0100 Subject: [PATCH 2/5] Use sys.executable instead of composing the executable name Better use sys.executable than using sys.version_info.major and compose the name of the python executable. --- test/test_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_convert.py b/test/test_convert.py index fe74b0b73..208bcdb7d 100644 --- a/test/test_convert.py +++ b/test/test_convert.py @@ -40,7 +40,7 @@ class TestHelper(helper.TestHelper): # A Python script that copies the file and appends a tag. stub = os.path.join(_common.RSRC, b'convert_stub.py').decode('utf-8') - return u"python{} '{}' $source $dest {}".format(sys.version_info.major, stub, tag) + return u"{} '{}' $source $dest {}".format(sys.executable, stub, tag) def assertFileTag(self, path, tag): # noqa """Assert that the path is a file and the files content ends with `tag`. From 44ddd2e8f5d2af920865fe3f79856e267e8d071a Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Fri, 27 Jan 2017 11:33:37 +0100 Subject: [PATCH 3/5] Shell-escape sys.executable sys.executable needs to be shell-escaped on windows. --- test/test_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_convert.py b/test/test_convert.py index 208bcdb7d..237cafdeb 100644 --- a/test/test_convert.py +++ b/test/test_convert.py @@ -40,7 +40,7 @@ class TestHelper(helper.TestHelper): # A Python script that copies the file and appends a tag. stub = os.path.join(_common.RSRC, b'convert_stub.py').decode('utf-8') - return u"{} '{}' $source $dest {}".format(sys.executable, stub, tag) + return u"'{}' '{}' $source $dest {}".format(sys.executable, stub, tag) def assertFileTag(self, path, tag): # noqa """Assert that the path is a file and the files content ends with `tag`. From fa468ce9d1fa1f57b50627db14387f7ad98de28f Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Wed, 22 Mar 2017 19:44:42 +0100 Subject: [PATCH 4/5] Properly quote executable and command line parameter Use shlex.quote (on python3) or pipes.quote (on python2) to properly quote the python executable and parameter instead of using single quotes --- test/test_convert.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_convert.py b/test/test_convert.py index 237cafdeb..69a23afd7 100644 --- a/test/test_convert.py +++ b/test/test_convert.py @@ -28,6 +28,15 @@ from beets.mediafile import MediaFile from beets import util +def shell_quote(text): + if sys.version_info[0] < 3: + import pipes + return pipes.quote(text) + else: + import shlex + return shlex.quote(text) + + class TestHelper(helper.TestHelper): def tagged_copy_cmd(self, tag): @@ -40,7 +49,7 @@ class TestHelper(helper.TestHelper): # A Python script that copies the file and appends a tag. stub = os.path.join(_common.RSRC, b'convert_stub.py').decode('utf-8') - return u"'{}' '{}' $source $dest {}".format(sys.executable, stub, tag) + return u"{} {} $source $dest {}".format(shell_quote(sys.executable), shell_quote(stub), tag) def assertFileTag(self, path, tag): # noqa """Assert that the path is a file and the files content ends with `tag`. From 85e0c0dcee70d4983973485e0fe29f417aea3069 Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Thu, 23 Mar 2017 20:19:50 +0100 Subject: [PATCH 5/5] Fixed E501 and E305 PEP8 errors --- test/test_convert.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_convert.py b/test/test_convert.py index 69a23afd7..aa0cd0a34 100644 --- a/test/test_convert.py +++ b/test/test_convert.py @@ -49,7 +49,8 @@ class TestHelper(helper.TestHelper): # A Python script that copies the file and appends a tag. stub = os.path.join(_common.RSRC, b'convert_stub.py').decode('utf-8') - return u"{} {} $source $dest {}".format(shell_quote(sys.executable), shell_quote(stub), tag) + return u"{} {} $source $dest {}".format(shell_quote(sys.executable), + shell_quote(stub), tag) def assertFileTag(self, path, tag): # noqa """Assert that the path is a file and the files content ends with `tag`. @@ -283,5 +284,6 @@ class NeverConvertLossyFilesTest(unittest.TestCase, TestHelper, def suite(): return unittest.TestLoader().loadTestsFromName(__name__) + if __name__ == '__main__': unittest.main(defaultTest='suite')