-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(weave): Improve Weave patch to support pre-constructed images (#…
…3457) * Fixed the patch * Revision * Revision * Revision * Comment * Comment
- Loading branch information
Showing
3 changed files
with
111 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from tempfile import NamedTemporaryFile | ||
|
||
from weave.initialization import pil_image_thread_safety | ||
|
||
|
||
def test_patching_import_order(): | ||
# This test verifies the correct behavior if patching occurs after the construction | ||
# of an image | ||
assert pil_image_thread_safety._patched | ||
pil_image_thread_safety.undo_threadsafe_patch_to_pil_image() | ||
assert not pil_image_thread_safety._patched | ||
import PIL | ||
|
||
image = PIL.Image.new("RGB", (10, 10)) | ||
with NamedTemporaryFile(suffix=".png") as f: | ||
image.save(f.name) | ||
image = PIL.Image.open(f.name) | ||
|
||
pil_image_thread_safety.apply_threadsafe_patch_to_pil_image() | ||
assert pil_image_thread_safety._patched | ||
|
||
image.crop((0, 0, 10, 10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters