[Python-checkins] cpython (2.7): Issue #11638: Adding test to ensure .tar.gz files can be generated by sdist

jason.coombs python-checkins at python.org
Mon Dec 26 18:22:35 CET 2011


http://hg.python.org/cpython/rev/dc1045d08bd8
changeset:   74181:dc1045d08bd8
branch:      2.7
user:        Jason R. Coombs <jaraco at jaraco.com>
date:        Mon Dec 26 10:15:15 2011 -0500
summary:
  Issue #11638: Adding test to ensure .tar.gz files can be generated by sdist command with unicode metadata, based on David Barnett's patch.
Issue #11638: Added tests to capture failures in make_tarball with various unicode strings.
Following fix for Issue #13639, these tests now pass.

files:
  Lib/distutils/tests/test_archive_util.py |  31 +++++++++++-
  Lib/distutils/tests/test_sdist.py        |  22 ++++++++
  Misc/NEWS                                |   3 +
  3 files changed, 54 insertions(+), 2 deletions(-)


diff --git a/Lib/distutils/tests/test_archive_util.py b/Lib/distutils/tests/test_archive_util.py
--- a/Lib/distutils/tests/test_archive_util.py
+++ b/Lib/distutils/tests/test_archive_util.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 """Tests for distutils.archive_util."""
 __revision__ = "$Id$"
 
@@ -40,6 +41,9 @@
 
     @unittest.skipUnless(zlib, "requires zlib")
     def test_make_tarball(self):
+        self._make_tarball('archive')
+
+    def _make_tarball(self, target_name):
         # creating something to tar
         tmpdir = self.mkdtemp()
         self.write_file([tmpdir, 'file1'], 'xxx')
@@ -51,7 +55,7 @@
         unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
                             "source and target should be on same drive")
 
-        base_name = os.path.join(tmpdir2, 'archive')
+        base_name = os.path.join(tmpdir2, target_name)
 
         # working with relative paths to avoid tar warnings
         old_dir = os.getcwd()
@@ -66,7 +70,7 @@
         self.assertTrue(os.path.exists(tarball))
 
         # trying an uncompressed one
-        base_name = os.path.join(tmpdir2, 'archive')
+        base_name = os.path.join(tmpdir2, target_name)
         old_dir = os.getcwd()
         os.chdir(tmpdir)
         try:
@@ -277,6 +281,29 @@
         finally:
             del ARCHIVE_FORMATS['xxx']
 
+    @unittest.skipUnless(zlib, "requires zlib")
+    def test_make_tarball_unicode(self):
+        """
+        Mirror test_make_tarball, except filename is unicode.
+        """
+        self._make_tarball(u'archive')
+
+    @unittest.skipUnless(zlib, "requires zlib")
+    def test_make_tarball_unicode_latin1(self):
+        """
+        Mirror test_make_tarball, except filename is unicode and contains
+        latin characters.
+        """
+        self._make_tarball(u'årchiv') # note this isn't a real word
+
+    @unittest.skipUnless(zlib, "requires zlib")
+    def test_make_tarball_unicode_extended(self):
+        """
+        Mirror test_make_tarball, except filename is unicode and contains
+        characters outside the latin charset.
+        """
+        self._make_tarball(u'のアーカイブ') # japanese for archive
+
 def test_suite():
     return unittest.makeSuite(ArchiveUtilTestCase)
 
diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py
--- a/Lib/distutils/tests/test_sdist.py
+++ b/Lib/distutils/tests/test_sdist.py
@@ -166,6 +166,28 @@
         self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])
 
     @unittest.skipUnless(zlib, "requires zlib")
+    def test_unicode_metadata_tgz(self):
+        """
+        Unicode name or version should not break building to tar.gz format.
+        Reference issue #11638.
+        """
+
+        # create the sdist command with unicode parameters
+        dist, cmd = self.get_cmd({'name': u'fake', 'version': u'1.0'})
+
+        # create the sdist as gztar and run the command
+        cmd.formats = ['gztar']
+        cmd.ensure_finalized()
+        cmd.run()
+
+        # The command should have created the .tar.gz file
+        dist_folder = join(self.tmp_dir, 'dist')
+        result = os.listdir(dist_folder)
+        self.assertEqual(result, ['fake-1.0.tar.gz'])
+
+        os.remove(join(dist_folder, 'fake-1.0.tar.gz'))
+
+    @unittest.skipUnless(zlib, "requires zlib")
     def test_add_defaults(self):
 
         # http://bugs.python.org/issue2279
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
 Core and Builtins
 -----------------
 
+- Issue #11638: Unicode strings in 'name' and 'version' no longer cause
+  UnicodeDecodeErrors.
+
 - Fix the fix for issue #12149: it was incorrect, although it had the side
   effect of appearing to resolve the issue.  Thanks to Mark Shannon for
   noticing.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list