mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-02 11:30:11 +03:00
Added running_in_another_thread()
This commit is contained in:
parent
16372dd951
commit
1df561869f
|
@ -4,6 +4,7 @@ Helper functions.
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
@ -29,6 +30,8 @@ if os.environ.get("SHOW_ERRORS"):
|
|||
elif "GITHUB_ACTIONS" in os.environ:
|
||||
uploader = "github_actions"
|
||||
|
||||
already_running = []
|
||||
|
||||
|
||||
def upload(a: Image.Image, b: Image.Image) -> str | None:
|
||||
if uploader == "show":
|
||||
|
@ -165,6 +168,18 @@ def assert_tuple_approx_equal(
|
|||
pytest.fail(msg + ": " + repr(actuals) + " != " + repr(targets))
|
||||
|
||||
|
||||
def running_in_another_thread() -> bool:
|
||||
frameInfo = inspect.stack()[1]
|
||||
identifier = (
|
||||
frameInfo.filename + ":" + frameInfo.function + ":" + str(frameInfo.lineno)
|
||||
)
|
||||
if identifier in already_running:
|
||||
return True
|
||||
|
||||
already_running.append(identifier)
|
||||
return False
|
||||
|
||||
|
||||
def skip_unless_feature(feature: str) -> pytest.MarkDecorator:
|
||||
reason = f"{feature} not available"
|
||||
return pytest.mark.skipif(not features.check(feature), reason=reason)
|
||||
|
|
|
@ -6,7 +6,7 @@ import pytest
|
|||
|
||||
from PIL import Image
|
||||
|
||||
from .helper import is_pypy
|
||||
from .helper import is_pypy, running_in_another_thread
|
||||
|
||||
|
||||
def test_get_stats() -> None:
|
||||
|
@ -48,6 +48,9 @@ class TestCoreMemory:
|
|||
assert alignment > 0
|
||||
|
||||
def test_set_alignment(self) -> None:
|
||||
if running_in_another_thread():
|
||||
return
|
||||
|
||||
for i in [1, 2, 4, 8, 16, 32]:
|
||||
Image.core.set_alignment(i)
|
||||
alignment = Image.core.get_alignment()
|
||||
|
|
|
@ -7,7 +7,7 @@ import pytest
|
|||
|
||||
from PIL import BufrStubImagePlugin, Image, ImageFile
|
||||
|
||||
from .helper import hopper
|
||||
from .helper import hopper, running_in_another_thread
|
||||
|
||||
TEST_FILE = "Tests/images/gfs.t06z.rassda.tm00.bufr_d"
|
||||
|
||||
|
@ -70,6 +70,9 @@ def test_handler(tmp_path: Path) -> None:
|
|||
def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None:
|
||||
self.saved = True
|
||||
|
||||
if running_in_another_thread():
|
||||
return
|
||||
|
||||
handler = TestHandler()
|
||||
BufrStubImagePlugin.register_handler(handler)
|
||||
with Image.open(TEST_FILE) as im:
|
||||
|
|
|
@ -7,7 +7,7 @@ import pytest
|
|||
|
||||
from PIL import GribStubImagePlugin, Image, ImageFile
|
||||
|
||||
from .helper import hopper
|
||||
from .helper import hopper, running_in_another_thread
|
||||
|
||||
TEST_FILE = "Tests/images/WAlaska.wind.7days.grb"
|
||||
|
||||
|
@ -70,6 +70,9 @@ def test_handler(tmp_path: Path) -> None:
|
|||
def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None:
|
||||
self.saved = True
|
||||
|
||||
if running_in_another_thread():
|
||||
return
|
||||
|
||||
handler = TestHandler()
|
||||
GribStubImagePlugin.register_handler(handler)
|
||||
with Image.open(TEST_FILE) as im:
|
||||
|
|
|
@ -8,6 +8,8 @@ import pytest
|
|||
|
||||
from PIL import Hdf5StubImagePlugin, Image, ImageFile
|
||||
|
||||
from .helper import running_in_another_thread
|
||||
|
||||
TEST_FILE = "Tests/images/hdf5.h5"
|
||||
|
||||
|
||||
|
@ -72,6 +74,9 @@ def test_handler(tmp_path: Path) -> None:
|
|||
def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None:
|
||||
self.saved = True
|
||||
|
||||
if running_in_another_thread():
|
||||
return
|
||||
|
||||
handler = TestHandler()
|
||||
Hdf5StubImagePlugin.register_handler(handler)
|
||||
with Image.open(TEST_FILE) as im:
|
||||
|
|
|
@ -8,7 +8,7 @@ import pytest
|
|||
|
||||
from PIL import Image, ImageFile, WmfImagePlugin
|
||||
|
||||
from .helper import assert_image_similar_tofile, hopper
|
||||
from .helper import assert_image_similar_tofile, hopper, running_in_another_thread
|
||||
|
||||
|
||||
def test_load_raw() -> None:
|
||||
|
@ -45,6 +45,9 @@ def test_register_handler(tmp_path: Path) -> None:
|
|||
def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None:
|
||||
self.methodCalled = True
|
||||
|
||||
if running_in_another_thread():
|
||||
return
|
||||
|
||||
handler = TestHandler()
|
||||
original_handler = WmfImagePlugin._handler
|
||||
WmfImagePlugin.register_handler(handler)
|
||||
|
|
Loading…
Reference in New Issue
Block a user