|
5 | 5 | import os |
6 | 6 | import os.path |
7 | 7 | import platform |
| 8 | +from unittest.mock import patch |
8 | 9 |
|
9 | 10 | import pytest |
10 | 11 |
|
@@ -83,10 +84,10 @@ def test_entry_point(with_cursor: bool, capsys): |
83 | 84 |
|
84 | 85 | from mss.__main__ import main as entry_point |
85 | 86 |
|
86 | | - def main(*args): |
| 87 | + def main(*args: str, ret: int = 0) -> None: |
87 | 88 | if with_cursor: |
88 | 89 | args = args + ("--with-cursor",) |
89 | | - entry_point(args) |
| 90 | + assert entry_point(args) == ret |
90 | 91 |
|
91 | 92 | for opt in ("-m", "--monitor"): |
92 | 93 | main(opt, "1") |
@@ -133,11 +134,31 @@ def main(*args): |
133 | 134 |
|
134 | 135 | coordinates = "2,12,40" |
135 | 136 | for opt in ("-c", "--coordinates"): |
136 | | - main(opt, coordinates) |
| 137 | + main(opt, coordinates, ret=2) |
137 | 138 | out, _ = capsys.readouterr() |
138 | 139 | assert out == "Coordinates syntax: top, left, width, height\n" |
139 | 140 |
|
140 | 141 |
|
| 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 | + |
141 | 162 | def test_grab_with_tuple(pixel_ratio): |
142 | 163 | left = 100 |
143 | 164 | top = 100 |
|
0 commit comments