forked from BoboTiG/python-mss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_macos.py
More file actions
63 lines (50 loc) · 1.52 KB
/
test_macos.py
File metadata and controls
63 lines (50 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding: utf-8
import ctypes.util
import platform
import pytest
import mss
from mss.exception import ScreenShotError
if platform.system().lower() != "darwin":
pytestmark = pytest.mark.skip
def test_repr():
from mss.darwin import CGSize, CGPoint, CGRect
# CGPoint
point = CGPoint(2.0, 1.0)
ref = CGPoint()
ref.x = 2.0
ref.y = 1.0
assert repr(point) == repr(ref)
# CGSize
size = CGSize(2.0, 1.0)
ref = CGSize()
ref.width = 2.0
ref.height = 1.0
assert repr(size) == repr(ref)
# CGRect
rect = CGRect(point, size)
ref = CGRect()
ref.origin.x = 2.0
ref.origin.y = 1.0
ref.size.width = 2.0
ref.size.height = 1.0
assert repr(rect) == repr(ref)
def test_implementation(monkeypatch):
# No `CoreGraphics` library
monkeypatch.setattr(ctypes.util, "find_library", lambda x: None)
with pytest.raises(ScreenShotError):
mss.mss()
monkeypatch.undo()
with mss.mss() as sct:
# Test monitor's rotation
original = sct.monitors[1]
monkeypatch.setattr(sct.core, "CGDisplayRotation", lambda x: -90.0)
sct._monitors = []
modified = sct.monitors[1]
assert original["width"] == modified["height"]
assert original["height"] == modified["width"]
monkeypatch.undo()
# Test bad data retreival
monkeypatch.setattr(sct.core, "CGWindowListCreateImage", lambda *args: None)
with pytest.raises(ScreenShotError):
sct.grab(sct.monitors[1])
monkeypatch.undo()