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

Method test_make_zipfile

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

Source from the content-addressed store, hash-verified

1771
1772 @support.requires_zlib()
1773 def test_make_zipfile(self):
1774 root_dir, base_dir = self._create_files()
1775 # Test without base_dir.
1776 with os_helper.temp_cwd(), no_chdir:
1777 base_name = os.path.join('dst', 'archive')
1778 archive = make_archive(base_name, 'zip', root_dir)
1779 self.assertEqual(archive, os.path.abspath(base_name) + '.zip')
1780 self.assertTrue(os.path.isfile(archive))
1781 self.assertTrue(zipfile.is_zipfile(archive))
1782 with zipfile.ZipFile(archive) as zf:
1783 self.assertCountEqual(zf.namelist(),
1784 ['dist/', 'dist/sub/', 'dist/sub2/',
1785 'dist/file1', 'dist/file2', 'dist/sub/file3',
1786 'outer'])
1787
1788 # Test with base_dir.
1789 with os_helper.temp_cwd(), no_chdir:
1790 base_name = os.path.join('dst2', 'archive')
1791 archive = make_archive(base_name, 'zip', root_dir, base_dir)
1792 self.assertEqual(archive, os.path.abspath(base_name) + '.zip')
1793 self.assertTrue(os.path.isfile(archive))
1794 self.assertTrue(zipfile.is_zipfile(archive))
1795 with zipfile.ZipFile(archive) as zf:
1796 self.assertCountEqual(zf.namelist(),
1797 ['dist/', 'dist/sub/', 'dist/sub2/',
1798 'dist/file1', 'dist/file2', 'dist/sub/file3'])
1799
1800 # Test with multi-component base_dir.
1801 with os_helper.temp_cwd(), no_chdir:
1802 base_name = os.path.join('dst3', 'archive')
1803 archive = make_archive(base_name, 'zip', root_dir,
1804 os.path.join(base_dir, 'sub'))
1805 self.assertEqual(archive, os.path.abspath(base_name) + '.zip')
1806 self.assertTrue(os.path.isfile(archive))
1807 self.assertTrue(zipfile.is_zipfile(archive))
1808 with zipfile.ZipFile(archive) as zf:
1809 self.assertCountEqual(zf.namelist(),
1810 ['dist/sub/', 'dist/sub/file3'])
1811
1812 @support.requires_zlib()
1813 def test_make_zipfile_without_rootdir(self):

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected