From 665293e9b9ddf19264f55e26498fc7092d9c96be Mon Sep 17 00:00:00 2001 From: hugovk Date: Thu, 17 Jul 2014 02:38:57 +0300 Subject: [PATCH 1/3] More tests for XpmImagePlugin.py --- Tests/test_file_xpm.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index d79f5fbda..7eef04676 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -16,6 +16,17 @@ class TestFileXpm(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "XPM") + def test_load_read(self): + # Arrange + im = Image.open(file) + dummy_bytes = 1 + + # Act + data = im.load_read(dummy_bytes) + + # Assert + self.assertEqual(len(data), 16384) + if __name__ == '__main__': unittest.main() From 8db043b35f7d587d4a5db23e72db3a335dc88eae Mon Sep 17 00:00:00 2001 From: hugovk Date: Thu, 17 Jul 2014 02:40:14 +0300 Subject: [PATCH 2/3] flake8 --- PIL/XpmImagePlugin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PIL/XpmImagePlugin.py b/PIL/XpmImagePlugin.py index 701a23b64..517580895 100644 --- a/PIL/XpmImagePlugin.py +++ b/PIL/XpmImagePlugin.py @@ -29,6 +29,7 @@ xpm_head = re.compile(b"\"([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*)") def _accept(prefix): return prefix[:9] == b"/* XPM */" + ## # Image plugin for X11 pixel maps. @@ -86,9 +87,9 @@ class XpmImageFile(ImageFile.ImageFile): elif rgb[0:1] == b"#": # FIXME: handle colour names (see ImagePalette.py) rgb = int(rgb[1:], 16) - palette[c] = o8((rgb >> 16) & 255) +\ - o8((rgb >> 8) & 255) +\ - o8(rgb & 255) + palette[c] = (o8((rgb >> 16) & 255) + + o8((rgb >> 8) & 255) + + o8(rgb & 255)) else: # unknown colour raise ValueError("cannot read this XPM file") From 14d1ac6389fc47f9c44210991cce990f68d0b185 Mon Sep 17 00:00:00 2001 From: hugovk Date: Thu, 17 Jul 2014 23:23:50 +0300 Subject: [PATCH 3/3] Rename bad variable name 'file' to 'TEST_FILE', remove unused 'data' variable --- Tests/test_file_xpm.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index 7eef04676..16a811a4c 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -3,14 +3,13 @@ from helper import unittest, PillowTestCase from PIL import Image # sample ppm stream -file = "Tests/images/lena.xpm" -data = open(file, "rb").read() +TEST_FILE = "Tests/images/lena.xpm" class TestFileXpm(PillowTestCase): def test_sanity(self): - im = Image.open(file) + im = Image.open(TEST_FILE) im.load() self.assertEqual(im.mode, "P") self.assertEqual(im.size, (128, 128)) @@ -18,7 +17,7 @@ class TestFileXpm(PillowTestCase): def test_load_read(self): # Arrange - im = Image.open(file) + im = Image.open(TEST_FILE) dummy_bytes = 1 # Act