From ca3bc290e326e520f029882214ca17b874a68dcb Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 18 Mar 2022 19:57:24 +1100 Subject: [PATCH 1/2] Record resolution instead of requiring ctypes --- Tests/test_file_libtiff.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index a9337f4fc65..d83c584b5da 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -4,7 +4,6 @@ import os import re from collections import namedtuple -from ctypes import c_float import pytest @@ -168,14 +167,11 @@ def test_write_metadata(self, tmp_path): val = original[tag] if tag.endswith("Resolution"): if legacy_api: - assert ( - c_float(val[0][0] / val[0][1]).value - == c_float(value[0][0] / value[0][1]).value + assert val[0][0] / val[0][1] == ( + 4294967295 / 113653537 ), f"{tag} didn't roundtrip" else: - assert ( - c_float(val).value == c_float(value).value - ), f"{tag} didn't roundtrip" + assert val == 37.79000115940079, f"{tag} didn't roundtrip" else: assert val == value, f"{tag} didn't roundtrip" From 2a285d1b1f81d68276c18b0f3fdd6950fb715fec Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 19 Mar 2022 14:46:25 +1100 Subject: [PATCH 2/2] Only import ctypes as needed on Windows --- Tests/test_image_access.py | 3 ++- Tests/test_imagewin_pointers.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index 5bca0858256..617274a576d 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -1,4 +1,3 @@ -import ctypes import os import subprocess import sys @@ -404,6 +403,8 @@ class TestEmbeddable: "not from shell", ) def test_embeddable(self): + import ctypes + with open("embed_pil.c", "w") as fh: fh.write( """ diff --git a/Tests/test_imagewin_pointers.py b/Tests/test_imagewin_pointers.py index c51a66089c8..df130565575 100644 --- a/Tests/test_imagewin_pointers.py +++ b/Tests/test_imagewin_pointers.py @@ -1,4 +1,3 @@ -import ctypes from io import BytesIO from PIL import Image, ImageWin @@ -8,6 +7,7 @@ # see https://github.com/python-pillow/Pillow/pull/1431#issuecomment-144692652 if is_win32(): + import ctypes import ctypes.wintypes class BITMAPFILEHEADER(ctypes.Structure):