Skip to content

Commit eba8fee

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.
1 parent a091a82 commit eba8fee

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
@@ -968,13 +968,13 @@ def test_make_tarball(self):
968968
tmpdir2 = self.mkdtemp()
969969
# force shutil to create the directory
970970
os.rmdir(tmpdir2)
971-
unittest.skipUnless(splitdrive(root_dir)[0] == splitdrive(tmpdir2)[0],
972-
"source and target should be on same drive")
971+
# working with relative paths
972+
work_dir = os.path.dirname(tmpdir2)
973+
rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
974+
base_name = os.path.join(work_dir, rel_base_name)
973975

974-
base_name = os.path.join(tmpdir2, 'archive')
975-
976-
# working with relative paths to avoid tar warnings
977-
tarball = make_archive(splitdrive(base_name)[1], 'gztar', root_dir, '.')
976+
with support.change_cwd(work_dir):
977+
tarball = make_archive(rel_base_name, 'gztar', root_dir, '.')
978978

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

988988
# trying an uncompressed one
989-
tarball = make_archive(splitdrive(base_name)[1], 'tar', root_dir, '.')
989+
with support.change_cwd(work_dir):
990+
tarball = make_archive(rel_base_name, 'tar', root_dir, '.')
990991
self.assertEqual(tarball, base_name + '.tar')
991992
self.assertTrue(os.path.isfile(tarball))
992993
self.assertTrue(tarfile.is_tarfile(tarball))
@@ -1053,8 +1054,17 @@ def test_tarfile_vs_tar(self):
10531054
def test_make_zipfile(self):
10541055
# creating something to zip
10551056
root_dir, base_dir = self._create_files()
1056-
base_name = os.path.join(self.mkdtemp(), 'archive')
1057-
res = make_archive(base_name, 'zip', root_dir, 'dist')
1057+
1058+
tmpdir2 = self.mkdtemp()
1059+
# force shutil to create the directory
1060+
os.rmdir(tmpdir2)
1061+
# working with relative paths
1062+
work_dir = os.path.dirname(tmpdir2)
1063+
rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
1064+
base_name = os.path.join(work_dir, rel_base_name)
1065+
1066+
with support.change_cwd(work_dir):
1067+
res = make_archive(rel_base_name, 'zip', root_dir, 'dist')
10581068

10591069
self.assertEqual(res, base_name + '.zip')
10601070
self.assertTrue(os.path.isfile(res))

0 commit comments

Comments
 (0)