forked from BoboTiG/python-mss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_third_party.py
More file actions
78 lines (56 loc) · 1.98 KB
/
test_third_party.py
File metadata and controls
78 lines (56 loc) · 1.98 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# coding: utf-8
import os
import os.path
import pytest
try:
import numpy
except ImportError:
numpy = None
try:
from PIL import Image
except ImportError:
Image = None
@pytest.mark.skipif(numpy is None, reason="Numpy module not available.")
def test_numpy(sct):
box = {"top": 0, "left": 0, "width": 10, "height": 10}
img = numpy.array(sct.grab(box))
assert len(img) == 10
@pytest.mark.skipif(Image is None, reason="PIL module not available.")
def test_pil(sct):
width, height = 16, 16
box = {"top": 0, "left": 0, "width": width, "height": height}
sct_img = sct.grab(box)
img = Image.frombytes("RGB", sct_img.size, sct_img.rgb)
assert img.mode == "RGB"
assert img.size == sct_img.size
for x in range(width):
for y in range(height):
assert img.getpixel((x, y)) == sct_img.pixel(x, y)
img.save("box.png")
assert os.path.isfile("box.png")
@pytest.mark.skipif(Image is None, reason="PIL module not available.")
def test_pil_bgra(sct):
width, height = 16, 16
box = {"top": 0, "left": 0, "width": width, "height": height}
sct_img = sct.grab(box)
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
assert img.mode == "RGB"
assert img.size == sct_img.size
for x in range(width):
for y in range(height):
assert img.getpixel((x, y)) == sct_img.pixel(x, y)
img.save("box-bgra.png")
assert os.path.isfile("box-bgra.png")
@pytest.mark.skipif(Image is None, reason="PIL module not available.")
def test_pil_not_16_rounded(sct):
width, height = 10, 10
box = {"top": 0, "left": 0, "width": width, "height": height}
sct_img = sct.grab(box)
img = Image.frombytes("RGB", sct_img.size, sct_img.rgb)
assert img.mode == "RGB"
assert img.size == sct_img.size
for x in range(width):
for y in range(height):
assert img.getpixel((x, y)) == sct_img.pixel(x, y)
img.save("box.png")
assert os.path.isfile("box.png")