Skip to content

Commit ae0d752

Browse files
Issue #25018: Fixed testing shutil.make_archive() with relative base_name on
Windows. The test now makes sense on non-Windows. Added similar test for zip format.
2 parents c8c47f5 + eba8fee commit ae0d752

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

Lib/test/test_shutil.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,13 @@ def test_make_tarball(self):
974974
tmpdir2 = self.mkdtemp()
975975
# force shutil to create the directory
976976
os.rmdir(tmpdir2)
977-
unittest.skipUnless(splitdrive(root_dir)[0] == splitdrive(tmpdir2)[0],
978-
"source and target should be on same drive")
977+
# working with relative paths
978+
work_dir = os.path.dirname(tmpdir2)
979+
rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
980+
base_name = os.path.join(work_dir, rel_base_name)
979981

980-
base_name = os.path.join(tmpdir2, 'archive')
981-
982-
# working with relative paths to avoid tar warnings
983-
tarball = make_archive(splitdrive(base_name)[1], 'gztar', root_dir, '.')
982+
with support.change_cwd(work_dir):
983+
tarball = make_archive(rel_base_name, 'gztar', root_dir, '.')
984984

985985
# check if the compressed tarball was created
986986
self.assertEqual(tarball, base_name + '.tar.gz')
@@ -992,7 +992,8 @@ def test_make_tarball(self):
992992
'./file1', './file2', './sub/file3'])
993993

994994
# trying an uncompressed one
995-
tarball = make_archive(splitdrive(base_name)[1], 'tar', root_dir, '.')
995+
with support.change_cwd(work_dir):
996+
tarball = make_archive(rel_base_name, 'tar', root_dir, '.')
996997
self.assertEqual(tarball, base_name + '.tar')
997998
self.assertTrue(os.path.isfile(tarball))
998999
self.assertTrue(tarfile.is_tarfile(tarball))
@@ -1059,8 +1060,17 @@ def test_tarfile_vs_tar(self):
10591060
def test_make_zipfile(self):
10601061
# creating something to zip
10611062
root_dir, base_dir = self._create_files()
1062-
base_name = os.path.join(self.mkdtemp(), 'archive')
1063-
res = make_archive(base_name, 'zip', root_dir, 'dist')
1063+
1064+
tmpdir2 = self.mkdtemp()
1065+
# force shutil to create the directory
1066+
os.rmdir(tmpdir2)
1067+
# working with relative paths
1068+
work_dir = os.path.dirname(tmpdir2)
1069+
rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
1070+
base_name = os.path.join(work_dir, rel_base_name)
1071+
1072+
with support.change_cwd(work_dir):
1073+
res = make_archive(rel_base_name, 'zip', root_dir, 'dist')
10641074

10651075
self.assertEqual(res, base_name + '.zip')
10661076
self.assertTrue(os.path.isfile(res))

0 commit comments

Comments
 (0)