py3k: Add TarIO test

Not too convinced of the size fix. While it works against my file, I'm not
sure someone would have accidentally been an index off and not noticed.
This commit is contained in:
Brian Crowell 2012-10-25 07:57:39 -05:00 committed by Brian Crowell
parent 49b0d1563e
commit d6a0dec15b
3 changed files with 24 additions and 2 deletions

BIN
Images/lena.tar Normal file

Binary file not shown.

View File

@ -39,13 +39,13 @@ class TarIO(ContainerIO.ContainerIO):
raise IOError("unexpected end of tar file") raise IOError("unexpected end of tar file")
name = s[:100].decode('utf-8') name = s[:100].decode('utf-8')
i = name.find(b'\0') i = name.find('\0')
if i == 0: if i == 0:
raise IOError("cannot find subfile") raise IOError("cannot find subfile")
if i > 0: if i > 0:
name = name[:i] name = name[:i]
size = int(s[124:136], 8) size = int(s[124:135], 8)
if file == name: if file == name:
break break

22
Tests/test_file_tar.py Normal file
View File

@ -0,0 +1,22 @@
from tester import *
from PIL import Image, TarIO
# sample ppm stream
tarfile = "Images/lena.tar"
def test_sanity():
tar = TarIO.TarIO(tarfile, 'lena.png')
im = Image.open(tar)
im.load()
assert_equal(im.mode, "RGB")
assert_equal(im.size, (128, 128))
assert_equal(im.format, "PNG")
tar = TarIO.TarIO(tarfile, 'lena.jpg')
im = Image.open(tar)
im.load()
assert_equal(im.mode, "RGB")
assert_equal(im.size, (128, 128))
assert_equal(im.format, "JPEG")