From 21beef192a33518ca463ce38437750a3c846aeb2 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 3 Jan 2016 12:20:19 -0800 Subject: [PATCH 1/2] Fixing test failures on python 2.6/windows --- Tests/test_image_getim.py | 9 ++++++++- Tests/test_imagewin_pointers.py | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Tests/test_image_getim.py b/Tests/test_image_getim.py index e83439789..ab0ec781c 100644 --- a/Tests/test_image_getim.py +++ b/Tests/test_image_getim.py @@ -10,7 +10,14 @@ class TestImageGetIm(PillowTestCase): if py3: self.assertIn("PyCapsule", type_repr) - self.assertIsInstance(im.im.id, int) + + try: + #py2.6 + target_types = (int, long) + except: + target_types = (int) + + self.assertIsInstance(im.im.id, target_types) if __name__ == '__main__': diff --git a/Tests/test_imagewin_pointers.py b/Tests/test_imagewin_pointers.py index bf7f4bb7c..05af24acb 100644 --- a/Tests/test_imagewin_pointers.py +++ b/Tests/test_imagewin_pointers.py @@ -72,7 +72,11 @@ if sys.platform.startswith('win32'): memcpy(bp, ctypes.byref(bf), ctypes.sizeof(bf)) memcpy(bp + ctypes.sizeof(bf), ctypes.byref(bi), bi.biSize) memcpy(bp + bf.bfOffBits, pixels, bi.biSizeImage) - return bytearray(buf) + try: + return bytearray(buf) + except: + # py2.6 + return buffer(buf)[:] class TestImageWinPointers(PillowTestCase): def test_pointer(self): From 859ce84976f28ae3ddf80d3d2017b13a8ec27cec Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 3 Jan 2016 13:04:04 -0800 Subject: [PATCH 2/2] Version check rather than try/except --- Tests/test_image_getim.py | 8 ++++---- Tests/test_imagewin_pointers.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/test_image_getim.py b/Tests/test_image_getim.py index ab0ec781c..83c857975 100644 --- a/Tests/test_image_getim.py +++ b/Tests/test_image_getim.py @@ -1,5 +1,5 @@ from helper import unittest, PillowTestCase, hopper, py3 - +import sys class TestImageGetIm(PillowTestCase): @@ -11,10 +11,10 @@ class TestImageGetIm(PillowTestCase): self.assertIn("PyCapsule", type_repr) - try: - #py2.6 + if sys.hexversion < 0x2070000: + # py2.6 x64, windows target_types = (int, long) - except: + else: target_types = (int) self.assertIsInstance(im.im.id, target_types) diff --git a/Tests/test_imagewin_pointers.py b/Tests/test_imagewin_pointers.py index 05af24acb..692868bdf 100644 --- a/Tests/test_imagewin_pointers.py +++ b/Tests/test_imagewin_pointers.py @@ -74,7 +74,7 @@ if sys.platform.startswith('win32'): memcpy(bp + bf.bfOffBits, pixels, bi.biSizeImage) try: return bytearray(buf) - except: + except ValueError: # py2.6 return buffer(buf)[:]