Use command argument

This commit is contained in:
Andrew Murray 2020-06-14 17:36:15 +10:00
parent dd4b61c83c
commit b6c6ed6b66
2 changed files with 32 additions and 3 deletions

View File

@ -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],
)

View File

@ -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