MCPcopy Index your code
hub / github.com/python/cpython / test_make_tarfile

Method test_make_tarfile

Lib/test/test_shutil.py:1640–1679  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1638
1639 @support.requires_zlib()
1640 def test_make_tarfile(self):
1641 root_dir, base_dir = self._create_files()
1642 # Test without base_dir.
1643 with os_helper.temp_cwd(), no_chdir:
1644 base_name = os.path.join('dst', 'archive')
1645 archive = make_archive(base_name, 'tar', root_dir)
1646 # check if the compressed tarball was created
1647 self.assertEqual(archive, os.path.abspath(base_name) + '.tar')
1648 self.assertTrue(os.path.isfile(archive))
1649 self.assertTrue(tarfile.is_tarfile(archive))
1650 with tarfile.open(archive, 'r') as tf:
1651 self.assertCountEqual(tf.getnames(),
1652 ['.', './dist', './dist/sub', './dist/sub2',
1653 './dist/file1', './dist/file2', './dist/sub/file3',
1654 './outer'])
1655
1656 # Test with base_dir.
1657 with os_helper.temp_cwd(), no_chdir:
1658 base_name = os.path.join('dst2', 'archive')
1659 archive = make_archive(base_name, 'tar', root_dir, base_dir)
1660 self.assertEqual(archive, os.path.abspath(base_name) + '.tar')
1661 # check if the uncompressed tarball was created
1662 self.assertTrue(os.path.isfile(archive))
1663 self.assertTrue(tarfile.is_tarfile(archive))
1664 with tarfile.open(archive, 'r') as tf:
1665 self.assertCountEqual(tf.getnames(),
1666 ['dist', 'dist/sub', 'dist/sub2',
1667 'dist/file1', 'dist/file2', 'dist/sub/file3'])
1668
1669 # Test with multi-component base_dir.
1670 with os_helper.temp_cwd(), no_chdir:
1671 base_name = os.path.join('dst3', 'archive')
1672 archive = make_archive(base_name, 'tar', root_dir,
1673 os.path.join(base_dir, 'sub'))
1674 self.assertEqual(archive, os.path.abspath(base_name) + '.tar')
1675 self.assertTrue(os.path.isfile(archive))
1676 self.assertTrue(tarfile.is_tarfile(archive))
1677 with tarfile.open(archive, 'r') as tf:
1678 self.assertCountEqual(tf.getnames(),
1679 ['dist/sub', 'dist/sub/file3'])
1680
1681 @support.requires_zlib()
1682 def test_make_tarfile_without_rootdir(self):

Callers

nothing calls this directly

Calls 10

_create_filesMethod · 0.95
make_archiveFunction · 0.90
assertTrueMethod · 0.80
assertCountEqualMethod · 0.80
getnamesMethod · 0.80
joinMethod · 0.45
assertEqualMethod · 0.45
abspathMethod · 0.45
isfileMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected