From 4350a091eecb5af1dd461442c311d981550bedb5 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Mon, 4 Feb 2013 23:43:35 -0600 Subject: A few non-python 3 print statements --HG-- branch : distribute extra : rebase_source : 75f0b0e993a44ccfef8292717af58943e187d4cd --- setuptools/tests/win_script_wrapper.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'setuptools/tests') diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt index 9ccc96f0..82719273 100644 --- a/setuptools/tests/win_script_wrapper.txt +++ b/setuptools/tests/win_script_wrapper.txt @@ -21,11 +21,11 @@ Let's create a simple script, foo-script.py: ... """#!%(python_exe)s ... import sys ... input = repr(sys.stdin.read()) - ... print sys.argv[0][-14:] - ... print sys.argv[1:] - ... print input + ... print(sys.argv[0][-14:]) + ... print(sys.argv[1:]) + ... print(input) ... if __debug__: - ... print 'non-optimized' + ... print('non-optimized') ... """ % dict(python_exe=nt_quote_arg(sys.executable))) >>> f.close() @@ -54,7 +54,7 @@ the wrapper: ... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b"') >>> input.write('hello\nworld\n') >>> input.close() - >>> print output.read(), + >>> print(output.read(),) \foo-script.py ['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b'] 'hello\nworld\n' @@ -86,18 +86,18 @@ enter the interpreter after running the script, you could use -Oi: ... """#!%(python_exe)s -Oi ... import sys ... input = repr(sys.stdin.read()) - ... print sys.argv[0][-14:] - ... print sys.argv[1:] - ... print input + ... print(sys.argv[0][-14:]) + ... print(sys.argv[1:]) + ... print(input) ... if __debug__: - ... print 'non-optimized' + ... print('non-optimized') ... sys.ps1 = '---' ... """ % dict(python_exe=nt_quote_arg(sys.executable))) >>> f.close() >>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe'))) >>> input.close() - >>> print output.read(), + >>> print(output.read(),) \foo-script.py [] '' @@ -136,10 +136,10 @@ Finally, we'll run the script and check the result: >>> input, output = os.popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'bar.exe')) ... + r' "%s" "Test Argument"' % os.path.join(sample_directory, 'test_output.txt')) >>> input.close() - >>> print output.read() + >>> print(output.read()) >>> f = open(os.path.join(sample_directory, 'test_output.txt'), 'rb') - >>> print f.read() + >>> print(f.read()) 'Test Argument' >>> f.close() -- cgit v1.2.1 From 6f6de308e3ade9a262308297f0a96af261c9dde5 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 16 Feb 2013 11:34:11 -0600 Subject: Backout the pkg_resources.py fix --HG-- branch : distribute extra : rebase_source : d144d2afc763c9ed6420d32bad3015075d265226 --- setuptools/tests/win_script_wrapper.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/tests') diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt index 82719273..3dc725c8 100644 --- a/setuptools/tests/win_script_wrapper.txt +++ b/setuptools/tests/win_script_wrapper.txt @@ -54,11 +54,12 @@ the wrapper: ... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b"') >>> input.write('hello\nworld\n') >>> input.close() - >>> print(output.read(),) + >>> print(output.read()) \foo-script.py ['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b'] 'hello\nworld\n' non-optimized + This example was a little pathological in that it exercised windows (MS C runtime) quoting rules: @@ -97,11 +98,12 @@ enter the interpreter after running the script, you could use -Oi: >>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe'))) >>> input.close() - >>> print(output.read(),) + >>> print(output.read()) \foo-script.py [] '' --- + Testing the GUI Version ----------------------- -- cgit v1.2.1 From 4bb7aab67a2ba4c890732d053a64737486b31b60 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 16 Feb 2013 15:02:50 -0600 Subject: There were some failing tests on windows. I assume this is a NTFS vs FAT or NT versus 9x things... Seemed odd. In any case. My filesystem is deifnitely NOT cp1252. --HG-- branch : distribute extra : rebase_source : c4d64aff6b811ba36bbf33cd4cf2a12f563a6880 --- setuptools/tests/test_sdist.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'setuptools/tests') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index a9d5d6e5..7e6c837c 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -337,10 +337,16 @@ class TestSdistTest(unittest.TestCase): filename = decompose(filename) if sys.version_info >= (3,): - if sys.platform == 'win32': - # Python 3 mangles the UTF-8 filename - filename = filename.decode('cp1252') - self.assertTrue(filename in cmd.filelist.files) + fs_enc = sys.getfilesystemencoding() + + if sys.platform == 'win32': + if fs_enc == 'cp1252': + # Python 3 mangles the UTF-8 filename + filename = filename.decode('cp1252') + self.assertTrue(filename in cmd.filelist.files) + else: + filename = filename.decode('mbcs') + self.assertTrue(filename in cmd.filelist.files) else: filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files) @@ -357,6 +363,7 @@ class TestSdistTest(unittest.TestCase): # Latin-1 filename filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) open(filename, 'w').close() + self.assertTrue(os.path.isfile(filename)) quiet() try: @@ -365,16 +372,27 @@ class TestSdistTest(unittest.TestCase): unquiet() if sys.version_info >= (3,): - filename = filename.decode('latin-1') + fs_enc = sys.getfilesystemencoding() + + + #not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': - # Latin-1 is similar to Windows-1252 + # Latin-1 is similar to Windows-1252 however + # on mbcs filesys it is not in latin-1 encoding + if fs_enc == 'mbcs': + filename = filename.decode('mbcs') + else: + filename = filename.decode('latin-1') + self.assertTrue(filename in cmd.filelist.files) else: # The Latin-1 filename should have been skipped + filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) else: # No conversion takes place under Python 2 and the file # is included. We shall keep it that way for BBB. + filename = filename.decode('latin-1') self.assertTrue(filename in cmd.filelist.files) -- cgit v1.2.1 From 968ff8401b82ad8454191f564c903b137a8e8714 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 16 Feb 2013 15:04:00 -0600 Subject: old win wrapper script not expecting return values from write() python 3 no longer has popen4 had some issue with ^M on end on line. --HG-- branch : distribute extra : rebase_source : 5b2c834e9a8dfd4027791cacef7c2bfe03652f31 --- setuptools/tests/win_script_wrapper.txt | 61 +++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'setuptools/tests') diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt index 3dc725c8..db1daf6b 100644 --- a/setuptools/tests/win_script_wrapper.txt +++ b/setuptools/tests/win_script_wrapper.txt @@ -17,7 +17,7 @@ Let's create a simple script, foo-script.py: >>> from setuptools.command.easy_install import nt_quote_arg >>> sample_directory = tempfile.mkdtemp() >>> f = open(os.path.join(sample_directory, 'foo-script.py'), 'w') - >>> f.write( + >>> bytes_written = f.write( ... """#!%(python_exe)s ... import sys ... input = repr(sys.stdin.read()) @@ -37,7 +37,7 @@ We'll also copy cli.exe to the sample-directory with the name foo.exe: >>> import pkg_resources >>> f = open(os.path.join(sample_directory, 'foo.exe'), 'wb') - >>> f.write( + >>> bytes_written = f.write( ... pkg_resources.resource_string('setuptools', 'cli-32.exe') ... ) >>> f.close() @@ -49,12 +49,32 @@ GUI programs, the suffix '-script-pyw' is added.) This is why we named out script the way we did. Now we can run out script by running the wrapper: - >>> import os - >>> input, output = os.popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'foo.exe')) - ... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b"') - >>> input.write('hello\nworld\n') + >>> from subprocess import Popen, PIPE, STDOUT + >>> try: + ... unicode=unicode + ... except: + ... unicode=str + >>> def popen4(cmd, *args): + ... if hasattr(os, 'popen4'): + ... input, output = os.popen4(cmd + " ".join(args)) + ... return input, output + ... else: + ... #emulate popen4 in python 3 + ... if cmd[0] == '"' and cmd[-1] != '"': + ... cmd = cmd[1:] + ... cmd += " ".join(args) + ... p = Popen(cmd, shell=True, bufsize=0, + ... stdin=PIPE, stdout=PIPE, stderr=STDOUT) + ... return p.stdin, p.stdout + + >>> input, output = popen4('"' + nt_quote_arg(os.path.join(sample_directory, 'foo.exe')), + ... r' arg1', r'"arg 2"', r'"arg \"2\\\""', r'"arg 4\\"', r'"arg5 a\\b"') + >>> bytes_written = input.write('hello\nworld\n'.encode('utf-8')) >>> input.close() - >>> print(output.read()) + >>> # This is needed for line ending differences between py2 and py3 on win32 + >>> msg = unicode(output.read(), encoding='utf-8').split("\n") + >>> for line in msg: + ... print(line.strip()) \foo-script.py ['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b'] 'hello\nworld\n' @@ -83,7 +103,7 @@ options as usual. For example, to run in optimized mode and enter the interpreter after running the script, you could use -Oi: >>> f = open(os.path.join(sample_directory, 'foo-script.py'), 'w') - >>> f.write( + >>> bytes_written = f.write( ... """#!%(python_exe)s -Oi ... import sys ... input = repr(sys.stdin.read()) @@ -96,9 +116,12 @@ enter the interpreter after running the script, you could use -Oi: ... """ % dict(python_exe=nt_quote_arg(sys.executable))) >>> f.close() - >>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe'))) + >>> input, output = popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe'))) >>> input.close() - >>> print(output.read()) + >>> # This is needed for line ending differences between py2 and py3 on win32 + >>> msg = unicode(output.read(), encoding='utf-8').split("\n") + >>> for line in msg: + ... print(line.strip()) \foo-script.py [] '' @@ -114,11 +137,11 @@ Now let's test the GUI version with the simple scipt, bar-script.py: >>> from setuptools.command.easy_install import nt_quote_arg >>> sample_directory = tempfile.mkdtemp() >>> f = open(os.path.join(sample_directory, 'bar-script.pyw'), 'w') - >>> f.write( + >>> bytes_written = f.write( ... """#!%(python_exe)s ... import sys ... f = open(sys.argv[1], 'wb') - ... f.write(repr(sys.argv[2])) + ... bytes_written = f.write(repr(sys.argv[2]).encode('utf-8')) ... f.close() ... """ % dict(python_exe=nt_quote_arg(sys.executable))) >>> f.close() @@ -127,21 +150,23 @@ We'll also copy gui.exe to the sample-directory with the name bar.exe: >>> import pkg_resources >>> f = open(os.path.join(sample_directory, 'bar.exe'), 'wb') - >>> f.write( + >>> bytes_written = f.write( ... pkg_resources.resource_string('setuptools', 'gui-32.exe') ... ) >>> f.close() Finally, we'll run the script and check the result: - >>> import os - >>> input, output = os.popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'bar.exe')) - ... + r' "%s" "Test Argument"' % os.path.join(sample_directory, 'test_output.txt')) + >>> input, output = popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'bar.exe')), + ... r' "%s" "Test Argument"' % os.path.join(sample_directory, 'test_output.txt')) >>> input.close() - >>> print(output.read()) + >>> # This is needed for line ending differences between py2 and py3 on win32 + >>> msg = unicode(output.read(), encoding='utf-8').split("\n") + >>> for line in msg: + ... print(line.strip()) >>> f = open(os.path.join(sample_directory, 'test_output.txt'), 'rb') - >>> print(f.read()) + >>> print(unicode(f.read(), encoding='utf-8')) 'Test Argument' >>> f.close() -- cgit v1.2.1 From e9685aa408ac3d118890bd9944bd26260e519908 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 16 Feb 2013 15:22:46 -0600 Subject: don't decode in python 2.x. that's my oops --HG-- branch : distribute extra : rebase_source : 4b981d54c6a171d7a6500c6c62838d8c368ae0b1 --- setuptools/tests/test_sdist.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'setuptools/tests') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 7e6c837c..f51d4567 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -372,13 +372,11 @@ class TestSdistTest(unittest.TestCase): unquiet() if sys.version_info >= (3,): - fs_enc = sys.getfilesystemencoding() - - #not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however # on mbcs filesys it is not in latin-1 encoding + fs_enc = sys.getfilesystemencoding() if fs_enc == 'mbcs': filename = filename.decode('mbcs') else: @@ -392,7 +390,6 @@ class TestSdistTest(unittest.TestCase): else: # No conversion takes place under Python 2 and the file # is included. We shall keep it that way for BBB. - filename = filename.decode('latin-1') self.assertTrue(filename in cmd.filelist.files) -- cgit v1.2.1