forked from BoboTiG/python-mss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_get_pixels.py
More file actions
46 lines (36 loc) · 1.33 KB
/
test_get_pixels.py
File metadata and controls
46 lines (36 loc) · 1.33 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
# coding: utf-8
import pytest
from mss.base import ScreenShot
from mss.exception import ScreenShotError
def test_grab_monitor(sct):
for mon in sct.monitors:
image = sct.grab(mon)
assert isinstance(image, ScreenShot)
assert isinstance(image.raw, bytearray)
assert isinstance(image.rgb, bytes)
def test_grab_part_of_screen(sct):
monitor = {"top": 160, "left": 160, "width": 160, "height": 160}
image = sct.grab(monitor)
assert isinstance(image, ScreenShot)
assert isinstance(image.raw, bytearray)
assert isinstance(image.rgb, bytes)
assert image.top == 160
assert image.left == 160
assert image.width == 160
assert image.height == 160
def test_grab_part_of_screen_rounded(sct):
monitor = {"top": 160, "left": 160, "width": 161, "height": 159}
image = sct.grab(monitor)
assert isinstance(image, ScreenShot)
assert isinstance(image.raw, bytearray)
assert isinstance(image.rgb, bytes)
assert image.top == 160
assert image.left == 160
assert image.width == 161
assert image.height == 159
def test_grab_individual_pixels(sct):
monitor = {"top": 160, "left": 160, "width": 222, "height": 42}
image = sct.grab(monitor)
assert isinstance(image.pixel(0, 0), tuple)
with pytest.raises(ScreenShotError):
image.pixel(image.width + 1, 12)