(self)
| 2765 | self.zip.open("test.txt") |
| 2766 | |
| 2767 | def test_seek_tell(self): |
| 2768 | self.zip.setpassword(b"python") |
| 2769 | txt = self.plain |
| 2770 | test_word = b'encryption' |
| 2771 | bloc = txt.find(test_word) |
| 2772 | bloc_len = len(test_word) |
| 2773 | with self.zip.open("test.txt", "r") as fp: |
| 2774 | fp.seek(bloc, os.SEEK_SET) |
| 2775 | self.assertEqual(fp.tell(), bloc) |
| 2776 | fp.seek(-bloc, os.SEEK_CUR) |
| 2777 | self.assertEqual(fp.tell(), 0) |
| 2778 | fp.seek(bloc, os.SEEK_CUR) |
| 2779 | self.assertEqual(fp.tell(), bloc) |
| 2780 | self.assertEqual(fp.read(bloc_len), txt[bloc:bloc+bloc_len]) |
| 2781 | |
| 2782 | # Make sure that the second read after seeking back beyond |
| 2783 | # _readbuffer returns the same content (ie. rewind to the start of |
| 2784 | # the file to read forward to the required position). |
| 2785 | old_read_size = fp.MIN_READ_SIZE |
| 2786 | fp.MIN_READ_SIZE = 1 |
| 2787 | fp._readbuffer = b'' |
| 2788 | fp._offset = 0 |
| 2789 | fp.seek(0, os.SEEK_SET) |
| 2790 | self.assertEqual(fp.tell(), 0) |
| 2791 | fp.seek(bloc, os.SEEK_CUR) |
| 2792 | self.assertEqual(fp.read(bloc_len), txt[bloc:bloc+bloc_len]) |
| 2793 | fp.MIN_READ_SIZE = old_read_size |
| 2794 | |
| 2795 | fp.seek(0, os.SEEK_END) |
| 2796 | self.assertEqual(fp.tell(), len(txt)) |
| 2797 | fp.seek(0, os.SEEK_SET) |
| 2798 | self.assertEqual(fp.tell(), 0) |
| 2799 | |
| 2800 | # Read the file completely to definitely call any eof integrity |
| 2801 | # checks (crc) and make sure they still pass. |
| 2802 | fp.read() |
| 2803 | |
| 2804 | |
| 2805 | class AbstractTestsWithRandomBinaryFiles: |
nothing calls this directly
no test coverage detected