(self)
| 1726 | @unittest.skipUnless(shutil.which('tar'), |
| 1727 | 'Need the tar command to run') |
| 1728 | def test_tarfile_vs_tar(self): |
| 1729 | root_dir, base_dir = self._create_files() |
| 1730 | base_name = os.path.join(self.mkdtemp(), 'archive') |
| 1731 | with no_chdir: |
| 1732 | tarball = make_archive(base_name, 'gztar', root_dir, base_dir) |
| 1733 | |
| 1734 | # check if the compressed tarball was created |
| 1735 | self.assertEqual(tarball, base_name + '.tar.gz') |
| 1736 | self.assertTrue(os.path.isfile(tarball)) |
| 1737 | |
| 1738 | # now create another tarball using `tar` |
| 1739 | tarball2 = os.path.join(root_dir, 'archive2.tar') |
| 1740 | tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir] |
| 1741 | if sys.platform == 'darwin': |
| 1742 | # macOS tar can include extended attributes, |
| 1743 | # ACLs and other mac specific metadata into the |
| 1744 | # archive (an recentish version of the OS). |
| 1745 | # |
| 1746 | # This feature can be disabled with the |
| 1747 | # '--no-mac-metadata' option on macOS 11 or |
| 1748 | # later. |
| 1749 | import platform |
| 1750 | if int(platform.mac_ver()[0].split('.')[0]) >= 11: |
| 1751 | tar_cmd.insert(1, '--no-mac-metadata') |
| 1752 | subprocess.check_call(tar_cmd, cwd=root_dir, |
| 1753 | stdout=subprocess.DEVNULL) |
| 1754 | |
| 1755 | self.assertTrue(os.path.isfile(tarball2)) |
| 1756 | # let's compare both tarballs |
| 1757 | self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2)) |
| 1758 | |
| 1759 | # trying an uncompressed one |
| 1760 | with no_chdir: |
| 1761 | tarball = make_archive(base_name, 'tar', root_dir, base_dir) |
| 1762 | self.assertEqual(tarball, base_name + '.tar') |
| 1763 | self.assertTrue(os.path.isfile(tarball)) |
| 1764 | |
| 1765 | # now for a dry_run |
| 1766 | with no_chdir: |
| 1767 | tarball = make_archive(base_name, 'tar', root_dir, base_dir, |
| 1768 | dry_run=True) |
| 1769 | self.assertEqual(tarball, base_name + '.tar') |
| 1770 | self.assertTrue(os.path.isfile(tarball)) |
| 1771 | |
| 1772 | @support.requires_zlib() |
| 1773 | def test_make_zipfile(self): |
nothing calls this directly
no test coverage detected