diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2007-12-01 21:02:12 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2007-12-01 21:02:12 (GMT) |
commit | 77b2d63b40942087f023999a0329aeea6dd1d6e9 (patch) | |
tree | da814527fb821f1b8fdd0df249e1973ea026605c /Lib/test | |
parent | 3e76d9346b326a10791fcf2b1ea887f8dbfccc80 (diff) | |
download | cpython-77b2d63b40942087f023999a0329aeea6dd1d6e9.zip cpython-77b2d63b40942087f023999a0329aeea6dd1d6e9.tar.gz cpython-77b2d63b40942087f023999a0329aeea6dd1d6e9.tar.bz2 |
Issue #1531: Read fileobj from the current offset, do not seek to
the start.
(will backport to 2.5)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_tarfile.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 1f08258..a280bdd 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -160,6 +160,38 @@ class MiscReadTest(ReadTest): tar = tarfile.open(fileobj=fobj, mode=self.mode) self.assertEqual(tar.name, None) + def test_fileobj_with_offset(self): + # Skip the first member and store values from the second member + # of the testtar. + tar = tarfile.open(self.tarname, mode=self.mode) + tar.next() + t = tar.next() + name = t.name + offset = t.offset + data = tar.extractfile(t).read() + tar.close() + + # Open the testtar and seek to the offset of the second member. + if self.mode.endswith(":gz"): + _open = gzip.GzipFile + elif self.mode.endswith(":bz2"): + _open = bz2.BZ2File + else: + _open = open + fobj = _open(self.tarname, "rb") + fobj.seek(offset) + + # Test if the tarfile starts with the second member. + tar = tar.open(self.tarname, mode="r:", fileobj=fobj) + t = tar.next() + self.assertEqual(t.name, name) + # Read to the end of fileobj and test if seeking back to the + # beginning works. + tar.getmembers() + self.assertEqual(tar.extractfile(t).read(), data, + "seek back did not work") + tar.close() + def test_fail_comp(self): # For Gzip and Bz2 Tests: fail with a ReadError on an uncompressed file. if self.mode == "r:": |