mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-22 21:24:46 +03:00
Use command argument
This commit is contained in:
parent
dd4b61c83c
commit
b6c6ed6b66
|
@ -12,6 +12,7 @@ from .helper import (
|
|||
assert_image_similar,
|
||||
assert_not_all_same,
|
||||
hopper,
|
||||
is_mingw,
|
||||
is_win32,
|
||||
)
|
||||
|
||||
|
@ -609,6 +610,24 @@ class TestImage:
|
|||
|
||||
assert not fp.closed
|
||||
|
||||
def test_show_command(self, tmp_path):
|
||||
# Arrange
|
||||
temp_file = str(tmp_path / "opened")
|
||||
with open(temp_file, "a") as f:
|
||||
f.close()
|
||||
assert os.path.exists(temp_file)
|
||||
im = hopper()
|
||||
|
||||
# Act
|
||||
im.show(
|
||||
command=("del" if (is_win32() and not is_mingw()) else "rm")
|
||||
+ " "
|
||||
+ temp_file
|
||||
)
|
||||
|
||||
# Assert
|
||||
assert not os.path.exists(temp_file)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_module", [PIL, Image],
|
||||
)
|
||||
|
|
|
@ -44,9 +44,19 @@ def show(image, title=None, **options):
|
|||
:param \**options: Additional viewer options.
|
||||
:returns: True if a suitable viewer was found, false otherwise.
|
||||
"""
|
||||
for viewer in _viewers:
|
||||
if viewer.show(image, title=title, **options):
|
||||
return 1
|
||||
command = options.get("command")
|
||||
if command:
|
||||
|
||||
class CommandViewer(Viewer):
|
||||
def get_command(self, file):
|
||||
return command + " " + file
|
||||
|
||||
CommandViewer().show(image)
|
||||
return 1
|
||||
else:
|
||||
for viewer in _viewers:
|
||||
if viewer.show(image, title=title, **options):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user