Fix formatting

This commit is contained in:
Adian Kozlica 2025-03-28 17:18:09 +01:00
parent 722283e819
commit eeb494abf7
2 changed files with 7 additions and 6 deletions

View File

@ -40,7 +40,11 @@ class TestImageGrab:
@pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB") @pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB")
def test_grab_no_xcb(self) -> None: def test_grab_no_xcb(self) -> None:
if sys.platform not in ("win32", "darwin") and not shutil.which("gnome-screenshot") and not shutil.which('spectacle'): if (
sys.platform not in ("win32", "darwin")
and not shutil.which("gnome-screenshot")
and not shutil.which("spectacle")
):
with pytest.raises(OSError) as e: with pytest.raises(OSError) as e:
ImageGrab.grab() ImageGrab.grab()
assert str(e.value).startswith("Pillow was built without XCB support") assert str(e.value).startswith("Pillow was built without XCB support")

View File

@ -77,10 +77,7 @@ def grab(
raise OSError(msg) raise OSError(msg)
size, data = Image.core.grabscreen_x11(display_name) size, data = Image.core.grabscreen_x11(display_name)
except OSError: except OSError:
if ( if display_name is None and sys.platform not in ("darwin", "win32"):
display_name is None
and sys.platform not in ("darwin", "win32")
):
fh, filepath = tempfile.mkstemp(".png") fh, filepath = tempfile.mkstemp(".png")
os.close(fh) os.close(fh)
if shutil.which("gnome-screenshot"): if shutil.which("gnome-screenshot"):
@ -89,7 +86,7 @@ def grab(
subprocess.call(["spectacle", "-n", "-b", "-f", "-o", filepath]) subprocess.call(["spectacle", "-n", "-b", "-f", "-o", filepath])
else: else:
os.unlink(filepath) os.unlink(filepath)
raise raise
im = Image.open(filepath) im = Image.open(filepath)
im.load() im.load()
os.unlink(filepath) os.unlink(filepath)