Skip to content

Commit 54c8c8b

Browse files
committed
CLI: do not raise a ScreenShotError when -q, or --quiet, is used
1 parent c35bc06 commit 54c8c8b

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ History:
33
<see Git checking messages for history>
44

55
8.0.1 2023/xx/xx
6+
- CLI: do not raise a ScreenShotError when -q, or --quiet, is used but return 1
67
- tests: fix test_entry_point() with multiple monitors having the same resolution
78

89
8.0.0 2023/04/09

mss/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def main(args: List[str], /) -> int:
7575
print(os.path.realpath(file_name))
7676
return 0
7777
except ScreenShotError:
78-
return 1
78+
if options.quiet:
79+
return 1
80+
raise
7981

8082

8183
if __name__ == "__main__": # pragma: nocover

mss/tests/test_implementation.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import os.path
77
import platform
8+
from unittest.mock import patch
89

910
import pytest
1011

@@ -83,10 +84,10 @@ def test_entry_point(with_cursor: bool, capsys):
8384

8485
from mss.__main__ import main as entry_point
8586

86-
def main(*args):
87+
def main(*args: str, ret: int = 0) -> None:
8788
if with_cursor:
8889
args = args + ("--with-cursor",)
89-
entry_point(args)
90+
assert entry_point(args) == ret
9091

9192
for opt in ("-m", "--monitor"):
9293
main(opt, "1")
@@ -133,11 +134,31 @@ def main(*args):
133134

134135
coordinates = "2,12,40"
135136
for opt in ("-c", "--coordinates"):
136-
main(opt, coordinates)
137+
main(opt, coordinates, ret=2)
137138
out, _ = capsys.readouterr()
138139
assert out == "Coordinates syntax: top, left, width, height\n"
139140

140141

142+
@patch("mss.base.MSSBase.monitors", new=[])
143+
@pytest.mark.parametrize("quiet", [False, True])
144+
def test_entry_point_error(quiet: bool, capsys):
145+
from mss.__main__ import main as entry_point
146+
147+
def main(*args: str) -> int:
148+
if quiet:
149+
args = args + ("--quiet",)
150+
return entry_point(args)
151+
152+
if quiet:
153+
assert main() == 1
154+
out, err = capsys.readouterr()
155+
assert not out
156+
assert not err
157+
else:
158+
with pytest.raises(ScreenShotError):
159+
main()
160+
161+
141162
def test_grab_with_tuple(pixel_ratio):
142163
left = 100
143164
top = 100

0 commit comments

Comments
 (0)