Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.

Will backport to 2.5.
This commit is contained in:
Lars Gustäbel 2006-12-27 10:30:46 +00:00
parent 7166232399
commit a7ba6fc548
3 changed files with 17 additions and 0 deletions

View file

@ -648,6 +648,16 @@ class HeaderErrorTest(unittest.TestCase):
b = "a" + buf[1:] # manipulate the buffer, so checksum won't match.
self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, b)
class OpenFileobjTest(BaseTest):
# Test for SF bug #1496501.
def test_opener(self):
fobj = StringIO.StringIO("foo\n")
try:
tarfile.open("", "r", fileobj=fobj)
except tarfile.ReadError:
self.assertEqual(fobj.tell(), 0, "fileobj's position has moved")
if bz2:
# Bzip2 TestCases
class ReadTestBzip2(ReadTestGzip):
@ -693,6 +703,7 @@ def test_main():
tests = [
FileModeTest,
HeaderErrorTest,
OpenFileobjTest,
ReadTest,
ReadStreamTest,
ReadDetectTest,