(self, f, compression)
| 728 | fp.write(self.data) |
| 729 | |
| 730 | def zip_test(self, f, compression): |
| 731 | # Create the ZIP archive |
| 732 | with zipfile.ZipFile(f, "w", compression, allowZip64=True) as zipfp: |
| 733 | zipfp.write(TESTFN, "another.name") |
| 734 | zipfp.write(TESTFN, TESTFN) |
| 735 | zipfp.writestr("strfile", self.data) |
| 736 | |
| 737 | # Read the ZIP archive |
| 738 | with zipfile.ZipFile(f, "r", compression) as zipfp: |
| 739 | self.assertEqual(zipfp.read(TESTFN), self.data) |
| 740 | self.assertEqual(zipfp.read("another.name"), self.data) |
| 741 | self.assertEqual(zipfp.read("strfile"), self.data) |
| 742 | |
| 743 | # Print the ZIP directory |
| 744 | fp = io.StringIO() |
| 745 | zipfp.printdir(fp) |
| 746 | |
| 747 | directory = fp.getvalue() |
| 748 | lines = directory.splitlines() |
| 749 | self.assertEqual(len(lines), 4) # Number of files + header |
| 750 | |
| 751 | self.assertIn('File Name', lines[0]) |
| 752 | self.assertIn('Modified', lines[0]) |
| 753 | self.assertIn('Size', lines[0]) |
| 754 | |
| 755 | fn, date, time_, size = lines[1].split() |
| 756 | self.assertEqual(fn, 'another.name') |
| 757 | self.assertTrue(time.strptime(date, '%Y-%m-%d')) |
| 758 | self.assertTrue(time.strptime(time_, '%H:%M:%S')) |
| 759 | self.assertEqual(size, str(len(self.data))) |
| 760 | |
| 761 | # Check the namelist |
| 762 | names = zipfp.namelist() |
| 763 | self.assertEqual(len(names), 3) |
| 764 | self.assertIn(TESTFN, names) |
| 765 | self.assertIn("another.name", names) |
| 766 | self.assertIn("strfile", names) |
| 767 | |
| 768 | # Check infolist |
| 769 | infos = zipfp.infolist() |
| 770 | names = [i.filename for i in infos] |
| 771 | self.assertEqual(len(names), 3) |
| 772 | self.assertIn(TESTFN, names) |
| 773 | self.assertIn("another.name", names) |
| 774 | self.assertIn("strfile", names) |
| 775 | for i in infos: |
| 776 | self.assertEqual(i.file_size, len(self.data)) |
| 777 | |
| 778 | # check getinfo |
| 779 | for nm in (TESTFN, "another.name", "strfile"): |
| 780 | info = zipfp.getinfo(nm) |
| 781 | self.assertEqual(info.filename, nm) |
| 782 | self.assertEqual(info.file_size, len(self.data)) |
| 783 | |
| 784 | # Check that testzip thinks the archive is valid |
| 785 | self.assertIsNone(zipfp.testzip()) |
| 786 | |
| 787 | def test_basic(self): |
no test coverage detected