From 21ead63de1689b99007d0ab9b41a19b09543e7b3 Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Mon, 15 Oct 2012 14:48:49 +0200 Subject: Revert 86d7748 drive-by commit because of unclear BBB consequences. --HG-- branch : distribute extra : rebase_source : 2fb9a6ec09184e238551be4d0ea908e719badd27 --- setuptools/tests/test_sdist.py | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 7e2f0a49..4478d438 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -29,6 +29,17 @@ setup(**%r) """ % SETUP_ATTRS +def compose(path): + # HFS Plus returns decomposed UTF-8 + if sys.platform == 'darwin': + from unicodedata import normalize + if sys.version_info >= (3,): + path = normalize('NFC', path) + else: + path = normalize('NFC', path.decode('utf-8')).encode('utf-8') + return path + + class TestSdistTest(unittest.TestCase): def setUp(self): self.temp_dir = tempfile.mkdtemp() @@ -79,31 +90,6 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest) self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest) - def test_filelist_is_fully_composed(self): - # Test for #303. Requires HFS Plus to fail. - - # Add file with non-ASCII filename - filename = os.path.join('sdist_test', 'smörbröd.py') - open(filename, 'w').close() - - dist = Distribution(SETUP_ATTRS) - dist.script_name = 'setup.py' - cmd = sdist(dist) - cmd.ensure_finalized() - - # squelch output - old_stdout = sys.stdout - old_stderr = sys.stderr - sys.stdout = StringIO() - sys.stderr = StringIO() - try: - cmd.run() - finally: - sys.stdout = old_stdout - sys.stderr = old_stderr - - self.assertTrue(filename in cmd.filelist.files) - def test_manifest_is_written_in_utf8(self): # Test for #303. @@ -162,7 +148,7 @@ class TestSdistTest(unittest.TestCase): cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') cmd.read_manifest() - self.assertTrue(filename in cmd.filelist.files) + self.assertTrue(filename in [compose(x) for x in cmd.filelist.files]) def test_suite(): -- cgit v1.2.1 From 9d66fb61d9579516c5333d51eb85dc3495e6032f Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Wed, 17 Oct 2012 10:54:39 +0200 Subject: Use surrogateescape error handler when reading and writing the manifest. Refs #303. --HG-- branch : distribute extra : rebase_source : f0231cf87e2478f988f798dfe579f28e7561aeff --- setuptools/tests/test_sdist.py | 256 ++++++++++++++++++++++++++++++++++------- 1 file changed, 212 insertions(+), 44 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 4478d438..65b83b6e 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -7,10 +7,13 @@ import shutil import sys import tempfile import unittest +import urllib +import unicodedata from StringIO import StringIO from setuptools.command.sdist import sdist +from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution @@ -29,18 +32,58 @@ setup(**%r) """ % SETUP_ATTRS -def compose(path): - # HFS Plus returns decomposed UTF-8 - if sys.platform == 'darwin': - from unicodedata import normalize +if sys.version_info >= (3,): + LATIN1_FILENAME = 'smörbröd.py'.encode('latin-1') +else: + LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py' + + +# Cannot use context manager because of Python 2.4 +def quiet(): + global old_stdout, old_stderr + old_stdout, old_stderr = sys.stdout, sys.stderr + sys.stdout, sys.stderr = StringIO(), StringIO() + +def unquiet(): + sys.stdout, sys.stderr = old_stdout, old_stderr + + +# Fake byte literals to shut up Python <= 2.5 +def b(s, encoding='utf-8'): + if sys.version_info >= (3,): + return s.encode(encoding) + return s + + +# HFS Plus returns decomposed UTF-8 +def decompose(path): + if isinstance(path, unicode): + return unicodedata.normalize('NFD', path) + try: + path = path.decode('utf-8') + path = unicodedata.normalize('NFD', path) + path = path.encode('utf-8') + except UnicodeError: + pass # Not UTF-8 + return path + + +# HFS Plus quotes unknown bytes like so: %F6 +def hfs_quote(path): + if isinstance(path, unicode): + raise TypeError('bytes are required') + try: + u = path.decode('utf-8') + except UnicodeDecodeError: + path = urllib.quote(path) # Not UTF-8 + else: if sys.version_info >= (3,): - path = normalize('NFC', path) - else: - path = normalize('NFC', path.decode('utf-8')).encode('utf-8') + path = u return path class TestSdistTest(unittest.TestCase): + def setUp(self): self.temp_dir = tempfile.mkdtemp() f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') @@ -74,81 +117,206 @@ class TestSdistTest(unittest.TestCase): cmd.ensure_finalized() # squelch output - old_stdout = sys.stdout - old_stderr = sys.stderr - sys.stdout = StringIO() - sys.stderr = StringIO() + quiet() try: cmd.run() finally: - sys.stdout = old_stdout - sys.stderr = old_stderr + unquiet() manifest = cmd.filelist.files - self.assertTrue(os.path.join('sdist_test', 'a.txt') in manifest) self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest) self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest) - def test_manifest_is_written_in_utf8(self): + def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + mm = manifest_maker(dist) + mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + os.mkdir('sdist_test.egg-info') - # Add file with non-ASCII filename + # UTF-8 filename filename = os.path.join('sdist_test', 'smörbröd.py') - open(filename, 'w').close() + # Add UTF-8 filename and write manifest + quiet() + try: + mm.run() + mm.filelist.files.append(filename) + mm.write_manifest() + finally: + unquiet() + + manifest = open(mm.manifest, 'rbU') + contents = manifest.read() + manifest.close() + + # The manifest should be UTF-8 encoded + try: + u = contents.decode('UTF-8') + except UnicodeDecodeError, e: + self.fail(e) + + # The manifest should contain the UTF-8 filename + if sys.version_info >= (3,): + self.assertTrue(filename in u) + else: + self.assertTrue(filename in contents) + + def test_manifest_is_written_with_surrogateescape_error_handler(self): + # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' - cmd = sdist(dist) - cmd.ensure_finalized() + mm = manifest_maker(dist) + mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + os.mkdir('sdist_test.egg-info') - # squelch output - old_stdout = sys.stdout - old_stderr = sys.stderr - sys.stdout = StringIO() - sys.stderr = StringIO() + # Latin-1 filename + filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + + # Add filename with surrogates and write manifest + quiet() try: - cmd.run() + mm.run() + if sys.version_info >= (3,): + u = filename.decode('utf-8', 'surrogateescape') + mm.filelist.files.append(u) + else: + mm.filelist.files.append(filename) + mm.write_manifest() finally: - sys.stdout = old_stdout - sys.stderr = old_stderr + unquiet() - manifest = open(os.path.join('sdist_test.egg-info', 'SOURCES.txt'), 'rbU') + manifest = open(mm.manifest, 'rbU') contents = manifest.read() manifest.close() - self.assertTrue(len(contents)) - # This must not fail: - contents.decode('UTF-8') + # The manifest should contain the Latin-1 filename + self.assertTrue(filename in contents) - def test_manifest_is_read_in_utf8(self): + def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() - # Add file with non-ASCII filename + # UTF-8 filename filename = os.path.join('sdist_test', 'smörbröd.py') open(filename, 'w').close() + quiet() + try: + cmd.run() + finally: + unquiet() + + # The filelist should contain the UTF-8 filename + if sys.platform == 'darwin': + filename = decompose(filename) + self.assertTrue(filename in cmd.filelist.files) + + def test_manifest_is_read_with_surrogateescape_error_handler(self): + # Test for #303. + + # This is hard to test on HFS Plus because it quotes unknown + # bytes (see previous test). Furthermore, egg_info.FileList + # only appends filenames that os.path.exist. + + # We therefore write the manifest file by hand and check whether + # read_manifest produces a UnicodeDecodeError. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + + quiet() + try: + cmd.run() + # Add Latin-1 filename to manifest + cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + manifest = open(cmd.manifest, 'ab') + manifest.write(filename+b('\n')) + manifest.close() + # Re-read manifest + try: + cmd.read_manifest() + except UnicodeDecodeError, e: + self.fail(e) + finally: + unquiet() + + def test_sdist_with_utf8_encoded_filename(self): + # Test for #303. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # UTF-8 filename + filename = os.path.join(b('sdist_test'), b('smörbröd.py')) + open(filename, 'w').close() + + quiet() + try: + cmd.run() + finally: + unquiet() + + # The filelist should contain the UTF-8 filename + # (in one representation or other) + if sys.version_info >= (3,): + filename = filename.decode(sys.getfilesystemencoding(), 'surrogateescape') + if sys.platform == 'darwin': + filename = decompose(filename) + self.assertTrue(filename in cmd.filelist.files) + + def test_sdist_with_latin1_encoded_filename(self): + # Test for #303. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() - # squelch output - old_stdout = sys.stdout - old_stderr = sys.stderr - sys.stdout = StringIO() - sys.stderr = StringIO() + # Latin-1 filename + filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + open(filename, 'w').close() + + quiet() try: cmd.run() finally: - sys.stdout = old_stdout - sys.stderr = old_stderr + unquiet() + + # The filelist should contain the Latin-1 filename + # (in one representation or other) + if sys.platform == 'darwin': + filename = hfs_quote(filename) + elif sys.version_info >= (3,): + filename = filename.decode(sys.getfilesystemencoding(), 'surrogateescape') + self.assertTrue(filename in cmd.filelist.files) + + def test_decompose(self): + self.assertNotEqual('smörbröd.py', decompose('smörbröd.py')) - cmd.filelist.files = [] - cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') - cmd.read_manifest() + if sys.version_info >= (3,): + self.assertEqual(len('smörbröd.py'), 11) + self.assertEqual(len(decompose('smörbröd.py')), 13) + else: + self.assertEqual(len('smörbröd.py'), 13) + self.assertEqual(len(decompose('smörbröd.py')), 15) + + def test_hfs_quote(self): + self.assertEqual(hfs_quote(LATIN1_FILENAME), 'sm%F6rbr%F6d.py') - self.assertTrue(filename in [compose(x) for x in cmd.filelist.files]) + # Bytes are required + if sys.version_info >= (3,): + self.assertRaises(TypeError, hfs_quote, 'smörbröd.py') + else: + self.assertRaises(TypeError, hfs_quote, 'smörbröd.py'.decode('utf-8')) def test_suite(): -- cgit v1.2.1 From 44db905fd2d3c3a8cd7218a1c45cf54d353ed9ea Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 21 Oct 2012 03:49:51 -0400 Subject: Fix two failing tests on Windows (paths separated by backslash didn't match manifest paths separated by slash). --HG-- branch : distribute extra : rebase_source : f8cd5491fcfe18f687a67423bb8ccc43d3d76672 --- setuptools/tests/test_sdist.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 65b83b6e..347e0085 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,6 +9,7 @@ import tempfile import unittest import urllib import unicodedata +import posixpath from StringIO import StringIO @@ -137,7 +138,7 @@ class TestSdistTest(unittest.TestCase): os.mkdir('sdist_test.egg-info') # UTF-8 filename - filename = os.path.join('sdist_test', 'smörbröd.py') + filename = posixpath.join('sdist_test', 'smörbröd.py') # Add UTF-8 filename and write manifest quiet() @@ -173,7 +174,7 @@ class TestSdistTest(unittest.TestCase): os.mkdir('sdist_test.egg-info') # Latin-1 filename - filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + filename = posixpath.join(b('sdist_test'), LATIN1_FILENAME) # Add filename with surrogates and write manifest quiet() -- cgit v1.2.1 From 383ad7a4f7a1832cf74c250cdae5b63fa4ad61bb Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Thu, 25 Oct 2012 23:45:35 +0200 Subject: Update tests. --HG-- branch : distribute extra : rebase_source : 831e694725e5db1bc360298fbc4b7b58db836bdd --- setuptools/tests/test_sdist.py | 220 ++++++++++++++++++++++------------------- 1 file changed, 121 insertions(+), 99 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 347e0085..a3fde026 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,7 +9,6 @@ import tempfile import unittest import urllib import unicodedata -import posixpath from StringIO import StringIO @@ -49,14 +48,22 @@ def unquiet(): sys.stdout, sys.stderr = old_stdout, old_stderr -# Fake byte literals to shut up Python <= 2.5 +# Fake byte literals for Python <= 2.5 def b(s, encoding='utf-8'): if sys.version_info >= (3,): return s.encode(encoding) return s -# HFS Plus returns decomposed UTF-8 +# Convert to POSIX path +def posix(path): + if sys.version_info >= (3,) and not isinstance(path, str): + return path.replace(os.sep.encode('ascii'), b('/')) + else: + return path.replace(os.sep, '/') + + +# HFS Plus uses decomposed UTF-8 def decompose(path): if isinstance(path, unicode): return unicodedata.normalize('NFD', path) @@ -69,20 +76,6 @@ def decompose(path): return path -# HFS Plus quotes unknown bytes like so: %F6 -def hfs_quote(path): - if isinstance(path, unicode): - raise TypeError('bytes are required') - try: - u = path.decode('utf-8') - except UnicodeDecodeError: - path = urllib.quote(path) # Not UTF-8 - else: - if sys.version_info >= (3,): - path = u - return path - - class TestSdistTest(unittest.TestCase): def setUp(self): @@ -138,7 +131,7 @@ class TestSdistTest(unittest.TestCase): os.mkdir('sdist_test.egg-info') # UTF-8 filename - filename = posixpath.join('sdist_test', 'smörbröd.py') + filename = os.path.join('sdist_test', 'smörbröd.py') # Add UTF-8 filename and write manifest quiet() @@ -155,46 +148,94 @@ class TestSdistTest(unittest.TestCase): # The manifest should be UTF-8 encoded try: - u = contents.decode('UTF-8') + u_contents = contents.decode('UTF-8') except UnicodeDecodeError, e: self.fail(e) # The manifest should contain the UTF-8 filename if sys.version_info >= (3,): - self.assertTrue(filename in u) + self.assertTrue(posix(filename) in u_contents) else: - self.assertTrue(filename in contents) + self.assertTrue(posix(filename) in contents) - def test_manifest_is_written_with_surrogateescape_error_handler(self): - # Test for #303. - dist = Distribution(SETUP_ATTRS) - dist.script_name = 'setup.py' - mm = manifest_maker(dist) - mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') - os.mkdir('sdist_test.egg-info') + # Python 3 only + if sys.version_info >= (3,): - # Latin-1 filename - filename = posixpath.join(b('sdist_test'), LATIN1_FILENAME) + def test_write_manifest_allows_utf8_filenames(self): + # Test for #303. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + mm = manifest_maker(dist) + mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + os.mkdir('sdist_test.egg-info') - # Add filename with surrogates and write manifest - quiet() - try: - mm.run() - if sys.version_info >= (3,): - u = filename.decode('utf-8', 'surrogateescape') - mm.filelist.files.append(u) - else: - mm.filelist.files.append(filename) - mm.write_manifest() - finally: - unquiet() + # UTF-8 filename + filename = os.path.join(b('sdist_test'), b('smörbröd.py')) - manifest = open(mm.manifest, 'rbU') - contents = manifest.read() - manifest.close() + # Add filename and write manifest + quiet() + try: + mm.run() + u_filename = filename.decode('utf-8') + mm.filelist.files.append(u_filename) + # Re-write manifest + mm.write_manifest() + finally: + unquiet() + + manifest = open(mm.manifest, 'rbU') + contents = manifest.read() + manifest.close() + + # The manifest should be UTF-8 encoded + try: + contents.decode('UTF-8') + except UnicodeDecodeError, e: + self.fail(e) + + # The manifest should contain the UTF-8 filename + self.assertTrue(posix(filename) in contents) + + # The filelist should have been updated as well + self.assertTrue(u_filename in mm.filelist.files) - # The manifest should contain the Latin-1 filename - self.assertTrue(filename in contents) + def test_write_manifest_skips_non_utf8_filenames(self): + # Test for #303. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + mm = manifest_maker(dist) + mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + os.mkdir('sdist_test.egg-info') + + # Latin-1 filename + filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + + # Add filename with surrogates and write manifest + quiet() + try: + mm.run() + u_filename = filename.decode('utf-8', 'surrogateescape') + mm.filelist.files.append(u_filename) + # Re-write manifest + mm.write_manifest() + finally: + unquiet() + + manifest = open(mm.manifest, 'rbU') + contents = manifest.read() + manifest.close() + + # The manifest should be UTF-8 encoded + try: + contents.decode('UTF-8') + except UnicodeDecodeError, e: + self.fail(e) + + # The Latin-1 filename should have been skipped + self.assertFalse(posix(filename) in contents) + + # The filelist should have been updated as well + self.assertFalse(u_filename in mm.filelist.files) def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. @@ -218,37 +259,37 @@ class TestSdistTest(unittest.TestCase): filename = decompose(filename) self.assertTrue(filename in cmd.filelist.files) - def test_manifest_is_read_with_surrogateescape_error_handler(self): - # Test for #303. + # Python 3 only + if sys.version_info >= (3,): - # This is hard to test on HFS Plus because it quotes unknown - # bytes (see previous test). Furthermore, egg_info.FileList - # only appends filenames that os.path.exist. + def test_read_manifest_rejects_surrogates(self): + # Test for #303. - # We therefore write the manifest file by hand and check whether - # read_manifest produces a UnicodeDecodeError. - dist = Distribution(SETUP_ATTRS) - dist.script_name = 'setup.py' - cmd = sdist(dist) - cmd.ensure_finalized() + # This is hard to test on HFS Plus because it quotes unknown + # bytes (see previous test). Furthermore, egg_info.FileList + # only appends filenames that os.path.exist. - filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + # We therefore write the manifest file by hand and check whether + # read_manifest produces a UnicodeDecodeError. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() - quiet() - try: - cmd.run() - # Add Latin-1 filename to manifest - cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') - manifest = open(cmd.manifest, 'ab') - manifest.write(filename+b('\n')) - manifest.close() - # Re-read manifest + filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + + quiet() try: - cmd.read_manifest() - except UnicodeDecodeError, e: - self.fail(e) - finally: - unquiet() + cmd.run() + # Add Latin-1 filename to manifest + cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + manifest = open(cmd.manifest, 'ab') + manifest.write(filename+b('\n')) + manifest.close() + finally: + unquiet() + + self.assertRaises(UnicodeDecodeError, cmd.read_manifest) def test_sdist_with_utf8_encoded_filename(self): # Test for #303. @@ -268,9 +309,8 @@ class TestSdistTest(unittest.TestCase): unquiet() # The filelist should contain the UTF-8 filename - # (in one representation or other) if sys.version_info >= (3,): - filename = filename.decode(sys.getfilesystemencoding(), 'surrogateescape') + filename = filename.decode('utf-8') if sys.platform == 'darwin': filename = decompose(filename) self.assertTrue(filename in cmd.filelist.files) @@ -292,32 +332,14 @@ class TestSdistTest(unittest.TestCase): finally: unquiet() - # The filelist should contain the Latin-1 filename - # (in one representation or other) - if sys.platform == 'darwin': - filename = hfs_quote(filename) - elif sys.version_info >= (3,): - filename = filename.decode(sys.getfilesystemencoding(), 'surrogateescape') - self.assertTrue(filename in cmd.filelist.files) - - def test_decompose(self): - self.assertNotEqual('smörbröd.py', decompose('smörbröd.py')) - - if sys.version_info >= (3,): - self.assertEqual(len('smörbröd.py'), 11) - self.assertEqual(len(decompose('smörbröd.py')), 13) - else: - self.assertEqual(len('smörbröd.py'), 13) - self.assertEqual(len(decompose('smörbröd.py')), 15) - - def test_hfs_quote(self): - self.assertEqual(hfs_quote(LATIN1_FILENAME), 'sm%F6rbr%F6d.py') - - # Bytes are required + # The Latin-1 filename should have been skipped if sys.version_info >= (3,): - self.assertRaises(TypeError, hfs_quote, 'smörbröd.py') + filename = filename.decode('latin-1') + self.assertFalse(filename in cmd.filelist.files) else: - self.assertRaises(TypeError, hfs_quote, 'smörbröd.py'.decode('utf-8')) + # No conversion takes place under Python 2 and the + # filename is included. We shall keep it that way for BBB. + self.assertTrue(filename in cmd.filelist.files) def test_suite(): -- cgit v1.2.1 From 22882958087e20839daf0139a94f8411d17d6a2c Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Fri, 26 Oct 2012 02:10:14 +0200 Subject: Make sdist tests pass on Windows. --HG-- branch : distribute extra : rebase_source : 9fb51372737224be8d5c50265b04a36f19543572 --- setuptools/tests/test_sdist.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index a3fde026..378015a8 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -308,12 +308,19 @@ class TestSdistTest(unittest.TestCase): finally: unquiet() - # The filelist should contain the UTF-8 filename - if sys.version_info >= (3,): - filename = filename.decode('utf-8') if sys.platform == 'darwin': filename = decompose(filename) - self.assertTrue(filename in cmd.filelist.files) + + 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) + else: + filename = filename.decode('utf-8') + self.assertTrue(filename in cmd.filelist.files) + else: + self.assertTrue(filename in cmd.filelist.files) def test_sdist_with_latin1_encoded_filename(self): # Test for #303. @@ -332,13 +339,17 @@ class TestSdistTest(unittest.TestCase): finally: unquiet() - # The Latin-1 filename should have been skipped if sys.version_info >= (3,): filename = filename.decode('latin-1') - self.assertFalse(filename in cmd.filelist.files) + if sys.platform == 'win32': + # Latin-1 is similar to Windows-1252 + self.assertTrue(filename in cmd.filelist.files) + else: + # The Latin-1 filename should have been skipped + self.assertFalse(filename in cmd.filelist.files) else: - # No conversion takes place under Python 2 and the - # filename is included. We shall keep it that way for BBB. + # No conversion takes place under Python 2 and the file + # is included. We shall keep it that way for BBB. self.assertTrue(filename in cmd.filelist.files) -- cgit v1.2.1 From e485c19015d4fced68b25c09ca66a1743d3ab27c Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Fri, 26 Oct 2012 12:46:41 +0200 Subject: Keep 'surrogateescape' when reading the manifest, to avoid breaking on bad input. --HG-- branch : distribute extra : rebase_source : 6f894cd508e73fae0ad02860654df5181055ba4d --- setuptools/tests/test_sdist.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 378015a8..04b3db66 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -262,7 +262,7 @@ class TestSdistTest(unittest.TestCase): # Python 3 only if sys.version_info >= (3,): - def test_read_manifest_rejects_surrogates(self): + def test_manifest_is_read_with_surrogateescape_error_handler(self): # Test for #303. # This is hard to test on HFS Plus because it quotes unknown @@ -286,11 +286,14 @@ class TestSdistTest(unittest.TestCase): manifest = open(cmd.manifest, 'ab') manifest.write(filename+b('\n')) manifest.close() + # Re-read manifest + try: + cmd.read_manifest() + except UnicodeDecodeError, e: + self.fail(e) finally: unquiet() - self.assertRaises(UnicodeDecodeError, cmd.read_manifest) - def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From f266bc3745169122fcfcacb781e7e3c70fc58bfb Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Thu, 1 Nov 2012 11:47:24 +0100 Subject: Skip undecodable filenames in read_manifest as well. --HG-- branch : distribute extra : rebase_source : 2dda494b1a4758e84dde81cc61170acd0e55d2f2 --- setuptools/tests/test_sdist.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 04b3db66..a596f4bd 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -262,7 +262,7 @@ class TestSdistTest(unittest.TestCase): # Python 3 only if sys.version_info >= (3,): - def test_manifest_is_read_with_surrogateescape_error_handler(self): + def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. # This is hard to test on HFS Plus because it quotes unknown @@ -277,6 +277,7 @@ class TestSdistTest(unittest.TestCase): cmd.ensure_finalized() filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + u_filename = filename.decode('latin-1') quiet() try: @@ -284,7 +285,7 @@ class TestSdistTest(unittest.TestCase): # Add Latin-1 filename to manifest cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') - manifest.write(filename+b('\n')) + manifest.write(b('\n')+filename) manifest.close() # Re-read manifest try: @@ -294,6 +295,9 @@ class TestSdistTest(unittest.TestCase): finally: unquiet() + # The Latin-1 filename should have been skipped + self.assertFalse(u_filename in cmd.filelist.files) + def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From 945189affe2ec3d2e25a9255a73bf05b828ab7c3 Mon Sep 17 00:00:00 2001 From: "stefan@epy" Date: Mon, 5 Nov 2012 00:20:39 +0100 Subject: Rewrite tests for read_manifest. --HG-- branch : distribute extra : rebase_source : 8e52687fae6a06e1421c51ddec62870ef7499676 --- setuptools/tests/test_sdist.py | 58 +++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index a596f4bd..9d2c382f 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -57,7 +57,7 @@ def b(s, encoding='utf-8'): # Convert to POSIX path def posix(path): - if sys.version_info >= (3,) and not isinstance(path, str): + if sys.version_info >= (3,) and not isinstance(path, unicode): return path.replace(os.sep.encode('ascii'), b('/')) else: return path.replace(os.sep, '/') @@ -244,19 +244,35 @@ class TestSdistTest(unittest.TestCase): cmd = sdist(dist) cmd.ensure_finalized() - # UTF-8 filename - filename = os.path.join('sdist_test', 'smörbröd.py') + # Create manifest + quiet() + try: + cmd.run() + finally: + unquiet() + + # Add UTF-8 filename to manifest + filename = os.path.join(b('sdist_test'), b('smörbröd.py')) + cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + manifest = open(cmd.manifest, 'ab') + manifest.write(b('\n')+filename) + manifest.close() + + # The file must exist to be included in the filelist open(filename, 'w').close() + # Re-read manifest quiet() try: - cmd.run() + cmd.read_manifest() finally: unquiet() # The filelist should contain the UTF-8 filename if sys.platform == 'darwin': filename = decompose(filename) + if sys.version_info >= (3,): + filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files) # Python 3 only @@ -264,30 +280,31 @@ class TestSdistTest(unittest.TestCase): def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. - - # This is hard to test on HFS Plus because it quotes unknown - # bytes (see previous test). Furthermore, egg_info.FileList - # only appends filenames that os.path.exist. - - # We therefore write the manifest file by hand and check whether - # read_manifest produces a UnicodeDecodeError. dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() + # Create manifest + quiet() + try: + cmd.run() + finally: + unquiet() + + # Add Latin-1 filename to manifest filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) - u_filename = filename.decode('latin-1') + cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + manifest = open(cmd.manifest, 'ab') + manifest.write(b('\n')+filename) + manifest.close() + # The file must exist to be included in the filelist + open(filename, 'w').close() + + # Re-read manifest quiet() try: - cmd.run() - # Add Latin-1 filename to manifest - cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') - manifest = open(cmd.manifest, 'ab') - manifest.write(b('\n')+filename) - manifest.close() - # Re-read manifest try: cmd.read_manifest() except UnicodeDecodeError, e: @@ -296,7 +313,8 @@ class TestSdistTest(unittest.TestCase): unquiet() # The Latin-1 filename should have been skipped - self.assertFalse(u_filename in cmd.filelist.files) + filename = filename.decode('latin-1') + self.assertFalse(filename in cmd.filelist.files) def test_sdist_with_utf8_encoded_filename(self): # Test for #303. -- cgit v1.2.1 From 739d56cdb4f18829de123379488a78cf52e0a6d1 Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Mon, 5 Nov 2012 00:26:25 +0100 Subject: No longer decompose filename for comparison. --HG-- branch : distribute extra : rebase_source : 02265fdf50dbe58c41b98e575f1d0d71c95e4bcf --- setuptools/tests/test_sdist.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 9d2c382f..cb601d8c 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -269,8 +269,6 @@ class TestSdistTest(unittest.TestCase): unquiet() # The filelist should contain the UTF-8 filename - if sys.platform == 'darwin': - filename = decompose(filename) if sys.version_info >= (3,): filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files) -- cgit v1.2.1 From 19a723890b724f92b8c42b162cea2a4052a746f2 Mon Sep 17 00:00:00 2001 From: "stefan@epy" Date: Mon, 5 Nov 2012 01:35:25 +0100 Subject: Warn if filenames cannot be added to the filelist. --HG-- branch : distribute extra : rebase_source : 9fdc3c28b097e191db384cd81319c7a4edccf52b --- setuptools/tests/test_sdist.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index cb601d8c..a9d5d6e5 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -262,6 +262,7 @@ class TestSdistTest(unittest.TestCase): open(filename, 'w').close() # Re-read manifest + cmd.filelist.files = [] quiet() try: cmd.read_manifest() @@ -301,6 +302,7 @@ class TestSdistTest(unittest.TestCase): open(filename, 'w').close() # Re-read manifest + cmd.filelist.files = [] quiet() try: try: -- 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/test_sdist.py') 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 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/test_sdist.py') 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 From bf06ab669aacba63dfe4ee8adb5f50b72387c0bd Mon Sep 17 00:00:00 2001 From: Erik Bray Date: Wed, 5 Sep 2012 19:01:58 -0400 Subject: adds a test for pr #4 --HG-- branch : distribute extra : rebase_source : 347b39fb279b7168490a2c62562b4223b6c419e2 --- setuptools/tests/test_sdist.py | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 setuptools/tests/test_sdist.py (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py new file mode 100644 index 00000000..8d9ed922 --- /dev/null +++ b/setuptools/tests/test_sdist.py @@ -0,0 +1,79 @@ +"""sdist tests""" + + +import os +import shutil +import sys +import tempfile +import unittest +from StringIO import StringIO + + +from setuptools.command.sdist import sdist +from setuptools.dist import Distribution + + +SETUP_ATTRS = { + 'name': 'sdist_test', + 'version': '0.0', + 'packages': ['sdist_test'], + 'package_data': {'sdist_test': ['*.txt']} +} + + +SETUP_PY = """\ +from setuptools import setup + +setup(**%r) +""" % SETUP_ATTRS + + +class TestSdistTest(unittest.TestCase): + def setUp(self): + self.temp_dir = tempfile.mkdtemp() + f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') + f.write(SETUP_PY) + f.close() + # Set up the rest of the test package + test_pkg = os.path.join(self.temp_dir, 'sdist_test') + os.mkdir(test_pkg) + # *.rst was not included in package_data, so c.rst should not be + # automatically added to the manifest when not under version control + for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']: + # Just touch the files; their contents are irrelevant + open(os.path.join(test_pkg, fname), 'w').close() + + self.old_cwd = os.getcwd() + os.chdir(self.temp_dir) + + def tearDown(self): + os.chdir(self.old_cwd) + shutil.rmtree(self.temp_dir) + + def test_package_data_in_sdist(self): + """Regression test for pull request #4: ensures that files listed in + package_data are included in the manifest even if they're not added to + version control. + """ + + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # squelch output + old_stdout = sys.stdout + old_stderr = sys.stderr + sys.stdout = StringIO() + sys.stderr = StringIO() + try: + cmd.run() + finally: + sys.stdout = old_stdout + sys.stderr = old_stderr + + manifest = cmd.filelist.files + + self.assert_(os.path.join('sdist_test', 'a.txt') in manifest) + self.assert_(os.path.join('sdist_test', 'b.txt') in manifest) + self.assert_(os.path.join('sdist_test', 'c.rst') not in manifest) -- cgit v1.2.1 From 6851d4e38e1e4e5a2bbbf2556523fd19675cdbf7 Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Mon, 8 Oct 2012 19:48:19 +0200 Subject: Make sure the manifest never contains decomposed UTF-8. --HG-- branch : distribute extra : rebase_source : 0e0fb3beac56f66f12670ec69ebfd3996d12d912 --- setuptools/tests/test_sdist.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 8d9ed922..34123545 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """sdist tests""" @@ -74,6 +75,36 @@ class TestSdistTest(unittest.TestCase): manifest = cmd.filelist.files - self.assert_(os.path.join('sdist_test', 'a.txt') in manifest) - self.assert_(os.path.join('sdist_test', 'b.txt') in manifest) - self.assert_(os.path.join('sdist_test', 'c.rst') not in manifest) + self.assertTrue(os.path.join('sdist_test', 'a.txt') in manifest) + self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest) + self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest) + + def test_filelist_is_fully_composed(self): + # Test for #303. Requires HFS Plus to fail. + + # Add file with non-ASCII filename + filename = os.path.join('sdist_test', 'smörbröd.py') + open(filename, 'w').close() + + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # squelch output + old_stdout = sys.stdout + old_stderr = sys.stderr + sys.stdout = StringIO() + sys.stderr = StringIO() + try: + cmd.run() + finally: + sys.stdout = old_stdout + sys.stderr = old_stderr + + self.assertTrue(filename in cmd.filelist.files) + + +def test_suite(): + return unittest.defaultTestLoader.loadTestsFromName(__name__) + -- cgit v1.2.1 From d76ec4bfdf2fe9a2bced5ca2a3610831020453c6 Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Mon, 8 Oct 2012 19:52:32 +0200 Subject: Read and write manifest in UTF-8 under Python 3. Fixes #303. --HG-- branch : distribute extra : rebase_source : 609c654effd2711aa803f6a0e84013294026608f --- setuptools/tests/test_sdist.py | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 34123545..7e2f0a49 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -104,6 +104,66 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(filename in cmd.filelist.files) + def test_manifest_is_written_in_utf8(self): + # Test for #303. + + # Add file with non-ASCII filename + filename = os.path.join('sdist_test', 'smörbröd.py') + open(filename, 'w').close() + + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # squelch output + old_stdout = sys.stdout + old_stderr = sys.stderr + sys.stdout = StringIO() + sys.stderr = StringIO() + try: + cmd.run() + finally: + sys.stdout = old_stdout + sys.stderr = old_stderr + + manifest = open(os.path.join('sdist_test.egg-info', 'SOURCES.txt'), 'rbU') + contents = manifest.read() + manifest.close() + self.assertTrue(len(contents)) + + # This must not fail: + contents.decode('UTF-8') + + def test_manifest_is_read_in_utf8(self): + # Test for #303. + + # Add file with non-ASCII filename + filename = os.path.join('sdist_test', 'smörbröd.py') + open(filename, 'w').close() + + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # squelch output + old_stdout = sys.stdout + old_stderr = sys.stderr + sys.stdout = StringIO() + sys.stderr = StringIO() + try: + cmd.run() + finally: + sys.stdout = old_stdout + sys.stderr = old_stderr + + cmd.filelist.files = [] + cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + cmd.read_manifest() + + self.assertTrue(filename in cmd.filelist.files) + def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) -- cgit v1.2.1 From ac3ba239c54965e464e6047fd872f02ca1c0cb99 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Wed, 10 Oct 2012 09:39:21 +0100 Subject: Post-merge fixes for Python 3. --HG-- branch : distribute extra : source : 6b9041dea7b9197f6ea1fb993d7a05dd4f7c580d --- setuptools/tests/test_sdist.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 7e2f0a49..49007c3d 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -7,9 +7,8 @@ import shutil import sys import tempfile import unittest -from StringIO import StringIO - +from setuptools.compat import StringIO from setuptools.command.sdist import sdist from setuptools.dist import Distribution -- cgit v1.2.1 From a65b6ea00662c72fff9a887b1313c439e32a9219 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 11 Apr 2013 18:04:06 -0700 Subject: Skip test when file system encoding is not suitable. Fixes #55 and Distribute #363. --- setuptools/tests/test_sdist.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 438f7ced..19f6d4cd 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """sdist tests""" - +import locale import os import shutil import sys @@ -10,6 +10,7 @@ import unittest import unicodedata from setuptools.compat import StringIO, unicode +from setuptools.tests.py26compat import skipIf from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution @@ -318,6 +319,8 @@ class TestSdistTest(unittest.TestCase): filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) + @skipIf(sys.version_info >= (3,) and locale.getpreferredencoding() != 'UTF-8', + 'Unittest fails if locale is not utf-8 but the manifests is recorded correctly') def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From 67f9020e66d82dbf0b0ada5772a960ecc054d850 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 18 Jun 2013 14:18:30 -0500 Subject: Remove unused import --HG-- branch : distribute --- setuptools/tests/test_sdist.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index ececa765..f48decf6 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,7 +9,7 @@ import tempfile import unittest import unicodedata -from setuptools.compat import StringIO, urllib +from setuptools.compat import StringIO from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution @@ -337,7 +337,7 @@ class TestSdistTest(unittest.TestCase): if sys.version_info >= (3,): fs_enc = sys.getfilesystemencoding() - if sys.platform == 'win32': + if sys.platform == 'win32': if fs_enc == 'cp1252': # Python 3 mangles the UTF-8 filename filename = filename.decode('cp1252') @@ -372,14 +372,14 @@ class TestSdistTest(unittest.TestCase): if sys.version_info >= (3,): #not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': - # Latin-1 is similar to Windows-1252 however + # 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: filename = filename.decode('latin-1') - + self.assertTrue(filename in cmd.filelist.files) else: # The Latin-1 filename should have been skipped -- cgit v1.2.1 From b827baba9c89188f92579fe943da4f0dadde9fda Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 17 Jun 2013 08:23:32 -0500 Subject: Update exceptions for Python 3 compatibility --HG-- branch : distribute extra : rebase_source : 354795c0a0b8a864583f2549ce869e719be265d2 --- setuptools/tests/test_sdist.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f48decf6..1682989a 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -147,7 +147,8 @@ class TestSdistTest(unittest.TestCase): # The manifest should be UTF-8 encoded try: u_contents = contents.decode('UTF-8') - except UnicodeDecodeError, e: + except UnicodeDecodeError: + e = sys.exc_info()[1] self.fail(e) # The manifest should contain the UTF-8 filename @@ -188,7 +189,8 @@ class TestSdistTest(unittest.TestCase): # The manifest should be UTF-8 encoded try: contents.decode('UTF-8') - except UnicodeDecodeError, e: + except UnicodeDecodeError: + e = sys.exc_info()[1] self.fail(e) # The manifest should contain the UTF-8 filename @@ -226,7 +228,8 @@ class TestSdistTest(unittest.TestCase): # The manifest should be UTF-8 encoded try: contents.decode('UTF-8') - except UnicodeDecodeError, e: + except UnicodeDecodeError: + e = sys.exc_info()[1] self.fail(e) # The Latin-1 filename should have been skipped @@ -305,7 +308,8 @@ class TestSdistTest(unittest.TestCase): try: try: cmd.read_manifest() - except UnicodeDecodeError, e: + except UnicodeDecodeError: + e = sys.exc_info()[1] self.fail(e) finally: unquiet() -- cgit v1.2.1 From 4d2396983ae8db3429a4e1a96f6112ef0c659422 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 17 Jun 2013 10:38:20 -0500 Subject: Use unicode from compat module --HG-- branch : distribute extra : rebase_source : c4dd03dba58146eed2f620cd6d6b7ab52ee9d109 extra : histedit_source : 02c194ea1c97e8aea64fd23d77efc1bade185c0a --- setuptools/tests/test_sdist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 1682989a..438f7ced 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,7 +9,7 @@ import tempfile import unittest import unicodedata -from setuptools.compat import StringIO +from setuptools.compat import StringIO, unicode from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution @@ -55,7 +55,7 @@ def b(s, encoding='utf-8'): # Convert to POSIX path def posix(path): - if sys.version_info >= (3,) and not isinstance(path, unicode): + if sys.version_info >= (3,) and not isinstance(path, str): return path.replace(os.sep.encode('ascii'), b('/')) else: return path.replace(os.sep, '/') -- cgit v1.2.1 From b4ba33898f4d67af70319a0bb64edca72fc3ecee Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 20 Jul 2013 17:45:04 -0500 Subject: Additional Tests, Various fixes, and encoding dealings --HG-- extra : rebase_source : 2734e79e08e194923eab8c70f92cb77bce7daccf --- setuptools/tests/test_sdist.py | 64 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 438f7ced..8d6aff19 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -8,12 +8,14 @@ import sys import tempfile import unittest import unicodedata +from setuptools.tests import environment from setuptools.compat import StringIO, unicode -from setuptools.command.sdist import sdist +from setuptools.command.sdist import sdist, walk_revctrl from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution - +from setuptools import svn_utils +from setuptools.svn_utils import fsencode SETUP_ATTRS = { 'name': 'sdist_test', @@ -395,6 +397,64 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(filename in cmd.filelist.files) +class TestSvn(environment.ZippedEnvironment): + + def setUp(self): + version = svn_utils.SvnInfo.get_svn_version() + self.base_version = tuple([int(x) for x in version.split('.')][:2]) + + if not self.base_version: + raise ValueError('No SVN tools installed') + elif self.base_version < (1,3): + raise ValueError('Insufficient SVN Version %s' % version) + elif self.base_version >= (1,9): + #trying the latest version + self.base_version = (1,8) + + self.dataname = "svn%i%i_example" % self.base_version + self.datafile = os.path.join('setuptools', 'tests', + 'svn_data', self.dataname + ".zip") + super(TestSvn, self).setUp() + + def test_walksvn(self): + if self.base_version >= (1,6): + folder2 = 'third party2' + folder3 = 'third party3' + else: + folder2 = 'third_party2' + folder3 = 'third_party3' + + #TODO is this right + expected = set([ + os.path.join('a file'), + os.path.join(folder2, 'Changes.txt'), + os.path.join(folder2, 'MD5SUMS'), + os.path.join(folder2, 'README.txt'), + os.path.join(folder3, 'Changes.txt'), + os.path.join(folder3, 'MD5SUMS'), + os.path.join(folder3, 'README.txt'), + os.path.join(folder3, 'TODO.txt'), + os.path.join(folder3, 'fin'), + os.path.join('third_party', 'README.txt'), + os.path.join('folder', folder2, 'Changes.txt'), + os.path.join('folder', folder2, 'MD5SUMS'), + os.path.join('folder', folder2, 'WatashiNiYomimasu.txt'), + os.path.join( 'folder', folder3, 'Changes.txt'), + os.path.join('folder', folder3, 'fin'), + os.path.join('folder', folder3, 'MD5SUMS'), + os.path.join('folder', folder3, 'oops'), + os.path.join('folder', folder3, 'WatashiNiYomimasu.txt'), + os.path.join('folder', folder3, 'ZuMachen.txt'), + os.path.join('folder', 'third_party', 'WatashiNiYomimasu.txt'), + os.path.join('folder', 'lalala.txt'), + os.path.join('folder', 'quest.txt'), + #The example will have a deleted file (or should) but shouldn't return it + ]) + expected = set(fsencode(x) for x in expected) + self.assertEqual(set(x for x in walk_revctrl()), expected) + + + def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) -- cgit v1.2.1 From d0526b9ca5baad5b23180d32cf8b387bfcea0eaa Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Thu, 7 Nov 2013 21:13:10 -0600 Subject: Fixed the various tests that depended on fsencode. Added a test to run egg_info on a dummy SVN package. Added a second similar test that invokes the legacy code. --- setuptools/tests/test_sdist.py | 82 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 65a9f0b3..716893dc 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """sdist tests""" +from __future__ import with_statement import locale import os import shutil @@ -8,6 +9,7 @@ import sys import tempfile import unittest import unicodedata +import re from setuptools.tests import environment from setuptools.compat import StringIO, unicode @@ -16,7 +18,6 @@ from setuptools.command.sdist import sdist, walk_revctrl from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution from setuptools import svn_utils -from setuptools.svn_utils import fsencode SETUP_ATTRS = { 'name': 'sdist_test', @@ -400,6 +401,83 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(filename in cmd.filelist.files) +def soruce_test(self): + code, data = svn_utils._run_command([sys.executable, "setup.py", "egg_info"], stream=1) + + if code: + raise AssertionError(data) + + sources = os.path.join('dummy.egg-info', 'SOURCES.txt') + contents = """CHANGES.txt +CONTRIBUTORS.txt +HISTORY.txt +LICENSE +MANIFEST.in +README.txt +setup.py +dummy/__init__.py +dummy/test.txt +dummy.egg-info/PKG-INFO +dummy.egg-info/SOURCES.txt +dummy.egg-info/dependency_links.txt +dummy.egg-info/top_level.txt""" + + with open(sources, 'r') as infile: + read_contents = infile.read() + + self.assertEqual(contents, read_contents) + + +class TestSvnDummy(environment.ZippedEnvironment): + + def setUp(self): + version = svn_utils.SvnInfo.get_svn_version() + self.base_version = tuple([int(x) for x in version.split('.')][:2]) + + if not self.base_version: + raise ValueError('No SVN tools installed') + elif self.base_version < (1,3): + raise ValueError('Insufficient SVN Version %s' % version) + elif self.base_version >= (1,9): + #trying the latest version + self.base_version = (1,8) + + self.dataname = "dummy%i%i" % self.base_version + self.datafile = os.path.join('setuptools', 'tests', + 'svn_data', self.dataname + ".zip") + super(TestSvnDummy, self).setUp() + + def test_sources(self): + soruce_test(self) + + +class TestSvnDummyLegacy(environment.ZippedEnvironment): + + def setUp(self): + self.base_version = (1,6) + self.path_variable = None + for env in os.environ: + if env.lower() == 'path': + self.path_variable = env + self.old_path = os.environ[self.path_variable] + os.environ[self.path_variable] = '' + + if self.path_variable is None: + self.skipTest('Cannot figure out how to modify path') + + self.dataname = "dummy%i%i" % self.base_version + self.datafile = os.path.join('setuptools', 'tests', + 'svn_data', self.dataname + ".zip") + super(TestSvnDummyLegacy, self).setUp() + + def tearDown(self): + os.environ[self.path_variable] = self.old_path + super(TestSvnDummyLegacy, self).tearDown() + + def test_sources(self): + soruce_test(self) + + class TestSvn(environment.ZippedEnvironment): def setUp(self): @@ -453,11 +531,9 @@ class TestSvn(environment.ZippedEnvironment): os.path.join('folder', 'quest.txt'), #The example will have a deleted file (or should) but shouldn't return it ]) - expected = set(fsencode(x) for x in expected) self.assertEqual(set(x for x in walk_revctrl()), expected) - def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) -- cgit v1.2.1 From 76423012b5b51691dd059b1276351099e52c787e Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Mon, 11 Nov 2013 17:07:52 -0600 Subject: For .svn legacy fallback, look for the files in the .svn not the directory. (Fixed unexpected deprecation warning from prombredanne) Also removed the warning from fallback, only a deprecation warning is issued. Environment.py whitespacing Created a specialized command executor for tests in Environment.py Legacy Test in test_egg_info now supresses the deprecation warning. PythonPath is now explicitly controlled to allow setup.py test on clean python installations. *Fixes Issue #101* Moved some dummy svn tests from test_sdist to test_egg_info since they are egg_info tests. Downgraded a with statement in a test since we haven't offically dropped 2.4 support, however, maybe it is time. Added a test case to ensure no extranuous output on sdist with a simple dummy package without rev ctrl. --- setuptools/tests/test_sdist.py | 149 +++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 79 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 716893dc..b42dcc57 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """sdist tests""" -from __future__ import with_statement import locale import os import shutil @@ -401,81 +400,73 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(filename in cmd.filelist.files) -def soruce_test(self): - code, data = svn_utils._run_command([sys.executable, "setup.py", "egg_info"], stream=1) - - if code: - raise AssertionError(data) - - sources = os.path.join('dummy.egg-info', 'SOURCES.txt') - contents = """CHANGES.txt -CONTRIBUTORS.txt -HISTORY.txt -LICENSE -MANIFEST.in -README.txt -setup.py -dummy/__init__.py -dummy/test.txt -dummy.egg-info/PKG-INFO -dummy.egg-info/SOURCES.txt -dummy.egg-info/dependency_links.txt -dummy.egg-info/top_level.txt""" - - with open(sources, 'r') as infile: - read_contents = infile.read() - - self.assertEqual(contents, read_contents) - - -class TestSvnDummy(environment.ZippedEnvironment): - - def setUp(self): - version = svn_utils.SvnInfo.get_svn_version() - self.base_version = tuple([int(x) for x in version.split('.')][:2]) - - if not self.base_version: - raise ValueError('No SVN tools installed') - elif self.base_version < (1,3): - raise ValueError('Insufficient SVN Version %s' % version) - elif self.base_version >= (1,9): - #trying the latest version - self.base_version = (1,8) - - self.dataname = "dummy%i%i" % self.base_version - self.datafile = os.path.join('setuptools', 'tests', - 'svn_data', self.dataname + ".zip") - super(TestSvnDummy, self).setUp() - - def test_sources(self): - soruce_test(self) - - -class TestSvnDummyLegacy(environment.ZippedEnvironment): +class TestDummyOutput(environment.ZippedEnvironment): def setUp(self): - self.base_version = (1,6) - self.path_variable = None - for env in os.environ: - if env.lower() == 'path': - self.path_variable = env - self.old_path = os.environ[self.path_variable] - os.environ[self.path_variable] = '' - - if self.path_variable is None: - self.skipTest('Cannot figure out how to modify path') - - self.dataname = "dummy%i%i" % self.base_version self.datafile = os.path.join('setuptools', 'tests', - 'svn_data', self.dataname + ".zip") - super(TestSvnDummyLegacy, self).setUp() - - def tearDown(self): - os.environ[self.path_variable] = self.old_path - super(TestSvnDummyLegacy, self).tearDown() + 'svn_data', "dummy.zip") + self.dataname = "dummy" + super(TestDummyOutput, self).setUp() + + def _run(self): + code, data = environment.run_setup_py(["sdist"], + pypath=self.old_cwd, + data_stream=0) + if code: + info = "DIR: " + os.path.abspath('.') + info += "\n SDIST RETURNED: %i\n\n" % code + info += data + raise AssertionError(info) + + datalines = data.splitlines() + + possible = ( + "running sdist", + "running egg_info", + "creating dummy\.egg-info", + "writing dummy\.egg-info", + "writing top-level names to dummy\.egg-info", + "writing dependency_links to dummy\.egg-info", + "writing manifest file 'dummy\.egg-info", + "reading manifest file 'dummy\.egg-info", + "reading manifest template 'MANIFEST\.in'", + "writing manifest file 'dummy\.egg-info", + "creating dummy-0.1.1", + "making hard links in dummy-0\.1\.1", + "copying files to dummy-0\.1\.1", + "copying \S+ -> dummy-0\.1\.1", + "copying dummy", + "copying dummy\.egg-info", + "hard linking \S+ -> dummy-0\.1\.1", + "hard linking dummy", + "hard linking dummy\.egg-info", + "Writing dummy-0\.1\.1", + "creating dist", + "creating 'dist", + "Creating tar archive", + "running check", + "adding 'dummy-0\.1\.1", + "tar .+ dist/dummy-0\.1\.1\.tar dummy-0\.1\.1", + "gzip .+ dist/dummy-0\.1\.1\.tar", + "removing 'dummy-0\.1\.1' \\(and everything under it\\)", + ) + + print(" DIR: " + os.path.abspath('.')) + for line in datalines: + found = False + for pattern in possible: + if re.match(pattern, line): + print(" READ: " + line) + found = True + break + if not found: + raise AssertionError("Unexpexected: %s\n-in-\n%s" + % (line, data)) + + return data def test_sources(self): - soruce_test(self) + self._run() class TestSvn(environment.ZippedEnvironment): @@ -486,11 +477,11 @@ class TestSvn(environment.ZippedEnvironment): if not self.base_version: raise ValueError('No SVN tools installed') - elif self.base_version < (1,3): + elif self.base_version < (1, 3): raise ValueError('Insufficient SVN Version %s' % version) - elif self.base_version >= (1,9): + elif self.base_version >= (1, 9): #trying the latest version - self.base_version = (1,8) + self.base_version = (1, 8) self.dataname = "svn%i%i_example" % self.base_version self.datafile = os.path.join('setuptools', 'tests', @@ -498,7 +489,7 @@ class TestSvn(environment.ZippedEnvironment): super(TestSvn, self).setUp() def test_walksvn(self): - if self.base_version >= (1,6): + if self.base_version >= (1, 6): folder2 = 'third party2' folder3 = 'third party3' else: @@ -520,7 +511,7 @@ class TestSvn(environment.ZippedEnvironment): os.path.join('folder', folder2, 'Changes.txt'), os.path.join('folder', folder2, 'MD5SUMS'), os.path.join('folder', folder2, 'WatashiNiYomimasu.txt'), - os.path.join( 'folder', folder3, 'Changes.txt'), + os.path.join('folder', folder3, 'Changes.txt'), os.path.join('folder', folder3, 'fin'), os.path.join('folder', folder3, 'MD5SUMS'), os.path.join('folder', folder3, 'oops'), @@ -529,11 +520,11 @@ class TestSvn(environment.ZippedEnvironment): os.path.join('folder', 'third_party', 'WatashiNiYomimasu.txt'), os.path.join('folder', 'lalala.txt'), os.path.join('folder', 'quest.txt'), - #The example will have a deleted file (or should) but shouldn't return it - ]) + # The example will have a deleted file + # (or should) but shouldn't return it + ]) self.assertEqual(set(x for x in walk_revctrl()), expected) def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) - -- cgit v1.2.1 From 8bbdac7d065e408f3f320e4523274e10e1c469fc Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 7 Dec 2013 00:13:19 -0600 Subject: Modified setuptools.test.environment.ZipEnvironment to not choke on a bypassed setUp. test_egg_info, test_sdist, and test_svn all had tests that needed to be bypassed when svn was not present. tests.py26compat contains a SkipIf decorator for skipping. This worked after ironing a few wrinkles. The conditions is evaluated and stored in test_svn._svn_check. --- setuptools/tests/test_sdist.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index b42dcc57..71d10757 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,7 +9,8 @@ import tempfile import unittest import unicodedata import re -from setuptools.tests import environment +from setuptools.tests import environment, test_svn +from setuptools.tests.py26compat import skipIf from setuptools.compat import StringIO, unicode from setuptools.tests.py26compat import skipIf @@ -473,6 +474,9 @@ class TestSvn(environment.ZippedEnvironment): def setUp(self): version = svn_utils.SvnInfo.get_svn_version() + if not version: # None or Empty + return + self.base_version = tuple([int(x) for x in version.split('.')][:2]) if not self.base_version: @@ -488,6 +492,7 @@ class TestSvn(environment.ZippedEnvironment): 'svn_data', self.dataname + ".zip") super(TestSvn, self).setUp() + @skipIf(not test_svn._svn_check, "No SVN to text, in the first place") def test_walksvn(self): if self.base_version >= (1, 6): folder2 = 'third party2' -- cgit v1.2.1 From 836f7004959909767640822caee8ad3af26a938d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 15 May 2014 23:39:17 -0400 Subject: Extend docstring for test_write_manifest_skips_non_utf8_filenames --- setuptools/tests/test_sdist.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 71d10757..10042a44 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -204,7 +204,12 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(u_filename in mm.filelist.files) def test_write_manifest_skips_non_utf8_filenames(self): - # Test for #303. + """ + Files that cannot be encoded to UTF-8 (specifically, those that + weren't originally successfully decoded and have surrogate + escapes) should be omitted from the manifest. + See https://bitbucket.org/tarek/distribute/issue/303 for history. + """ dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' mm = manifest_maker(dist) -- cgit v1.2.1 From 2c63bb2e7c3dd6e27836630cec051e9d10891723 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 15 May 2014 23:40:37 -0400 Subject: Test should use the same high-level interface for appending filenames as the object itself will use when building the filelist. Ideally, FileList wouldn't expose this attribute at all. --- setuptools/tests/test_sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 10042a44..ec940d00 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -224,7 +224,7 @@ class TestSdistTest(unittest.TestCase): try: mm.run() u_filename = filename.decode('utf-8', 'surrogateescape') - mm.filelist.files.append(u_filename) + mm.filelist.append(u_filename) # Re-write manifest mm.write_manifest() finally: -- cgit v1.2.1 From 3f4f5b3b4432203163258083f9e29b75d2aaedc4 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 17 May 2014 02:30:28 -0500 Subject: Merge in test changes from previous try --HG-- extra : rebase_source : 0dba3308549833dc7fc5b242e8ae3a4ec9f3c119 --- setuptools/tests/test_sdist.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index ec940d00..ada86189 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -156,10 +156,11 @@ class TestSdistTest(unittest.TestCase): self.fail(e) # The manifest should contain the UTF-8 filename - if sys.version_info >= (3,): - self.assertTrue(posix(filename) in u_contents) - else: - self.assertTrue(posix(filename) in contents) + if sys.version_info < (3,): + fs_enc = sys.getfilesystemencoding() + filename = filename.decode(fs_enc) + + self.assertTrue(posix(filename) in u_contents) # Python 3 only if sys.version_info >= (3,): @@ -401,10 +402,17 @@ class TestSdistTest(unittest.TestCase): 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. - self.assertTrue(filename in cmd.filelist.files) - + # Under Python 2 there seems to be no decoded string in the + # filelist. However, due to decode and encoding of the + # file name to get utf-8 Manifest the latin1 maybe excluded + try: + # fs_enc should match how one is expect the decoding to + # be proformed for the manifest output. + fs_enc = sys.getfilesystemencoding() + filename.decode(fs_enc) + self.assertTrue(filename in cmd.filelist.files) + except UnicodeDecodeError: + self.assertFalse(filename in cmd.filelist.files) class TestDummyOutput(environment.ZippedEnvironment): -- cgit v1.2.1 From 8567ca65adbf927a0af5c9b7314688dfbc46ab66 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 May 2014 12:25:31 -0400 Subject: Use PY3 and PY2 throughout --- setuptools/tests/test_sdist.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index ada86189..231b40d0 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -12,7 +12,7 @@ import re from setuptools.tests import environment, test_svn from setuptools.tests.py26compat import skipIf -from setuptools.compat import StringIO, unicode +from setuptools.compat import StringIO, unicode, PY3, PY2 from setuptools.tests.py26compat import skipIf from setuptools.command.sdist import sdist, walk_revctrl from setuptools.command.egg_info import manifest_maker @@ -34,7 +34,7 @@ setup(**%r) """ % SETUP_ATTRS -if sys.version_info >= (3,): +if PY3: LATIN1_FILENAME = 'smörbröd.py'.encode('latin-1') else: LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py' @@ -52,14 +52,14 @@ def unquiet(): # Fake byte literals for Python <= 2.5 def b(s, encoding='utf-8'): - if sys.version_info >= (3,): + if PY3: return s.encode(encoding) return s # Convert to POSIX path def posix(path): - if sys.version_info >= (3,) and not isinstance(path, str): + if PY3 and not isinstance(path, str): return path.replace(os.sep.encode('ascii'), b('/')) else: return path.replace(os.sep, '/') @@ -156,14 +156,14 @@ class TestSdistTest(unittest.TestCase): self.fail(e) # The manifest should contain the UTF-8 filename - if sys.version_info < (3,): + if PY2: fs_enc = sys.getfilesystemencoding() filename = filename.decode(fs_enc) self.assertTrue(posix(filename) in u_contents) # Python 3 only - if sys.version_info >= (3,): + if PY3: def test_write_manifest_allows_utf8_filenames(self): # Test for #303. @@ -281,12 +281,12 @@ class TestSdistTest(unittest.TestCase): unquiet() # The filelist should contain the UTF-8 filename - if sys.version_info >= (3,): + if PY3: filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files) # Python 3 only - if sys.version_info >= (3,): + if PY3: def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. @@ -328,7 +328,7 @@ class TestSdistTest(unittest.TestCase): filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) - @skipIf(sys.version_info >= (3,) and locale.getpreferredencoding() != 'UTF-8', + @skipIf(PY3 and locale.getpreferredencoding() != 'UTF-8', 'Unittest fails if locale is not utf-8 but the manifests is recorded correctly') def test_sdist_with_utf8_encoded_filename(self): # Test for #303. @@ -350,7 +350,7 @@ class TestSdistTest(unittest.TestCase): if sys.platform == 'darwin': filename = decompose(filename) - if sys.version_info >= (3,): + if PY3: fs_enc = sys.getfilesystemencoding() if sys.platform == 'win32': @@ -385,7 +385,7 @@ class TestSdistTest(unittest.TestCase): finally: unquiet() - if sys.version_info >= (3,): + if PY3: #not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however @@ -408,7 +408,7 @@ class TestSdistTest(unittest.TestCase): try: # fs_enc should match how one is expect the decoding to # be proformed for the manifest output. - fs_enc = sys.getfilesystemencoding() + fs_enc = sys.getfilesystemencoding() filename.decode(fs_enc) self.assertTrue(filename in cmd.filelist.files) except UnicodeDecodeError: -- cgit v1.2.1 From cac29acff1a8b95f3d11f8bca8015d5e7c67036a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 May 2014 12:38:16 -0400 Subject: Convert quiet to a context manager, so its comment is no longer complaining and to simplify the code. --- setuptools/tests/test_sdist.py | 61 +++++++++++------------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 231b40d0..93b8c297 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,6 +9,7 @@ import tempfile import unittest import unicodedata import re +import contextlib from setuptools.tests import environment, test_svn from setuptools.tests.py26compat import skipIf @@ -41,13 +42,14 @@ else: # Cannot use context manager because of Python 2.4 +@contextlib.contextmanager def quiet(): - global old_stdout, old_stderr old_stdout, old_stderr = sys.stdout, sys.stderr sys.stdout, sys.stderr = StringIO(), StringIO() - -def unquiet(): - sys.stdout, sys.stderr = old_stdout, old_stderr + try: + yield + finally: + sys.stdout, sys.stderr = old_stdout, old_stderr # Fake byte literals for Python <= 2.5 @@ -112,12 +114,8 @@ class TestSdistTest(unittest.TestCase): cmd = sdist(dist) cmd.ensure_finalized() - # squelch output - quiet() - try: + with quiet(): cmd.run() - finally: - unquiet() manifest = cmd.filelist.files self.assertTrue(os.path.join('sdist_test', 'a.txt') in manifest) @@ -136,13 +134,10 @@ class TestSdistTest(unittest.TestCase): filename = os.path.join('sdist_test', 'smörbröd.py') # Add UTF-8 filename and write manifest - quiet() - try: + with quiet(): mm.run() mm.filelist.files.append(filename) mm.write_manifest() - finally: - unquiet() manifest = open(mm.manifest, 'rbU') contents = manifest.read() @@ -177,15 +172,12 @@ class TestSdistTest(unittest.TestCase): filename = os.path.join(b('sdist_test'), b('smörbröd.py')) # Add filename and write manifest - quiet() - try: + with quiet(): mm.run() u_filename = filename.decode('utf-8') mm.filelist.files.append(u_filename) # Re-write manifest mm.write_manifest() - finally: - unquiet() manifest = open(mm.manifest, 'rbU') contents = manifest.read() @@ -221,15 +213,12 @@ class TestSdistTest(unittest.TestCase): filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) # Add filename with surrogates and write manifest - quiet() - try: + with quiet(): mm.run() u_filename = filename.decode('utf-8', 'surrogateescape') mm.filelist.append(u_filename) # Re-write manifest mm.write_manifest() - finally: - unquiet() manifest = open(mm.manifest, 'rbU') contents = manifest.read() @@ -256,11 +245,8 @@ class TestSdistTest(unittest.TestCase): cmd.ensure_finalized() # Create manifest - quiet() - try: + with quiet(): cmd.run() - finally: - unquiet() # Add UTF-8 filename to manifest filename = os.path.join(b('sdist_test'), b('smörbröd.py')) @@ -274,11 +260,8 @@ class TestSdistTest(unittest.TestCase): # Re-read manifest cmd.filelist.files = [] - quiet() - try: + with quiet(): cmd.read_manifest() - finally: - unquiet() # The filelist should contain the UTF-8 filename if PY3: @@ -296,11 +279,8 @@ class TestSdistTest(unittest.TestCase): cmd.ensure_finalized() # Create manifest - quiet() - try: + with quiet(): cmd.run() - finally: - unquiet() # Add Latin-1 filename to manifest filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) @@ -314,15 +294,12 @@ class TestSdistTest(unittest.TestCase): # Re-read manifest cmd.filelist.files = [] - quiet() - try: + with quiet(): try: cmd.read_manifest() except UnicodeDecodeError: e = sys.exc_info()[1] self.fail(e) - finally: - unquiet() # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') @@ -341,11 +318,8 @@ class TestSdistTest(unittest.TestCase): filename = os.path.join(b('sdist_test'), b('smörbröd.py')) open(filename, 'w').close() - quiet() - try: + with quiet(): cmd.run() - finally: - unquiet() if sys.platform == 'darwin': filename = decompose(filename) @@ -379,11 +353,8 @@ class TestSdistTest(unittest.TestCase): open(filename, 'w').close() self.assertTrue(os.path.isfile(filename)) - quiet() - try: + with quiet(): cmd.run() - finally: - unquiet() if PY3: #not all windows systems have a default FS encoding of cp1252 -- cgit v1.2.1 From c5d760b060efa63e8de92bc5d1b1e56700ff16e6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 May 2014 12:38:54 -0400 Subject: Remove unused import --- setuptools/tests/test_sdist.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 93b8c297..d2188035 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -14,7 +14,6 @@ from setuptools.tests import environment, test_svn from setuptools.tests.py26compat import skipIf from setuptools.compat import StringIO, unicode, PY3, PY2 -from setuptools.tests.py26compat import skipIf from setuptools.command.sdist import sdist, walk_revctrl from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution -- cgit v1.2.1 From 999a55b7526f857af17d3c85579c7d9380c5baa8 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 17 May 2014 11:15:44 -0500 Subject: est_manifest_is_written_with_utf8_encoding should use the filelist's append, NOT filelist.files.append --HG-- extra : rebase_source : cdf0df0a11b96a60c29c10483579e6e043a7fcd1 --- setuptools/tests/test_sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index d2188035..9d2cc54f 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -135,7 +135,7 @@ class TestSdistTest(unittest.TestCase): # Add UTF-8 filename and write manifest with quiet(): mm.run() - mm.filelist.files.append(filename) + mm.filelist.append(filename) mm.write_manifest() manifest = open(mm.manifest, 'rbU') -- cgit v1.2.1 From 3e5d3adf96b78fa10f1d1172b4dff32e4366a0ee Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sat, 17 May 2014 11:40:08 -0500 Subject: Must create files for tests, else they are remoed from manifests --HG-- extra : rebase_source : c22b55cde69bbf7fc6a075bcd8797017797c6225 --- setuptools/tests/test_sdist.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 9d2cc54f..97ac5156 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -75,7 +75,7 @@ def decompose(path): path = unicodedata.normalize('NFD', path) path = path.encode('utf-8') except UnicodeError: - pass # Not UTF-8 + pass # Not UTF-8 return path @@ -132,6 +132,9 @@ class TestSdistTest(unittest.TestCase): # UTF-8 filename filename = os.path.join('sdist_test', 'smörbröd.py') + # Must create the file or it will get stripped. + open(filename, 'w').close() + # Add UTF-8 filename and write manifest with quiet(): mm.run() @@ -251,7 +254,7 @@ class TestSdistTest(unittest.TestCase): filename = os.path.join(b('sdist_test'), b('smörbröd.py')) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') - manifest.write(b('\n')+filename) + manifest.write(b('\n') + filename) manifest.close() # The file must exist to be included in the filelist @@ -285,7 +288,7 @@ class TestSdistTest(unittest.TestCase): filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') - manifest.write(b('\n')+filename) + manifest.write(b('\n') + filename) manifest.close() # The file must exist to be included in the filelist @@ -356,7 +359,7 @@ class TestSdistTest(unittest.TestCase): cmd.run() if PY3: - #not all windows systems have a default FS encoding of cp1252 + # 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 @@ -467,7 +470,7 @@ class TestSvn(environment.ZippedEnvironment): elif self.base_version < (1, 3): raise ValueError('Insufficient SVN Version %s' % version) elif self.base_version >= (1, 9): - #trying the latest version + # trying the latest version self.base_version = (1, 8) self.dataname = "svn%i%i_example" % self.base_version @@ -484,7 +487,7 @@ class TestSvn(environment.ZippedEnvironment): folder2 = 'third_party2' folder3 = 'third_party3' - #TODO is this right + # TODO is this right expected = set([ os.path.join('a file'), os.path.join(folder2, 'Changes.txt'), -- cgit v1.2.1 From ab8f277a286587dbfeee2e1e21a57f4744aaddd6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 May 2014 13:16:58 -0400 Subject: Must create files for tests, else they are remoed from manifests --- setuptools/tests/test_sdist.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 97ac5156..f4a492da 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -173,6 +173,9 @@ class TestSdistTest(unittest.TestCase): # UTF-8 filename filename = os.path.join(b('sdist_test'), b('smörbröd.py')) + #Must touch the file or risk removal + open(filename, "w").close() + # Add filename and write manifest with quiet(): mm.run() -- cgit v1.2.1 From f84506654ff8199b07bb4eab8b210de25eb546f2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 May 2014 13:23:20 -0400 Subject: Add whitespace for readability. --- setuptools/tests/test_sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f4a492da..5b3862e9 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -173,7 +173,7 @@ class TestSdistTest(unittest.TestCase): # UTF-8 filename filename = os.path.join(b('sdist_test'), b('smörbröd.py')) - #Must touch the file or risk removal + # Must touch the file or risk removal open(filename, "w").close() # Add filename and write manifest -- cgit v1.2.1 From b49435397a5094f94678adf3549cc8941aa469b7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Jul 2014 15:06:51 -0400 Subject: Use six for Python 2 compatibility --HG-- branch : feature/issue-229 extra : source : 7b1997ececc5772798ce33a0f8e77387cb55a977 --- setuptools/tests/test_sdist.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 5b3862e9..c78e5b0f 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -10,10 +10,11 @@ import unittest import unicodedata import re import contextlib + +import six + from setuptools.tests import environment, test_svn from setuptools.tests.py26compat import skipIf - -from setuptools.compat import StringIO, unicode, PY3, PY2 from setuptools.command.sdist import sdist, walk_revctrl from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution @@ -34,7 +35,7 @@ setup(**%r) """ % SETUP_ATTRS -if PY3: +if six.PY3: LATIN1_FILENAME = 'smörbröd.py'.encode('latin-1') else: LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py' @@ -44,7 +45,7 @@ else: @contextlib.contextmanager def quiet(): old_stdout, old_stderr = sys.stdout, sys.stderr - sys.stdout, sys.stderr = StringIO(), StringIO() + sys.stdout, sys.stderr = six.StringIO(), six.StringIO() try: yield finally: @@ -53,14 +54,14 @@ def quiet(): # Fake byte literals for Python <= 2.5 def b(s, encoding='utf-8'): - if PY3: + if six.PY3: return s.encode(encoding) return s # Convert to POSIX path def posix(path): - if PY3 and not isinstance(path, str): + if six.PY3 and not isinstance(path, str): return path.replace(os.sep.encode('ascii'), b('/')) else: return path.replace(os.sep, '/') @@ -68,7 +69,7 @@ def posix(path): # HFS Plus uses decomposed UTF-8 def decompose(path): - if isinstance(path, unicode): + if isinstance(path, six.text_type): return unicodedata.normalize('NFD', path) try: path = path.decode('utf-8') @@ -153,14 +154,14 @@ class TestSdistTest(unittest.TestCase): self.fail(e) # The manifest should contain the UTF-8 filename - if PY2: + if six.PY2: fs_enc = sys.getfilesystemencoding() filename = filename.decode(fs_enc) self.assertTrue(posix(filename) in u_contents) # Python 3 only - if PY3: + if six.PY3: def test_write_manifest_allows_utf8_filenames(self): # Test for #303. @@ -269,12 +270,12 @@ class TestSdistTest(unittest.TestCase): cmd.read_manifest() # The filelist should contain the UTF-8 filename - if PY3: + if six.PY3: filename = filename.decode('utf-8') self.assertTrue(filename in cmd.filelist.files) # Python 3 only - if PY3: + if six.PY3: def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. @@ -310,7 +311,7 @@ class TestSdistTest(unittest.TestCase): filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) - @skipIf(PY3 and locale.getpreferredencoding() != 'UTF-8', + @skipIf(six.PY3 and locale.getpreferredencoding() != 'UTF-8', 'Unittest fails if locale is not utf-8 but the manifests is recorded correctly') def test_sdist_with_utf8_encoded_filename(self): # Test for #303. @@ -329,7 +330,7 @@ class TestSdistTest(unittest.TestCase): if sys.platform == 'darwin': filename = decompose(filename) - if PY3: + if six.PY3: fs_enc = sys.getfilesystemencoding() if sys.platform == 'win32': @@ -361,7 +362,7 @@ class TestSdistTest(unittest.TestCase): with quiet(): cmd.run() - if PY3: + if six.PY3: # not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however -- cgit v1.2.1 From 4e5c7d0657a9719d2fa961c852daf0926de91ae3 Mon Sep 17 00:00:00 2001 From: Randy Syring Date: Sat, 20 Sep 2014 16:29:41 -0400 Subject: sdist command: fix case insensitivity when adding some files to filelist This should fix the problem in Bitbucket issue #100. It gives the same behavior for inclusion of default files (README*, etc.) on Windows as Linux. BACKWARDS INCOMPATABILITY: This may result in a backwards incompatible change for users on a case insensitive file system. If they were relying on some files getting included in their distribution due to setuptools defaults, and their files do not have the same case as the files being looked for in setuptools, those files will no longer be included in the package. For example, if a package had a file: readme.rst Previous to this commit, that file would have been included in the distribution as: README.rst But it will now no longer be included at all. To get the file included in the package, it can be added to the package's MANIFEST.in file: include readme.rst Files affected by this change will have a case variant of the files or patterns listed below: README README.txt README.rst setup.py (or whatever your setuptools script is named) setup.cfg test/test*.py --- setuptools/tests/test_sdist.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 5b3862e9..5f8a190f 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -86,6 +86,7 @@ class TestSdistTest(unittest.TestCase): f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') f.write(SETUP_PY) f.close() + # Set up the rest of the test package test_pkg = os.path.join(self.temp_dir, 'sdist_test') os.mkdir(test_pkg) @@ -121,6 +122,33 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest) self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest) + + def test_defaults_case_sensitivity(self): + """ + Make sure default files (README.*, etc.) are added in a case-sensitive + way to avoid problems with packages built on Windows. + """ + + open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close() + open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close() + + dist = Distribution(SETUP_ATTRS) + # the extension deliberately capitalized for this test + # to make sure the actual filename (not capitalized) gets added + # to the manifest + dist.script_name = 'setup.PY' + cmd = sdist(dist) + cmd.ensure_finalized() + + with quiet(): + cmd.run() + + # lowercase all names so we can test in a case-insensitive way to make sure the files are not included + manifest = map(lambda x: x.lower(), cmd.filelist.files) + self.assertFalse('readme.rst' in manifest, manifest) + self.assertFalse('setup.py' in manifest, manifest) + self.assertFalse('setup.cfg' in manifest, manifest) + def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From a7e5648bda737683c4ad220e61c44c1d17b73d87 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Dec 2014 18:25:45 -0500 Subject: Removed svn support from setuptools. Ref #313. --- setuptools/tests/test_sdist.py | 134 +---------------------------------------- 1 file changed, 1 insertion(+), 133 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 5f8a190f..bece76d2 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -8,16 +8,13 @@ import sys import tempfile import unittest import unicodedata -import re import contextlib -from setuptools.tests import environment, test_svn from setuptools.tests.py26compat import skipIf from setuptools.compat import StringIO, unicode, PY3, PY2 -from setuptools.command.sdist import sdist, walk_revctrl +from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution -from setuptools import svn_utils SETUP_ATTRS = { 'name': 'sdist_test', @@ -418,135 +415,6 @@ class TestSdistTest(unittest.TestCase): except UnicodeDecodeError: self.assertFalse(filename in cmd.filelist.files) -class TestDummyOutput(environment.ZippedEnvironment): - - def setUp(self): - self.datafile = os.path.join('setuptools', 'tests', - 'svn_data', "dummy.zip") - self.dataname = "dummy" - super(TestDummyOutput, self).setUp() - - def _run(self): - code, data = environment.run_setup_py(["sdist"], - pypath=self.old_cwd, - data_stream=0) - if code: - info = "DIR: " + os.path.abspath('.') - info += "\n SDIST RETURNED: %i\n\n" % code - info += data - raise AssertionError(info) - - datalines = data.splitlines() - - possible = ( - "running sdist", - "running egg_info", - "creating dummy\.egg-info", - "writing dummy\.egg-info", - "writing top-level names to dummy\.egg-info", - "writing dependency_links to dummy\.egg-info", - "writing manifest file 'dummy\.egg-info", - "reading manifest file 'dummy\.egg-info", - "reading manifest template 'MANIFEST\.in'", - "writing manifest file 'dummy\.egg-info", - "creating dummy-0.1.1", - "making hard links in dummy-0\.1\.1", - "copying files to dummy-0\.1\.1", - "copying \S+ -> dummy-0\.1\.1", - "copying dummy", - "copying dummy\.egg-info", - "hard linking \S+ -> dummy-0\.1\.1", - "hard linking dummy", - "hard linking dummy\.egg-info", - "Writing dummy-0\.1\.1", - "creating dist", - "creating 'dist", - "Creating tar archive", - "running check", - "adding 'dummy-0\.1\.1", - "tar .+ dist/dummy-0\.1\.1\.tar dummy-0\.1\.1", - "gzip .+ dist/dummy-0\.1\.1\.tar", - "removing 'dummy-0\.1\.1' \\(and everything under it\\)", - ) - - print(" DIR: " + os.path.abspath('.')) - for line in datalines: - found = False - for pattern in possible: - if re.match(pattern, line): - print(" READ: " + line) - found = True - break - if not found: - raise AssertionError("Unexpexected: %s\n-in-\n%s" - % (line, data)) - - return data - - def test_sources(self): - self._run() - - -class TestSvn(environment.ZippedEnvironment): - - def setUp(self): - version = svn_utils.SvnInfo.get_svn_version() - if not version: # None or Empty - return - - self.base_version = tuple([int(x) for x in version.split('.')][:2]) - - if not self.base_version: - raise ValueError('No SVN tools installed') - elif self.base_version < (1, 3): - raise ValueError('Insufficient SVN Version %s' % version) - elif self.base_version >= (1, 9): - # trying the latest version - self.base_version = (1, 8) - - self.dataname = "svn%i%i_example" % self.base_version - self.datafile = os.path.join('setuptools', 'tests', - 'svn_data', self.dataname + ".zip") - super(TestSvn, self).setUp() - - @skipIf(not test_svn._svn_check, "No SVN to text, in the first place") - def test_walksvn(self): - if self.base_version >= (1, 6): - folder2 = 'third party2' - folder3 = 'third party3' - else: - folder2 = 'third_party2' - folder3 = 'third_party3' - - # TODO is this right - expected = set([ - os.path.join('a file'), - os.path.join(folder2, 'Changes.txt'), - os.path.join(folder2, 'MD5SUMS'), - os.path.join(folder2, 'README.txt'), - os.path.join(folder3, 'Changes.txt'), - os.path.join(folder3, 'MD5SUMS'), - os.path.join(folder3, 'README.txt'), - os.path.join(folder3, 'TODO.txt'), - os.path.join(folder3, 'fin'), - os.path.join('third_party', 'README.txt'), - os.path.join('folder', folder2, 'Changes.txt'), - os.path.join('folder', folder2, 'MD5SUMS'), - os.path.join('folder', folder2, 'WatashiNiYomimasu.txt'), - os.path.join('folder', folder3, 'Changes.txt'), - os.path.join('folder', folder3, 'fin'), - os.path.join('folder', folder3, 'MD5SUMS'), - os.path.join('folder', folder3, 'oops'), - os.path.join('folder', folder3, 'WatashiNiYomimasu.txt'), - os.path.join('folder', folder3, 'ZuMachen.txt'), - os.path.join('folder', 'third_party', 'WatashiNiYomimasu.txt'), - os.path.join('folder', 'lalala.txt'), - os.path.join('folder', 'quest.txt'), - # The example will have a deleted file - # (or should) but shouldn't return it - ]) - self.assertEqual(set(x for x in walk_revctrl()), expected) - def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) -- cgit v1.2.1 From 54e96d8d8a6e18901d8e3e708fd0e82bfaba9569 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 31 Dec 2014 09:52:20 -0500 Subject: Add test capturing requirement. Ref #320. --- setuptools/tests/test_sdist.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index bece76d2..090e7304 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -11,6 +11,7 @@ import unicodedata import contextlib from setuptools.tests.py26compat import skipIf +import pkg_resources from setuptools.compat import StringIO, unicode, PY3, PY2 from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker @@ -416,5 +417,22 @@ class TestSdistTest(unittest.TestCase): self.assertFalse(filename in cmd.filelist.files) +def test_default_revctrl(): + """ + When _default_revctrl was removed from the `setuptools.command.sdist` + module in 10.0, it broke some systems which keep an old install of + setuptools (Distribute) around. Those old versions require that the + setuptools package continue to implement that interface, so this + function provides that interface, stubbed. See #320 for details. + + This interface must be maintained until Ubuntu 12.04 is no longer + supported (by Setuptools). + """ + ep_def = 'svn_cvs = setuptools.command.sdist:_default_revctrl' + ep = pkg_resources.EntryPoint.parse(ep_def) + res = ep.load(require=False) + assert hasattr(res, '__iter__') + + def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) -- cgit v1.2.1 From 80a28fa8c044ccb74e4ae54544be8c449ebd03e8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 31 Dec 2014 12:35:32 -0500 Subject: Use underlying invocation of ._load directly --- setuptools/tests/test_sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 090e7304..123e3ea9 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -430,7 +430,7 @@ def test_default_revctrl(): """ ep_def = 'svn_cvs = setuptools.command.sdist:_default_revctrl' ep = pkg_resources.EntryPoint.parse(ep_def) - res = ep.load(require=False) + res = ep._load() assert hasattr(res, '__iter__') -- cgit v1.2.1 From 4f9b50728ae8c5cf81b13b2d4fd3098b9f18dfb1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 1 Jan 2015 16:48:11 -0500 Subject: Use pytest for skips --- setuptools/tests/test_sdist.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 123e3ea9..120911d2 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,7 +9,8 @@ import tempfile import unittest import unicodedata import contextlib -from setuptools.tests.py26compat import skipIf + +import pytest import pkg_resources from setuptools.compat import StringIO, unicode, PY3, PY2 @@ -336,8 +337,9 @@ class TestSdistTest(unittest.TestCase): filename = filename.decode('latin-1') self.assertFalse(filename in cmd.filelist.files) - @skipIf(PY3 and locale.getpreferredencoding() != 'UTF-8', - 'Unittest fails if locale is not utf-8 but the manifests is recorded correctly') + @pytest.mark.skipif(PY3 and locale.getpreferredencoding() != 'UTF-8', + reason='Unittest fails if locale is not utf-8 but the manifests is ' + 'recorded correctly') def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From a6cfae4a1d1a0fb1c71b6fe353b9d1030417811a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 2 Jan 2015 11:58:30 -0500 Subject: Converted sdist tests to pytest --- setuptools/tests/test_sdist.py | 55 +++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 120911d2..943a5dee 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -6,7 +6,6 @@ import os import shutil import sys import tempfile -import unittest import unicodedata import contextlib @@ -78,9 +77,9 @@ def decompose(path): return path -class TestSdistTest(unittest.TestCase): +class TestSdistTest: - def setUp(self): + def setup_method(self, method): self.temp_dir = tempfile.mkdtemp() f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') f.write(SETUP_PY) @@ -98,7 +97,7 @@ class TestSdistTest(unittest.TestCase): self.old_cwd = os.getcwd() os.chdir(self.temp_dir) - def tearDown(self): + def teardown_method(self, method): os.chdir(self.old_cwd) shutil.rmtree(self.temp_dir) @@ -117,9 +116,9 @@ class TestSdistTest(unittest.TestCase): cmd.run() manifest = cmd.filelist.files - self.assertTrue(os.path.join('sdist_test', 'a.txt') in manifest) - self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest) - self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest) + assert os.path.join('sdist_test', 'a.txt') in manifest + assert os.path.join('sdist_test', 'b.txt') in manifest + assert os.path.join('sdist_test', 'c.rst') not in manifest def test_defaults_case_sensitivity(self): @@ -144,9 +143,9 @@ class TestSdistTest(unittest.TestCase): # lowercase all names so we can test in a case-insensitive way to make sure the files are not included manifest = map(lambda x: x.lower(), cmd.filelist.files) - self.assertFalse('readme.rst' in manifest, manifest) - self.assertFalse('setup.py' in manifest, manifest) - self.assertFalse('setup.cfg' in manifest, manifest) + assert 'readme.rst' not in manifest, manifest + assert 'setup.py' not in manifest, manifest + assert 'setup.cfg' not in manifest, manifest def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. @@ -184,7 +183,7 @@ class TestSdistTest(unittest.TestCase): fs_enc = sys.getfilesystemencoding() filename = filename.decode(fs_enc) - self.assertTrue(posix(filename) in u_contents) + assert posix(filename) in u_contents # Python 3 only if PY3: @@ -223,10 +222,10 @@ class TestSdistTest(unittest.TestCase): self.fail(e) # The manifest should contain the UTF-8 filename - self.assertTrue(posix(filename) in contents) + assert posix(filename) in contents # The filelist should have been updated as well - self.assertTrue(u_filename in mm.filelist.files) + assert u_filename in mm.filelist.files def test_write_manifest_skips_non_utf8_filenames(self): """ @@ -264,10 +263,10 @@ class TestSdistTest(unittest.TestCase): self.fail(e) # The Latin-1 filename should have been skipped - self.assertFalse(posix(filename) in contents) + assert posix(filename) not in contents # The filelist should have been updated as well - self.assertFalse(u_filename in mm.filelist.files) + assert u_filename not in mm.filelist.files def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. @@ -298,7 +297,7 @@ class TestSdistTest(unittest.TestCase): # The filelist should contain the UTF-8 filename if PY3: filename = filename.decode('utf-8') - self.assertTrue(filename in cmd.filelist.files) + assert filename in cmd.filelist.files # Python 3 only if PY3: @@ -335,7 +334,7 @@ class TestSdistTest(unittest.TestCase): # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') - self.assertFalse(filename in cmd.filelist.files) + assert filename not in cmd.filelist.files @pytest.mark.skipif(PY3 and locale.getpreferredencoding() != 'UTF-8', reason='Unittest fails if locale is not utf-8 but the manifests is ' @@ -364,15 +363,15 @@ class TestSdistTest(unittest.TestCase): if fs_enc == 'cp1252': # Python 3 mangles the UTF-8 filename filename = filename.decode('cp1252') - self.assertTrue(filename in cmd.filelist.files) + assert filename in cmd.filelist.files else: filename = filename.decode('mbcs') - self.assertTrue(filename in cmd.filelist.files) + assert filename in cmd.filelist.files else: filename = filename.decode('utf-8') - self.assertTrue(filename in cmd.filelist.files) + assert filename in cmd.filelist.files else: - self.assertTrue(filename in cmd.filelist.files) + assert filename in cmd.filelist.files def test_sdist_with_latin1_encoded_filename(self): # Test for #303. @@ -384,7 +383,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)) + assert os.path.isfile(filename) with quiet(): cmd.run() @@ -400,11 +399,11 @@ class TestSdistTest(unittest.TestCase): else: filename = filename.decode('latin-1') - self.assertTrue(filename in cmd.filelist.files) + assert 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) + filename not in cmd.filelist.files else: # Under Python 2 there seems to be no decoded string in the # filelist. However, due to decode and encoding of the @@ -414,9 +413,9 @@ class TestSdistTest(unittest.TestCase): # be proformed for the manifest output. fs_enc = sys.getfilesystemencoding() filename.decode(fs_enc) - self.assertTrue(filename in cmd.filelist.files) + assert filename in cmd.filelist.files except UnicodeDecodeError: - self.assertFalse(filename in cmd.filelist.files) + filename not in cmd.filelist.files def test_default_revctrl(): @@ -434,7 +433,3 @@ def test_default_revctrl(): ep = pkg_resources.EntryPoint.parse(ep_def) res = ep._load() assert hasattr(res, '__iter__') - - -def test_suite(): - return unittest.defaultTestLoader.loadTestsFromName(__name__) -- cgit v1.2.1 From 9d6a6e5927ae0e67164383e419f3145fc154467e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 11:35:16 -0500 Subject: Use except/as, now supported by Python 2.6 --- setuptools/tests/test_sdist.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 943a5dee..68f83ca7 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -174,8 +174,7 @@ class TestSdistTest: # The manifest should be UTF-8 encoded try: u_contents = contents.decode('UTF-8') - except UnicodeDecodeError: - e = sys.exc_info()[1] + except UnicodeDecodeError as e: self.fail(e) # The manifest should contain the UTF-8 filename @@ -217,8 +216,7 @@ class TestSdistTest: # The manifest should be UTF-8 encoded try: contents.decode('UTF-8') - except UnicodeDecodeError: - e = sys.exc_info()[1] + except UnicodeDecodeError as e: self.fail(e) # The manifest should contain the UTF-8 filename @@ -258,8 +256,7 @@ class TestSdistTest: # The manifest should be UTF-8 encoded try: contents.decode('UTF-8') - except UnicodeDecodeError: - e = sys.exc_info()[1] + except UnicodeDecodeError as e: self.fail(e) # The Latin-1 filename should have been skipped @@ -328,8 +325,7 @@ class TestSdistTest: with quiet(): try: cmd.read_manifest() - except UnicodeDecodeError: - e = sys.exc_info()[1] + except UnicodeDecodeError as e: self.fail(e) # The Latin-1 filename should have been skipped -- cgit v1.2.1 From fba8ee7abecb12726293438e8af19d7c3fa54bb8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 12:22:53 -0500 Subject: Remove try/except/fail - Exceptions are failures by default. --- setuptools/tests/test_sdist.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 68f83ca7..d3494d7a 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -172,10 +172,7 @@ class TestSdistTest: manifest.close() # The manifest should be UTF-8 encoded - try: - u_contents = contents.decode('UTF-8') - except UnicodeDecodeError as e: - self.fail(e) + u_contents = contents.decode('UTF-8') # The manifest should contain the UTF-8 filename if PY2: @@ -214,10 +211,7 @@ class TestSdistTest: manifest.close() # The manifest should be UTF-8 encoded - try: - contents.decode('UTF-8') - except UnicodeDecodeError as e: - self.fail(e) + contents.decode('UTF-8') # The manifest should contain the UTF-8 filename assert posix(filename) in contents @@ -254,10 +248,7 @@ class TestSdistTest: manifest.close() # The manifest should be UTF-8 encoded - try: - contents.decode('UTF-8') - except UnicodeDecodeError as e: - self.fail(e) + contents.decode('UTF-8') # The Latin-1 filename should have been skipped assert posix(filename) not in contents @@ -323,10 +314,7 @@ class TestSdistTest: # Re-read manifest cmd.filelist.files = [] with quiet(): - try: - cmd.read_manifest() - except UnicodeDecodeError as e: - self.fail(e) + cmd.read_manifest() # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') -- cgit v1.2.1 From 92a553d3adeb431cdf92b136ac9ccc3f2ef98bf1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Jan 2015 14:21:41 -0500 Subject: Add EntryPoint.resolve and deprecate most usage of EntryPoint.load. Removed EntryPoint._load. --- setuptools/tests/test_sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index d3494d7a..9013b505 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -415,5 +415,5 @@ def test_default_revctrl(): """ ep_def = 'svn_cvs = setuptools.command.sdist:_default_revctrl' ep = pkg_resources.EntryPoint.parse(ep_def) - res = ep._load() + res = ep.resolve() assert hasattr(res, '__iter__') -- cgit v1.2.1 From efededd6aa8be5ab054037ee32680a772d06a3c5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Dec 2015 12:41:58 -0500 Subject: Expect failures on these tests due to ASCII --- setuptools/tests/test_sdist.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 9013b505..4313c456 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -16,6 +16,8 @@ from setuptools.compat import StringIO, unicode, PY3, PY2 from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution +from setuptools.tests import fail_on_ascii + SETUP_ATTRS = { 'name': 'sdist_test', @@ -147,6 +149,7 @@ class TestSdistTest: assert 'setup.py' not in manifest, manifest assert 'setup.cfg' not in manifest, manifest + @fail_on_ascii def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) @@ -256,6 +259,7 @@ class TestSdistTest: # The filelist should have been updated as well assert u_filename not in mm.filelist.files + @fail_on_ascii def test_manifest_is_read_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) @@ -320,9 +324,7 @@ class TestSdistTest: filename = filename.decode('latin-1') assert filename not in cmd.filelist.files - @pytest.mark.skipif(PY3 and locale.getpreferredencoding() != 'UTF-8', - reason='Unittest fails if locale is not utf-8 but the manifests is ' - 'recorded correctly') + @fail_on_ascii def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From e7fdbbf85712acea80a591d2ec079b5349a53129 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Dec 2015 13:14:18 -0500 Subject: Try inlining the xfail marker. --- setuptools/tests/test_sdist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 4313c456..cc7661e6 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -16,7 +16,7 @@ from setuptools.compat import StringIO, unicode, PY3, PY2 from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution -from setuptools.tests import fail_on_ascii +from setuptools.tests import fail_on_ascii, is_ascii SETUP_ATTRS = { @@ -149,7 +149,7 @@ class TestSdistTest: assert 'setup.py' not in manifest, manifest assert 'setup.cfg' not in manifest, manifest - @fail_on_ascii + @pytest.mark.xfail(is_ascii, reason="Test fails in this locale") def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From 2e46cd7f81c5cf46ae45f8d7687ed4a4f9132a76 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Dec 2015 13:20:47 -0500 Subject: WTF --- setuptools/tests/test_sdist.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index cc7661e6..4d100fad 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -152,6 +152,7 @@ class TestSdistTest: @pytest.mark.xfail(is_ascii, reason="Test fails in this locale") def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. + assert not is_ascii dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' mm = manifest_maker(dist) -- cgit v1.2.1 From b4724ffead99897ce9c1411ff59206977df64f5f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Dec 2015 13:31:01 -0500 Subject: Try setting LC_CTYPE also --- setuptools/tests/test_sdist.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 4d100fad..df46518b 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """sdist tests""" -import locale import os import shutil import sys @@ -9,14 +8,12 @@ import tempfile import unicodedata import contextlib -import pytest - import pkg_resources from setuptools.compat import StringIO, unicode, PY3, PY2 from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution -from setuptools.tests import fail_on_ascii, is_ascii +from setuptools.tests import fail_on_ascii SETUP_ATTRS = { @@ -149,10 +146,9 @@ class TestSdistTest: assert 'setup.py' not in manifest, manifest assert 'setup.cfg' not in manifest, manifest - @pytest.mark.xfail(is_ascii, reason="Test fails in this locale") + @fail_on_ascii def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. - assert not is_ascii dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' mm = manifest_maker(dist) -- cgit v1.2.1 From 8e0ac92076007aa6e49f22029003b9618605c996 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Dec 2015 14:07:15 -0500 Subject: Expect failure running Python 3 only tests on Python 2 --- setuptools/tests/test_sdist.py | 210 +++++++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 104 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index df46518b..2b4d5207 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -8,6 +8,8 @@ import tempfile import unicodedata import contextlib +import pytest + import pkg_resources from setuptools.compat import StringIO, unicode, PY3, PY2 from setuptools.command.sdist import sdist @@ -16,6 +18,9 @@ from setuptools.dist import Distribution from setuptools.tests import fail_on_ascii +py3_only = pytest.mark.xfail(PY2, reason="Test runs on Python 3 only") + + SETUP_ATTRS = { 'name': 'sdist_test', 'version': '0.0', @@ -181,80 +186,79 @@ class TestSdistTest: assert posix(filename) in u_contents - # Python 3 only - if PY3: + @py3_only + def test_write_manifest_allows_utf8_filenames(self): + # Test for #303. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + mm = manifest_maker(dist) + mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + os.mkdir('sdist_test.egg-info') - def test_write_manifest_allows_utf8_filenames(self): - # Test for #303. - dist = Distribution(SETUP_ATTRS) - dist.script_name = 'setup.py' - mm = manifest_maker(dist) - mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') - os.mkdir('sdist_test.egg-info') - - # UTF-8 filename - filename = os.path.join(b('sdist_test'), b('smörbröd.py')) - - # Must touch the file or risk removal - open(filename, "w").close() - - # Add filename and write manifest - with quiet(): - mm.run() - u_filename = filename.decode('utf-8') - mm.filelist.files.append(u_filename) - # Re-write manifest - mm.write_manifest() - - manifest = open(mm.manifest, 'rbU') - contents = manifest.read() - manifest.close() - - # The manifest should be UTF-8 encoded - contents.decode('UTF-8') - - # The manifest should contain the UTF-8 filename - assert posix(filename) in contents - - # The filelist should have been updated as well - assert u_filename in mm.filelist.files - - def test_write_manifest_skips_non_utf8_filenames(self): - """ - Files that cannot be encoded to UTF-8 (specifically, those that - weren't originally successfully decoded and have surrogate - escapes) should be omitted from the manifest. - See https://bitbucket.org/tarek/distribute/issue/303 for history. - """ - dist = Distribution(SETUP_ATTRS) - dist.script_name = 'setup.py' - mm = manifest_maker(dist) - mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') - os.mkdir('sdist_test.egg-info') - - # Latin-1 filename - filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) - - # Add filename with surrogates and write manifest - with quiet(): - mm.run() - u_filename = filename.decode('utf-8', 'surrogateescape') - mm.filelist.append(u_filename) - # Re-write manifest - mm.write_manifest() - - manifest = open(mm.manifest, 'rbU') - contents = manifest.read() - manifest.close() - - # The manifest should be UTF-8 encoded - contents.decode('UTF-8') - - # The Latin-1 filename should have been skipped - assert posix(filename) not in contents - - # The filelist should have been updated as well - assert u_filename not in mm.filelist.files + # UTF-8 filename + filename = os.path.join(b('sdist_test'), b('smörbröd.py')) + + # Must touch the file or risk removal + open(filename, "w").close() + + # Add filename and write manifest + with quiet(): + mm.run() + u_filename = filename.decode('utf-8') + mm.filelist.files.append(u_filename) + # Re-write manifest + mm.write_manifest() + + manifest = open(mm.manifest, 'rbU') + contents = manifest.read() + manifest.close() + + # The manifest should be UTF-8 encoded + contents.decode('UTF-8') + + # The manifest should contain the UTF-8 filename + assert posix(filename) in contents + + # The filelist should have been updated as well + assert u_filename in mm.filelist.files + + @py3_only + def test_write_manifest_skips_non_utf8_filenames(self): + """ + Files that cannot be encoded to UTF-8 (specifically, those that + weren't originally successfully decoded and have surrogate + escapes) should be omitted from the manifest. + See https://bitbucket.org/tarek/distribute/issue/303 for history. + """ + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + mm = manifest_maker(dist) + mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + os.mkdir('sdist_test.egg-info') + + # Latin-1 filename + filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + + # Add filename with surrogates and write manifest + with quiet(): + mm.run() + u_filename = filename.decode('utf-8', 'surrogateescape') + mm.filelist.append(u_filename) + # Re-write manifest + mm.write_manifest() + + manifest = open(mm.manifest, 'rbU') + contents = manifest.read() + manifest.close() + + # The manifest should be UTF-8 encoded + contents.decode('UTF-8') + + # The Latin-1 filename should have been skipped + assert posix(filename) not in contents + + # The filelist should have been updated as well + assert u_filename not in mm.filelist.files @fail_on_ascii def test_manifest_is_read_with_utf8_encoding(self): @@ -288,38 +292,36 @@ class TestSdistTest: filename = filename.decode('utf-8') assert filename in cmd.filelist.files - # Python 3 only - if PY3: + @py3_only + def test_read_manifest_skips_non_utf8_filenames(self): + # Test for #303. + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # Create manifest + with quiet(): + cmd.run() + + # Add Latin-1 filename to manifest + filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') + manifest = open(cmd.manifest, 'ab') + manifest.write(b('\n') + filename) + manifest.close() + + # The file must exist to be included in the filelist + open(filename, 'w').close() + + # Re-read manifest + cmd.filelist.files = [] + with quiet(): + cmd.read_manifest() - def test_read_manifest_skips_non_utf8_filenames(self): - # Test for #303. - dist = Distribution(SETUP_ATTRS) - dist.script_name = 'setup.py' - cmd = sdist(dist) - cmd.ensure_finalized() - - # Create manifest - with quiet(): - cmd.run() - - # Add Latin-1 filename to manifest - filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) - cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') - manifest = open(cmd.manifest, 'ab') - manifest.write(b('\n') + filename) - manifest.close() - - # The file must exist to be included in the filelist - open(filename, 'w').close() - - # Re-read manifest - cmd.filelist.files = [] - with quiet(): - cmd.read_manifest() - - # The Latin-1 filename should have been skipped - filename = filename.decode('latin-1') - assert filename not in cmd.filelist.files + # The Latin-1 filename should have been skipped + filename = filename.decode('latin-1') + assert filename not in cmd.filelist.files @fail_on_ascii def test_sdist_with_utf8_encoded_filename(self): -- cgit v1.2.1 From dc67e7816dcc9f2f5d2056fe4b4613c74fe1e0d3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Dec 2015 14:08:43 -0500 Subject: Expect fail when LC_ALL=C --- setuptools/tests/test_sdist.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 2b4d5207..ec3c8aa9 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -187,6 +187,7 @@ class TestSdistTest: assert posix(filename) in u_contents @py3_only + @fail_on_ascii def test_write_manifest_allows_utf8_filenames(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From 41112f5afd0d2b0c14899ab1cf2c27183e64d6ac Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 9 Dec 2015 03:34:35 -0500 Subject: Use io.open for future compatibility and consistency --- setuptools/tests/test_sdist.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index ec3c8aa9..8ec9a4cb 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -7,6 +7,7 @@ import sys import tempfile import unicodedata import contextlib +import io import pytest @@ -81,6 +82,11 @@ def decompose(path): return path +def read_all_bytes(filename): + with io.open(filename, 'rb') as fp: + return fp.read() + + class TestSdistTest: def setup_method(self, method): @@ -172,9 +178,7 @@ class TestSdistTest: mm.filelist.append(filename) mm.write_manifest() - manifest = open(mm.manifest, 'rbU') - contents = manifest.read() - manifest.close() + contents = read_all_bytes(mm.manifest) # The manifest should be UTF-8 encoded u_contents = contents.decode('UTF-8') @@ -210,9 +214,7 @@ class TestSdistTest: # Re-write manifest mm.write_manifest() - manifest = open(mm.manifest, 'rbU') - contents = manifest.read() - manifest.close() + contents = read_all_bytes(mm.manifest) # The manifest should be UTF-8 encoded contents.decode('UTF-8') @@ -248,9 +250,7 @@ class TestSdistTest: # Re-write manifest mm.write_manifest() - manifest = open(mm.manifest, 'rbU') - contents = manifest.read() - manifest.close() + contents = read_all_bytes(mm.manifest) # The manifest should be UTF-8 encoded contents.decode('UTF-8') -- cgit v1.2.1 From 06872bb0bbbeb953e90bd0941444b0d499056557 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 11:51:01 -0500 Subject: Update vendoring technique to match that used for packaging. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/tests/test_sdist.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index c173d713..ea176733 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,7 +9,13 @@ import unicodedata import contextlib import io -import six +try: + from setuptools._vendor import six +except ImportError: + # fallback to naturally-installed version; allows system packagers to + # omit vendored packages. + import six + import pytest import pkg_resources -- cgit v1.2.1 From 952c1bafda1929c74c737646aa025e6ffad6632e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 16:30:47 -0500 Subject: Modeling after Astropy's technique for bundling libraries, the imports are now much cleaner. Thanks @embray. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/tests/test_sdist.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index ea176733..753b507d 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,12 +9,7 @@ import unicodedata import contextlib import io -try: - from setuptools._vendor import six -except ImportError: - # fallback to naturally-installed version; allows system packagers to - # omit vendored packages. - import six +from setuptools.extern import six import pytest -- cgit v1.2.1 From 8af3b6ef5b4173a0d0d6735147c98c882ae98344 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:54:00 -0500 Subject: Always use Python 3 version of map --- setuptools/tests/test_sdist.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 753b507d..d2a1f1bb 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -10,6 +10,7 @@ import contextlib import io from setuptools.extern import six +from setuptools.extern.six.moves import map import pytest -- cgit v1.2.1 From 6d11e88f938f09ef16db4c6064b6e74acba4db1d Mon Sep 17 00:00:00 2001 From: stepshal Date: Tue, 12 Jul 2016 22:00:43 +0700 Subject: Fix quantity of blank lines after code object. --- setuptools/tests/test_sdist.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index d2a1f1bb..16d0eb07 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -132,7 +132,6 @@ class TestSdistTest: assert os.path.join('sdist_test', 'b.txt') in manifest assert os.path.join('sdist_test', 'c.rst') not in manifest - def test_defaults_case_sensitivity(self): """ Make sure default files (README.*, etc.) are added in a case-sensitive -- cgit v1.2.1 From 31bd37c6ac8de9e8c1bacebc2d8e1215df91eb96 Mon Sep 17 00:00:00 2001 From: stepshal Date: Tue, 18 Oct 2016 20:24:35 +0700 Subject: Fix quantity of blank lines. --- setuptools/tests/test_sdist.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 16d0eb07..609c7830 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -20,10 +20,8 @@ from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution from setuptools.tests import fail_on_ascii - py3_only = pytest.mark.xfail(six.PY2, reason="Test runs on Python 3 only") - SETUP_ATTRS = { 'name': 'sdist_test', 'version': '0.0', @@ -31,14 +29,12 @@ SETUP_ATTRS = { 'package_data': {'sdist_test': ['*.txt']} } - SETUP_PY = """\ from setuptools import setup setup(**%r) """ % SETUP_ATTRS - if six.PY3: LATIN1_FILENAME = 'smörbröd.py'.encode('latin-1') else: @@ -90,7 +86,6 @@ def read_all_bytes(filename): class TestSdistTest: - def setup_method(self, method): self.temp_dir = tempfile.mkdtemp() f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') -- cgit v1.2.1 From 11b921f2e17586e394639e7ddbcaeae727ece4d0 Mon Sep 17 00:00:00 2001 From: Thiebaud Weksteen Date: Tue, 1 Nov 2016 15:54:23 +1100 Subject: Change _add_defaults_data_files override and add unittest --- setuptools/tests/test_sdist.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 609c7830..f34068dc 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -26,7 +26,8 @@ SETUP_ATTRS = { 'name': 'sdist_test', 'version': '0.0', 'packages': ['sdist_test'], - 'package_data': {'sdist_test': ['*.txt']} + 'package_data': {'sdist_test': ['*.txt']}, + 'data_files': [("data", [os.path.join("d", "e.dat")])], } SETUP_PY = """\ @@ -95,9 +96,12 @@ class TestSdistTest: # Set up the rest of the test package test_pkg = os.path.join(self.temp_dir, 'sdist_test') os.mkdir(test_pkg) + data_folder = os.path.join(self.temp_dir, "d") + os.mkdir(data_folder) # *.rst was not included in package_data, so c.rst should not be # automatically added to the manifest when not under version control - for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']: + for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst', + os.path.join(data_folder, "e.dat")]: # Just touch the files; their contents are irrelevant open(os.path.join(test_pkg, fname), 'w').close() @@ -126,6 +130,7 @@ class TestSdistTest: assert os.path.join('sdist_test', 'a.txt') in manifest assert os.path.join('sdist_test', 'b.txt') in manifest assert os.path.join('sdist_test', 'c.rst') not in manifest + assert os.path.join('d', 'e.dat') in manifest def test_defaults_case_sensitivity(self): """ -- cgit v1.2.1 From ff371f18f0076bc63da05334f7e551c1cc29e10d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2017 22:34:28 -0500 Subject: Strip out vendored packages and require them instead. Ref #581. --- setuptools/tests/test_sdist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f34068dc..38fdda24 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,8 +9,8 @@ import unicodedata import contextlib import io -from setuptools.extern import six -from setuptools.extern.six.moves import map +import six +from six.moves import map import pytest -- cgit v1.2.1 From 3d0cc355fb5e8012cb8c72f0e25042a5a44f31d6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Feb 2017 11:49:51 -0500 Subject: Revert "Merge pull request #933 from pypa/feature/581-depend-not-bundle" This reverts commit 089cdeb489a0fa94d11b7307b54210ef9aa40511, reversing changes made to aaec654d804cb78dbb6391afff721a63f26a71cd. --- setuptools/tests/test_sdist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 38fdda24..f34068dc 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -9,8 +9,8 @@ import unicodedata import contextlib import io -import six -from six.moves import map +from setuptools.extern import six +from setuptools.extern.six.moves import map import pytest -- cgit v1.2.1 From c292a995eaa090c88c2d3edab6716cdb77629e42 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 11 Oct 2017 09:41:09 +0200 Subject: Remove meaningless commend --- setuptools/tests/test_sdist.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f34068dc..f84c57dc 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -42,7 +42,6 @@ else: LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py' -# Cannot use context manager because of Python 2.4 @contextlib.contextmanager def quiet(): old_stdout, old_stderr = sys.stdout, sys.stderr -- cgit v1.2.1 From b8936cee54cc023ba6c6081e03e0425bce20b1f7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 11 Oct 2017 15:01:39 +0200 Subject: Use natural byte literals in test_sdist --- setuptools/tests/test_sdist.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f84c57dc..1b5422f4 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -41,6 +41,8 @@ if six.PY3: else: LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py' +utf_8_filename = LATIN1_FILENAME.decode('latin-1').encode('utf-8') + @contextlib.contextmanager def quiet(): @@ -52,17 +54,10 @@ def quiet(): sys.stdout, sys.stderr = old_stdout, old_stderr -# Fake byte literals for Python <= 2.5 -def b(s, encoding='utf-8'): - if six.PY3: - return s.encode(encoding) - return s - - # Convert to POSIX path def posix(path): if six.PY3 and not isinstance(path, str): - return path.replace(os.sep.encode('ascii'), b('/')) + return path.replace(os.sep.encode('ascii'), b'/') else: return path.replace(os.sep, '/') @@ -200,8 +195,7 @@ class TestSdistTest: mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') os.mkdir('sdist_test.egg-info') - # UTF-8 filename - filename = os.path.join(b('sdist_test'), b('smörbröd.py')) + filename = os.path.join(b'sdist_test', utf_8_filename) # Must touch the file or risk removal open(filename, "w").close() @@ -240,7 +234,7 @@ class TestSdistTest: os.mkdir('sdist_test.egg-info') # Latin-1 filename - filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + filename = os.path.join(b'sdist_test', LATIN1_FILENAME) # Add filename with surrogates and write manifest with quiet(): @@ -274,10 +268,10 @@ class TestSdistTest: cmd.run() # Add UTF-8 filename to manifest - filename = os.path.join(b('sdist_test'), b('smörbröd.py')) + filename = os.path.join(b'sdist_test', utf_8_filename) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') - manifest.write(b('\n') + filename) + manifest.write(b'\n' + filename) manifest.close() # The file must exist to be included in the filelist @@ -306,10 +300,10 @@ class TestSdistTest: cmd.run() # Add Latin-1 filename to manifest - filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + filename = os.path.join(b'sdist_test', LATIN1_FILENAME) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') - manifest.write(b('\n') + filename) + manifest.write(b'\n' + filename) manifest.close() # The file must exist to be included in the filelist @@ -333,7 +327,7 @@ class TestSdistTest: cmd.ensure_finalized() # UTF-8 filename - filename = os.path.join(b('sdist_test'), b('smörbröd.py')) + filename = os.path.join(b'sdist_test', utf_8_filename) open(filename, 'w').close() with quiet(): @@ -367,7 +361,7 @@ class TestSdistTest: cmd.ensure_finalized() # Latin-1 filename - filename = os.path.join(b('sdist_test'), LATIN1_FILENAME) + filename = os.path.join(b'sdist_test', LATIN1_FILENAME) open(filename, 'w').close() assert os.path.isfile(filename) -- cgit v1.2.1 From 1c00a900c9aba25d6369cf9312997434ad68b9b1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 11 Oct 2017 15:03:47 +0200 Subject: Collapse encoding detection --- setuptools/tests/test_sdist.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 1b5422f4..5cb63c4b 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -374,10 +374,9 @@ class TestSdistTest: # 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: - filename = filename.decode('latin-1') + if fs_enc != 'mbcs': + fs_enc = 'latin-1' + filename = filename.decode(fs_enc) assert filename in cmd.filelist.files else: -- cgit v1.2.1 From 5e6d72b852229750d00023885a6ce6149060d08a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 11 Oct 2017 15:04:25 +0200 Subject: Feed the hobgoblins (delint). --- setuptools/tests/test_sdist.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 5cb63c4b..e7fc71e3 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -128,8 +128,8 @@ class TestSdistTest: def test_defaults_case_sensitivity(self): """ - Make sure default files (README.*, etc.) are added in a case-sensitive - way to avoid problems with packages built on Windows. + Make sure default files (README.*, etc.) are added in a case-sensitive + way to avoid problems with packages built on Windows. """ open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close() @@ -146,7 +146,9 @@ class TestSdistTest: with quiet(): cmd.run() - # lowercase all names so we can test in a case-insensitive way to make sure the files are not included + # lowercase all names so we can test in a + # case-insensitive way to make sure the files + # are not included. manifest = map(lambda x: x.lower(), cmd.filelist.files) assert 'readme.rst' not in manifest, manifest assert 'setup.py' not in manifest, manifest -- cgit v1.2.1 From a85c59d34bbb232fc110714dc3aeb3c823a6f3cb Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 11 Oct 2017 15:30:09 +0200 Subject: Expect failure on macOS 10.13 and other operating systems where writing latin-1 encoded filenames is prohibited. Fixes #1169. --- setuptools/tests/test_sdist.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index e7fc71e3..3b9a3b94 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -80,6 +80,21 @@ def read_all_bytes(filename): return fp.read() +def latin1_fail(): + try: + desc, filename = tempfile.mkstemp(suffix=LATIN1_FILENAME) + os.close(desc) + os.remove(filename) + except Exception: + return True + + +fail_on_latin1_encoded_filenames = pytest.mark.xfail( + latin1_fail(), + reason="System does not support latin-1 filenames", +) + + class TestSdistTest: def setup_method(self, method): self.temp_dir = tempfile.mkdtemp() @@ -290,6 +305,7 @@ class TestSdistTest: assert filename in cmd.filelist.files @py3_only + @fail_on_latin1_encoded_filenames def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. dist = Distribution(SETUP_ATTRS) @@ -321,6 +337,7 @@ class TestSdistTest: assert filename not in cmd.filelist.files @fail_on_ascii + @fail_on_latin1_encoded_filenames def test_sdist_with_utf8_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) @@ -355,6 +372,7 @@ class TestSdistTest: else: assert filename in cmd.filelist.files + @fail_on_latin1_encoded_filenames def test_sdist_with_latin1_encoded_filename(self): # Test for #303. dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From ba46991d7cd488d682e80bb0e69964c4ed6c3303 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 11 Oct 2017 15:36:45 +0200 Subject: Move filename fixtures to a 'text' module so they can use unicode literals. --- setuptools/tests/test_sdist.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 3b9a3b94..02222da5 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -19,6 +19,7 @@ from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution from setuptools.tests import fail_on_ascii +from .text import Filenames py3_only = pytest.mark.xfail(six.PY2, reason="Test runs on Python 3 only") @@ -36,13 +37,6 @@ from setuptools import setup setup(**%r) """ % SETUP_ATTRS -if six.PY3: - LATIN1_FILENAME = 'smörbröd.py'.encode('latin-1') -else: - LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py' - -utf_8_filename = LATIN1_FILENAME.decode('latin-1').encode('utf-8') - @contextlib.contextmanager def quiet(): @@ -82,7 +76,7 @@ def read_all_bytes(filename): def latin1_fail(): try: - desc, filename = tempfile.mkstemp(suffix=LATIN1_FILENAME) + desc, filename = tempfile.mkstemp(suffix=Filenames.latin_1) os.close(desc) os.remove(filename) except Exception: @@ -212,7 +206,7 @@ class TestSdistTest: mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') os.mkdir('sdist_test.egg-info') - filename = os.path.join(b'sdist_test', utf_8_filename) + filename = os.path.join(b'sdist_test', Filenames.utf_8) # Must touch the file or risk removal open(filename, "w").close() @@ -251,7 +245,7 @@ class TestSdistTest: os.mkdir('sdist_test.egg-info') # Latin-1 filename - filename = os.path.join(b'sdist_test', LATIN1_FILENAME) + filename = os.path.join(b'sdist_test', Filenames.latin_1) # Add filename with surrogates and write manifest with quiet(): @@ -285,7 +279,7 @@ class TestSdistTest: cmd.run() # Add UTF-8 filename to manifest - filename = os.path.join(b'sdist_test', utf_8_filename) + filename = os.path.join(b'sdist_test', Filenames.utf_8) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b'\n' + filename) @@ -318,7 +312,7 @@ class TestSdistTest: cmd.run() # Add Latin-1 filename to manifest - filename = os.path.join(b'sdist_test', LATIN1_FILENAME) + filename = os.path.join(b'sdist_test', Filenames.latin_1) cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') manifest = open(cmd.manifest, 'ab') manifest.write(b'\n' + filename) @@ -345,8 +339,7 @@ class TestSdistTest: cmd = sdist(dist) cmd.ensure_finalized() - # UTF-8 filename - filename = os.path.join(b'sdist_test', utf_8_filename) + filename = os.path.join(b'sdist_test', Filenames.utf_8) open(filename, 'w').close() with quiet(): @@ -381,7 +374,7 @@ class TestSdistTest: cmd.ensure_finalized() # Latin-1 filename - filename = os.path.join(b'sdist_test', LATIN1_FILENAME) + filename = os.path.join(b'sdist_test', Filenames.latin_1) open(filename, 'w').close() assert os.path.isfile(filename) -- cgit v1.2.1 From d3215c10b6f9ccd8940f9345642ee0718f158585 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Sat, 27 Oct 2018 11:25:51 +0100 Subject: Mark Py 2/3-only tests as skip instead of xfail Also reuse pre-defined py2_only and py3_only decorators where appropriate. --- setuptools/tests/test_sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 02222da5..3a203890 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -20,8 +20,8 @@ from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution from setuptools.tests import fail_on_ascii from .text import Filenames +from . import py3_only -py3_only = pytest.mark.xfail(six.PY2, reason="Test runs on Python 3 only") SETUP_ATTRS = { 'name': 'sdist_test', -- cgit v1.2.1 From d3e08a321065f9c84ac923417f9d80ae510adaaf Mon Sep 17 00:00:00 2001 From: Shashank Singh Date: Sun, 28 Oct 2018 12:47:00 -0400 Subject: Add tests for setup.py inclusion This tests that `setup.py` is included by default in the distribution with the egg_info command and when an sdist is built with build_meta.build_sdist --- setuptools/tests/test_sdist.py | 46 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 3a203890..d2c4e0cf 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -92,9 +92,8 @@ fail_on_latin1_encoded_filenames = pytest.mark.xfail( class TestSdistTest: def setup_method(self, method): self.temp_dir = tempfile.mkdtemp() - f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') - f.write(SETUP_PY) - f.close() + with open(os.path.join(self.temp_dir, 'setup.py'), 'w') as f: + f.write(SETUP_PY) # Set up the rest of the test package test_pkg = os.path.join(self.temp_dir, 'sdist_test') @@ -135,6 +134,47 @@ class TestSdistTest: assert os.path.join('sdist_test', 'c.rst') not in manifest assert os.path.join('d', 'e.dat') in manifest + def test_setup_py_exists(self): + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'foo.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + with quiet(): + cmd.run() + + manifest = cmd.filelist.files + assert 'setup.py' in manifest + + def test_setup_py_missing(self): + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'foo.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + if os.path.exists("setup.py"): + os.remove("setup.py") + with quiet(): + cmd.run() + + manifest = cmd.filelist.files + assert 'setup.py' not in manifest + + def test_setup_py_excluded(self): + with open("MANIFEST.in", "w") as manifest_file: + manifest_file.write("exclude setup.py") + + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'foo.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + with quiet(): + cmd.run() + + manifest = cmd.filelist.files + assert 'setup.py' not in manifest + def test_defaults_case_sensitivity(self): """ Make sure default files (README.*, etc.) are added in a case-sensitive -- cgit v1.2.1 From 0c79e4d09cf429a2aabbcb6d4cf1455ec45a0137 Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Fri, 11 Jan 2019 15:29:40 +0300 Subject: include pyproject.toml in sdist (#1632) --- setuptools/tests/test_sdist.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index d2c4e0cf..06813a00 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -449,6 +449,20 @@ class TestSdistTest: except UnicodeDecodeError: filename not in cmd.filelist.files + def test_pyproject_toml_in_sdist(self): + """ + Check if pyproject.toml is included in source distribution if present + """ + open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + with quiet(): + cmd.run() + manifest = cmd.filelist.files + assert 'pyproject.toml' in manifest + def test_default_revctrl(): """ -- cgit v1.2.1 From f171cde1505fc5df438417dc5ae48d35fa60a002 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 12:47:46 -0500 Subject: Add test for exclusion expectation. Ref #1650. --- setuptools/tests/test_sdist.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 06813a00..a413e4ed 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -463,6 +463,22 @@ class TestSdistTest: manifest = cmd.filelist.files assert 'pyproject.toml' in manifest + def test_pyproject_toml_excluded(self): + """ + Check that pyproject.toml can excluded even if present + """ + open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + with open('MANIFEST.in', 'w') as mts: + print('exclude pyproject.toml', file=mts) + dist = Distribution(SETUP_ATTRS) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + with quiet(): + cmd.run() + manifest = cmd.filelist.files + assert 'pyproject.toml' not in manifest + def test_default_revctrl(): """ -- cgit v1.2.1 From 2eb3ba19f3153f83eb8b2470deb8ec02d21fca52 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 12:50:25 -0500 Subject: Restore Python 2.7 compatibility --- setuptools/tests/test_sdist.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index a413e4ed..b27c4a83 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """sdist tests""" +from __future__ import print_function + import os import shutil import sys -- cgit v1.2.1 From 9c40ab8861d1bbc18d1c8032f678e2ca15ada7ff Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 13:29:43 -0500 Subject: Rewrite TestSdistTest setup/teardown_method as pytest fixture. --- setuptools/tests/test_sdist.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index b27c4a83..f2e9a5ec 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -91,30 +91,29 @@ fail_on_latin1_encoded_filenames = pytest.mark.xfail( ) +def touch(path): + path.write_text('', encoding='utf-8') + + class TestSdistTest: - def setup_method(self, method): - self.temp_dir = tempfile.mkdtemp() - with open(os.path.join(self.temp_dir, 'setup.py'), 'w') as f: - f.write(SETUP_PY) + @pytest.fixture(autouse=True) + def source_dir(self, tmpdir): + self.temp_dir = str(tmpdir) + (tmpdir / 'setup.py').write_text(SETUP_PY, encoding='utf-8') # Set up the rest of the test package - test_pkg = os.path.join(self.temp_dir, 'sdist_test') - os.mkdir(test_pkg) - data_folder = os.path.join(self.temp_dir, "d") - os.mkdir(data_folder) + test_pkg = tmpdir / 'sdist_test' + test_pkg.mkdir() + data_folder = tmpdir / 'd' + data_folder.mkdir() # *.rst was not included in package_data, so c.rst should not be # automatically added to the manifest when not under version control - for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst', - os.path.join(data_folder, "e.dat")]: - # Just touch the files; their contents are irrelevant - open(os.path.join(test_pkg, fname), 'w').close() - - self.old_cwd = os.getcwd() - os.chdir(self.temp_dir) + for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']: + touch(test_pkg / fname) + touch(data_folder / 'e.dat') - def teardown_method(self, method): - os.chdir(self.old_cwd) - shutil.rmtree(self.temp_dir) + with tmpdir.as_cwd(): + yield def test_package_data_in_sdist(self): """Regression test for pull request #4: ensures that files listed in -- cgit v1.2.1 From 9e3149802ee214ee0500ec299250bf4febc67e52 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 13:31:37 -0500 Subject: Remove instance attribute; rely on tmpdir fixture; re-use touch helper. --- setuptools/tests/test_sdist.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index f2e9a5ec..1b951a5b 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -98,7 +98,6 @@ def touch(path): class TestSdistTest: @pytest.fixture(autouse=True) def source_dir(self, tmpdir): - self.temp_dir = str(tmpdir) (tmpdir / 'setup.py').write_text(SETUP_PY, encoding='utf-8') # Set up the rest of the test package @@ -176,14 +175,14 @@ class TestSdistTest: manifest = cmd.filelist.files assert 'setup.py' not in manifest - def test_defaults_case_sensitivity(self): + def test_defaults_case_sensitivity(self, tmpdir): """ Make sure default files (README.*, etc.) are added in a case-sensitive way to avoid problems with packages built on Windows. """ - open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close() - open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close() + touch(tmpdir / 'readme.rst') + touch(tmpdir / 'SETUP.cfg') dist = Distribution(SETUP_ATTRS) # the extension deliberately capitalized for this test @@ -450,11 +449,11 @@ class TestSdistTest: except UnicodeDecodeError: filename not in cmd.filelist.files - def test_pyproject_toml_in_sdist(self): + def test_pyproject_toml_in_sdist(self, tmpdir): """ Check if pyproject.toml is included in source distribution if present """ - open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + touch(tmpdir / 'pyproject.toml') dist = Distribution(SETUP_ATTRS) dist.script_name = 'setup.py' cmd = sdist(dist) @@ -464,11 +463,11 @@ class TestSdistTest: manifest = cmd.filelist.files assert 'pyproject.toml' in manifest - def test_pyproject_toml_excluded(self): + def test_pyproject_toml_excluded(self, tmpdir): """ Check that pyproject.toml can excluded even if present """ - open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close() + touch(tmpdir / 'pyproject.toml') with open('MANIFEST.in', 'w') as mts: print('exclude pyproject.toml', file=mts) dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From a87f975e65507382aaecfb01fe8df4608c38f466 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 31 Dec 2019 13:32:57 -0500 Subject: Remove unused import --- setuptools/tests/test_sdist.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 1b951a5b..dcc64cf2 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -4,7 +4,6 @@ from __future__ import print_function import os -import shutil import sys import tempfile import unicodedata -- cgit v1.2.1 From 90922a5eb9b2f002202a16c974b86750a46d21ea Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 1 Jan 2020 11:54:53 -0500 Subject: Restore Python 2.7 compatibility --- setuptools/tests/test_sdist.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index dcc64cf2..9ddbae8b 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """sdist tests""" -from __future__ import print_function +from __future__ import print_function, unicode_literals import os import sys @@ -229,10 +229,6 @@ class TestSdistTest: u_contents = contents.decode('UTF-8') # The manifest should contain the UTF-8 filename - if six.PY2: - fs_enc = sys.getfilesystemencoding() - filename = filename.decode(fs_enc) - assert posix(filename) in u_contents @py3_only -- cgit v1.2.1 From 3d5b7775b7b7ee6c0b354a04fe1d33c1f9b0e5df Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 1 Jan 2020 12:08:46 -0500 Subject: Fix latin1 and utf8 tests on Python 2 --- setuptools/tests/test_sdist.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 9ddbae8b..8538dd24 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -369,7 +369,7 @@ class TestSdistTest: @fail_on_latin1_encoded_filenames def test_sdist_with_utf8_encoded_filename(self): # Test for #303. - dist = Distribution(SETUP_ATTRS) + dist = Distribution(self.make_strings(SETUP_ATTRS)) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() @@ -400,10 +400,19 @@ class TestSdistTest: else: assert filename in cmd.filelist.files + @classmethod + def make_strings(cls, item): + if isinstance(item, dict): + return { + key: cls.make_strings(value) for key, value in item.items()} + if isinstance(item, list): + return list(map(cls.make_strings, item)) + return str(item) + @fail_on_latin1_encoded_filenames def test_sdist_with_latin1_encoded_filename(self): # Test for #303. - dist = Distribution(SETUP_ATTRS) + dist = Distribution(self.make_strings(SETUP_ATTRS)) dist.script_name = 'setup.py' cmd = sdist(dist) cmd.ensure_finalized() -- cgit v1.2.1 From 796abd8dbec884cedf326cb5f85512a5d5648c4e Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 8 Jan 2020 19:10:11 +0200 Subject: Fix for Python 4: replace unsafe six.PY3 with PY2 --- setuptools/tests/test_sdist.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 8538dd24..0bea53df 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -51,7 +51,7 @@ def quiet(): # Convert to POSIX path def posix(path): - if six.PY3 and not isinstance(path, str): + if not six.PY2 and not isinstance(path, str): return path.replace(os.sep.encode('ascii'), b'/') else: return path.replace(os.sep, '/') @@ -329,7 +329,7 @@ class TestSdistTest: cmd.read_manifest() # The filelist should contain the UTF-8 filename - if six.PY3: + if not six.PY2: filename = filename.decode('utf-8') assert filename in cmd.filelist.files @@ -383,7 +383,7 @@ class TestSdistTest: if sys.platform == 'darwin': filename = decompose(filename) - if six.PY3: + if not six.PY2: fs_enc = sys.getfilesystemencoding() if sys.platform == 'win32': @@ -425,7 +425,19 @@ class TestSdistTest: with quiet(): cmd.run() - if six.PY3: + if six.PY2: + # Under Python 2 there seems to be no decoded string in the + # filelist. However, due to decode and encoding of the + # file name to get utf-8 Manifest the latin1 maybe excluded + try: + # fs_enc should match how one is expect the decoding to + # be proformed for the manifest output. + fs_enc = sys.getfilesystemencoding() + filename.decode(fs_enc) + assert filename in cmd.filelist.files + except UnicodeDecodeError: + filename not in cmd.filelist.files + else: # not all windows systems have a default FS encoding of cp1252 if sys.platform == 'win32': # Latin-1 is similar to Windows-1252 however @@ -440,18 +452,6 @@ class TestSdistTest: # The Latin-1 filename should have been skipped filename = filename.decode('latin-1') filename not in cmd.filelist.files - else: - # Under Python 2 there seems to be no decoded string in the - # filelist. However, due to decode and encoding of the - # file name to get utf-8 Manifest the latin1 maybe excluded - try: - # fs_enc should match how one is expect the decoding to - # be proformed for the manifest output. - fs_enc = sys.getfilesystemencoding() - filename.decode(fs_enc) - assert filename in cmd.filelist.files - except UnicodeDecodeError: - filename not in cmd.filelist.files def test_pyproject_toml_in_sdist(self, tmpdir): """ -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/tests/test_sdist.py | 77 ++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 52 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 0bea53df..049fdcc0 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -1,8 +1,5 @@ -# -*- coding: utf-8 -*- """sdist tests""" -from __future__ import print_function, unicode_literals - import os import sys import tempfile @@ -10,9 +7,6 @@ import unicodedata import contextlib import io -from setuptools.extern import six -from setuptools.extern.six.moves import map - import pytest import pkg_resources @@ -21,7 +15,6 @@ from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution from setuptools.tests import fail_on_ascii from .text import Filenames -from . import py3_only SETUP_ATTRS = { @@ -42,7 +35,7 @@ setup(**%r) @contextlib.contextmanager def quiet(): old_stdout, old_stderr = sys.stdout, sys.stderr - sys.stdout, sys.stderr = six.StringIO(), six.StringIO() + sys.stdout, sys.stderr = io.StringIO(), io.StringIO() try: yield finally: @@ -51,7 +44,7 @@ def quiet(): # Convert to POSIX path def posix(path): - if not six.PY2 and not isinstance(path, str): + if not isinstance(path, str): return path.replace(os.sep.encode('ascii'), b'/') else: return path.replace(os.sep, '/') @@ -59,7 +52,7 @@ def posix(path): # HFS Plus uses decomposed UTF-8 def decompose(path): - if isinstance(path, six.text_type): + if isinstance(path, str): return unicodedata.normalize('NFD', path) try: path = path.decode('utf-8') @@ -231,7 +224,6 @@ class TestSdistTest: # The manifest should contain the UTF-8 filename assert posix(filename) in u_contents - @py3_only @fail_on_ascii def test_write_manifest_allows_utf8_filenames(self): # Test for #303. @@ -265,7 +257,6 @@ class TestSdistTest: # The filelist should have been updated as well assert u_filename in mm.filelist.files - @py3_only def test_write_manifest_skips_non_utf8_filenames(self): """ Files that cannot be encoded to UTF-8 (specifically, those that @@ -329,11 +320,9 @@ class TestSdistTest: cmd.read_manifest() # The filelist should contain the UTF-8 filename - if not six.PY2: - filename = filename.decode('utf-8') + filename = filename.decode('utf-8') assert filename in cmd.filelist.files - @py3_only @fail_on_latin1_encoded_filenames def test_read_manifest_skips_non_utf8_filenames(self): # Test for #303. @@ -383,21 +372,18 @@ class TestSdistTest: if sys.platform == 'darwin': filename = decompose(filename) - if not six.PY2: - fs_enc = sys.getfilesystemencoding() + fs_enc = sys.getfilesystemencoding() - if sys.platform == 'win32': - if fs_enc == 'cp1252': - # Python 3 mangles the UTF-8 filename - filename = filename.decode('cp1252') - assert filename in cmd.filelist.files - else: - filename = filename.decode('mbcs') - assert filename in cmd.filelist.files + if sys.platform == 'win32': + if fs_enc == 'cp1252': + # Python mangles the UTF-8 filename + filename = filename.decode('cp1252') + assert filename in cmd.filelist.files else: - filename = filename.decode('utf-8') + filename = filename.decode('mbcs') assert filename in cmd.filelist.files else: + filename = filename.decode('utf-8') assert filename in cmd.filelist.files @classmethod @@ -425,33 +411,20 @@ class TestSdistTest: with quiet(): cmd.run() - if six.PY2: - # Under Python 2 there seems to be no decoded string in the - # filelist. However, due to decode and encoding of the - # file name to get utf-8 Manifest the latin1 maybe excluded - try: - # fs_enc should match how one is expect the decoding to - # be proformed for the manifest output. - fs_enc = sys.getfilesystemencoding() - filename.decode(fs_enc) - assert filename in cmd.filelist.files - except UnicodeDecodeError: - filename not in cmd.filelist.files - else: - # 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': - fs_enc = 'latin-1' - filename = filename.decode(fs_enc) + # 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': + fs_enc = 'latin-1' + filename = filename.decode(fs_enc) - assert filename in cmd.filelist.files - else: - # The Latin-1 filename should have been skipped - filename = filename.decode('latin-1') - filename not in cmd.filelist.files + assert filename in cmd.filelist.files + else: + # The Latin-1 filename should have been skipped + filename = filename.decode('latin-1') + filename not in cmd.filelist.files def test_pyproject_toml_in_sdist(self, tmpdir): """ -- cgit v1.2.1 From 2e66eb7147ae1e8a799b2276c7340f48f63a7220 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 1 Nov 2021 19:47:33 +0000 Subject: Fix 1461: Better loop breaker for `manifest_maker` The inconsistency for the `package_data` configuration in sdists when `include_package_data=True` in #1461 have been causing some problems for the community for a while, as also shown in #2835. As pointed out by [@jaraco](https://github.com/pypa/setuptools/issues/1461#issuecomment-749092366), this was being caused by a mechanism to break the recursion between the `egg_info` and `sdist` commands. In summary the loop is caused by the following behaviour: - the `egg_info` command uses a subclass of `sdist` (`manifest_maker`) to calculate the MANIFEST, - the `sdist` class needs to know the MANIFEST to calculate the data files when `include_package_data=True` Previously, the mechanism to break this loop was to simply ignore the data files in `sdist` when `include_package_data=True`. The approach implemented in this change was to replace this mechanism, by allowing `manifest_maker` to override the `_safe_data_files` method from `sdist`. --- Please notice [an extensive experiment] (https://github.com/abravalheri/experiment-setuptools-package-data) was carried out to investigate the previous confusing behaviour. There is also [a simplified theoretical analysis] (https://github.com/pyscaffold/pyscaffold/pull/535#issuecomment-956296407) comparing the observed behavior in the experiment and the expected one. This analysis point out to the same offender indicated by [@jaraco](https://github.com/pypa/setuptools/issues/1461#issuecomment-749092366) (which is being replaced in this change). --- setuptools/tests/test_sdist.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 049fdcc0..98eb1a4f 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -126,6 +126,30 @@ class TestSdistTest: assert os.path.join('sdist_test', 'c.rst') not in manifest assert os.path.join('d', 'e.dat') in manifest + def test_package_data_and_include_package_data_in_sdist(self): + """Make sure there is no recursion when ``include_package_data=True``. + + The mention to a recursion can be first found in: + https://github.com/pypa/setuptools/commit/f6cb3d29d919ff6b9313b8a3281c66cfb368c29b + """ + + setup_attrs = {**SETUP_ATTRS, 'include_package_data': True} + assert setup_attrs['package_data'] # make sure we have both options + + dist = Distribution(setup_attrs) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + with quiet(): + cmd.run() + + manifest = cmd.filelist.files + assert os.path.join('sdist_test', 'a.txt') in manifest + assert os.path.join('sdist_test', 'b.txt') in manifest + assert os.path.join('sdist_test', 'c.rst') not in manifest + assert os.path.join('d', 'e.dat') in manifest + def test_setup_py_exists(self): dist = Distribution(SETUP_ATTRS) dist.script_name = 'foo.py' -- cgit v1.2.1 From 10ead90587c991774f2b6157ed7924bac83fff65 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 2 Nov 2021 21:15:56 -0400 Subject: Trim docstring and remove comment. --- setuptools/tests/test_sdist.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 98eb1a4f..34c32bb0 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -127,14 +127,12 @@ class TestSdistTest: assert os.path.join('d', 'e.dat') in manifest def test_package_data_and_include_package_data_in_sdist(self): - """Make sure there is no recursion when ``include_package_data=True``. - - The mention to a recursion can be first found in: - https://github.com/pypa/setuptools/commit/f6cb3d29d919ff6b9313b8a3281c66cfb368c29b """ - + Ensure package_data and include_package_data work + together. + """ setup_attrs = {**SETUP_ATTRS, 'include_package_data': True} - assert setup_attrs['package_data'] # make sure we have both options + assert setup_attrs['package_data'] dist = Distribution(setup_attrs) dist.script_name = 'setup.py' -- cgit v1.2.1 From a5716723c3e311c0a69da57dbf7c5bc65d4ef062 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Thu, 4 Nov 2021 12:27:55 +0000 Subject: Add regression test for #2849 --- setuptools/tests/test_sdist.py | 57 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 34c32bb0..4ab13228 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -6,6 +6,7 @@ import tempfile import unicodedata import contextlib import io +from unittest import mock import pytest @@ -106,6 +107,13 @@ class TestSdistTest: with tmpdir.as_cwd(): yield + def assert_package_data_in_manifest(self, cmd): + manifest = cmd.filelist.files + assert os.path.join('sdist_test', 'a.txt') in manifest + assert os.path.join('sdist_test', 'b.txt') in manifest + assert os.path.join('sdist_test', 'c.rst') not in manifest + assert os.path.join('d', 'e.dat') in manifest + def test_package_data_in_sdist(self): """Regression test for pull request #4: ensures that files listed in package_data are included in the manifest even if they're not added to @@ -120,11 +128,7 @@ class TestSdistTest: with quiet(): cmd.run() - manifest = cmd.filelist.files - assert os.path.join('sdist_test', 'a.txt') in manifest - assert os.path.join('sdist_test', 'b.txt') in manifest - assert os.path.join('sdist_test', 'c.rst') not in manifest - assert os.path.join('d', 'e.dat') in manifest + self.assert_package_data_in_manifest(cmd) def test_package_data_and_include_package_data_in_sdist(self): """ @@ -142,11 +146,44 @@ class TestSdistTest: with quiet(): cmd.run() - manifest = cmd.filelist.files - assert os.path.join('sdist_test', 'a.txt') in manifest - assert os.path.join('sdist_test', 'b.txt') in manifest - assert os.path.join('sdist_test', 'c.rst') not in manifest - assert os.path.join('d', 'e.dat') in manifest + self.assert_package_data_in_manifest(cmd) + + def test_custom_build_py(self): + """ + Ensure projects defining custom build_py don't break + when creating sdists (issue #2849) + """ + from distutils.command.build_py import build_py as OrigBuildPy + + using_custom_command_guard = mock.Mock() + + class CustomBuildPy(OrigBuildPy): + """ + Some projects have custom commands inheriting from `distutils` + """ + + def get_data_files(self): + using_custom_command_guard() + return super().get_data_files() + + setup_attrs = {**SETUP_ATTRS, 'include_package_data': True} + assert setup_attrs['package_data'] + + dist = Distribution(setup_attrs) + dist.script_name = 'setup.py' + cmd = sdist(dist) + cmd.ensure_finalized() + + # Make sure we use the custom command + cmd.cmdclass = {'build_py': CustomBuildPy} + cmd.distribution.cmdclass = {'build_py': CustomBuildPy} + assert cmd.distribution.get_command_class('build_py') == CustomBuildPy + + with quiet(): + cmd.run() + + using_custom_command_guard.assert_called() + self.assert_package_data_in_manifest(cmd) def test_setup_py_exists(self): dist = Distribution(SETUP_ATTRS) -- cgit v1.2.1 From 9d0dc418639a0bf7cd9244feb705d30b60e1a906 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Thu, 4 Nov 2021 12:40:50 +0000 Subject: Make sure user gets warned when using distutils --- setuptools/tests/test_sdist.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 4ab13228..e6d8e908 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -148,7 +148,8 @@ class TestSdistTest: self.assert_package_data_in_manifest(cmd) - def test_custom_build_py(self): + @mock.patch('setuptools.command.egg_info.log') + def test_custom_build_py(self, log_stub): """ Ensure projects defining custom build_py don't break when creating sdists (issue #2849) @@ -185,6 +186,19 @@ class TestSdistTest: using_custom_command_guard.assert_called() self.assert_package_data_in_manifest(cmd) + warn_stub = log_stub.warn + warn_stub.assert_called() + for call in warn_stub.call_args_list: + args, _kw = call + if "setuptools instead of distutils" in args[0]: + return + else: + raise AssertionError( + "The user should have been warned to extend setuptools command" + " classes instead of distutils", + warn_stub.call_args_list + ) + def test_setup_py_exists(self): dist = Distribution(SETUP_ATTRS) dist.script_name = 'foo.py' -- cgit v1.2.1 From e2220331136c3a60b8d70a6b4eaad05816c9b637 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 5 Nov 2021 14:14:29 +0000 Subject: Use warning instead of log for distutils command As discussed in #2855, using an actual warning instead of the logger allow users to control what gets displayed via warning filters. --- setuptools/tests/test_sdist.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'setuptools/tests/test_sdist.py') diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index e6d8e908..66f46ad0 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -11,6 +11,7 @@ from unittest import mock import pytest import pkg_resources +from setuptools import SetuptoolsDeprecationWarning from setuptools.command.sdist import sdist from setuptools.command.egg_info import manifest_maker from setuptools.dist import Distribution @@ -148,8 +149,7 @@ class TestSdistTest: self.assert_package_data_in_manifest(cmd) - @mock.patch('setuptools.command.egg_info.log') - def test_custom_build_py(self, log_stub): + def test_custom_build_py(self): """ Ensure projects defining custom build_py don't break when creating sdists (issue #2849) @@ -180,25 +180,13 @@ class TestSdistTest: cmd.distribution.cmdclass = {'build_py': CustomBuildPy} assert cmd.distribution.get_command_class('build_py') == CustomBuildPy - with quiet(): + msg = "setuptools instead of distutils" + with quiet(), pytest.warns(SetuptoolsDeprecationWarning, match=msg): cmd.run() using_custom_command_guard.assert_called() self.assert_package_data_in_manifest(cmd) - warn_stub = log_stub.warn - warn_stub.assert_called() - for call in warn_stub.call_args_list: - args, _kw = call - if "setuptools instead of distutils" in args[0]: - return - else: - raise AssertionError( - "The user should have been warned to extend setuptools command" - " classes instead of distutils", - warn_stub.call_args_list - ) - def test_setup_py_exists(self): dist = Distribution(SETUP_ATTRS) dist.script_name = 'foo.py' -- cgit v1.2.1