Commit 25720176 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Explicitly test archive name in shutil.make_archive() tests to expose failure

details in issue25018.
parent 2764002b
...@@ -974,10 +974,10 @@ class TestShutil(unittest.TestCase): ...@@ -974,10 +974,10 @@ class TestShutil(unittest.TestCase):
base_name = os.path.join(tmpdir2, 'archive') base_name = os.path.join(tmpdir2, 'archive')
# working with relative paths to avoid tar warnings # working with relative paths to avoid tar warnings
make_archive(splitdrive(base_name)[1], 'gztar', root_dir, '.') tarball = make_archive(splitdrive(base_name)[1], 'gztar', root_dir, '.')
# check if the compressed tarball was created # check if the compressed tarball was created
tarball = base_name + '.tar.gz' self.assertEqual(tarball, base_name + '.tar.gz')
self.assertTrue(os.path.isfile(tarball)) self.assertTrue(os.path.isfile(tarball))
self.assertTrue(tarfile.is_tarfile(tarball)) self.assertTrue(tarfile.is_tarfile(tarball))
with tarfile.open(tarball, 'r:gz') as tf: with tarfile.open(tarball, 'r:gz') as tf:
...@@ -986,9 +986,8 @@ class TestShutil(unittest.TestCase): ...@@ -986,9 +986,8 @@ class TestShutil(unittest.TestCase):
'./file1', './file2', './sub/file3']) './file1', './file2', './sub/file3'])
# trying an uncompressed one # trying an uncompressed one
base_name = os.path.join(tmpdir2, 'archive') tarball = make_archive(splitdrive(base_name)[1], 'tar', root_dir, '.')
make_archive(splitdrive(base_name)[1], 'tar', root_dir, '.') self.assertEqual(tarball, base_name + '.tar')
tarball = base_name + '.tar'
self.assertTrue(os.path.isfile(tarball)) self.assertTrue(os.path.isfile(tarball))
self.assertTrue(tarfile.is_tarfile(tarball)) self.assertTrue(tarfile.is_tarfile(tarball))
with tarfile.open(tarball, 'r') as tf: with tarfile.open(tarball, 'r') as tf:
...@@ -1022,10 +1021,10 @@ class TestShutil(unittest.TestCase): ...@@ -1022,10 +1021,10 @@ class TestShutil(unittest.TestCase):
def test_tarfile_vs_tar(self): def test_tarfile_vs_tar(self):
root_dir, base_dir = self._create_files() root_dir, base_dir = self._create_files()
base_name = os.path.join(self.mkdtemp(), 'archive') base_name = os.path.join(self.mkdtemp(), 'archive')
make_archive(base_name, 'gztar', root_dir, base_dir) tarball = make_archive(base_name, 'gztar', root_dir, base_dir)
# check if the compressed tarball was created # check if the compressed tarball was created
tarball = base_name + '.tar.gz' self.assertEqual(tarball, base_name + '.tar.gz')
self.assertTrue(os.path.isfile(tarball)) self.assertTrue(os.path.isfile(tarball))
# now create another tarball using `tar` # now create another tarball using `tar`
...@@ -1039,13 +1038,14 @@ class TestShutil(unittest.TestCase): ...@@ -1039,13 +1038,14 @@ class TestShutil(unittest.TestCase):
self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2)) self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
# trying an uncompressed one # trying an uncompressed one
make_archive(base_name, 'tar', root_dir, base_dir) tarball = make_archive(base_name, 'tar', root_dir, base_dir)
tarball = base_name + '.tar' self.assertEqual(tarball, base_name + '.tar')
self.assertTrue(os.path.isfile(tarball)) self.assertTrue(os.path.isfile(tarball))
# now for a dry_run # now for a dry_run
make_archive(base_name, 'tar', root_dir, base_dir, dry_run=True) tarball = make_archive(base_name, 'tar', root_dir, base_dir,
tarball = base_name + '.tar' dry_run=True)
self.assertEqual(tarball, base_name + '.tar')
self.assertTrue(os.path.isfile(tarball)) self.assertTrue(os.path.isfile(tarball))
@requires_zlib @requires_zlib
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment