22This is part of the MSS Python's module.
33Source: https://github.com/BoboTiG/python-mss
44"""
5+
6+ import itertools
57import os
68
79import pytest
@@ -21,35 +23,27 @@ def test_grab_monitor():
2123
2224
2325def test_grab_part_of_screen (pixel_ratio ):
24- monitor = {"top" : 160 , "left" : 160 , "width" : 160 , "height" : 160 }
25- with mss (display = os .getenv ("DISPLAY" )) as sct :
26- image = sct .grab (monitor )
27- assert isinstance (image , ScreenShot )
28- assert isinstance (image .raw , bytearray )
29- assert isinstance (image .rgb , bytes )
30- assert image .top == 160
31- assert image .left == 160
32- assert image .width == 160 * pixel_ratio
33- assert image .height == 160 * pixel_ratio
34-
35-
36- def test_grab_part_of_screen_rounded (pixel_ratio ):
37- monitor = {"top" : 160 , "left" : 160 , "width" : 161 , "height" : 159 }
3826 with mss (display = os .getenv ("DISPLAY" )) as sct :
39- image = sct .grab (monitor )
40- assert isinstance (image , ScreenShot )
41- assert isinstance (image .raw , bytearray )
42- assert isinstance (image .rgb , bytes )
43- assert image .top == 160
44- assert image .left == 160
45- assert image .width == 161 * pixel_ratio
46- assert image .height == 159 * pixel_ratio
47-
48-
49- def test_grab_individual_pixels ():
50- monitor = {"top" : 160 , "left" : 160 , "width" : 222 , "height" : 42 }
51- with mss (display = os .getenv ("DISPLAY" )) as sct :
52- image = sct .grab (monitor )
53- assert isinstance (image .pixel (0 , 0 ), tuple )
27+ for width , height in itertools .product (range (1 , 42 ), range (1 , 42 )):
28+ monitor = {"top" : 160 , "left" : 160 , "width" : width , "height" : height }
29+ image = sct .grab (monitor )
30+
31+ assert image .top == 160
32+ assert image .left == 160
33+ assert image .width == width * pixel_ratio
34+ assert image .height == height * pixel_ratio
35+
36+
37+ def test_get_pixel (raw : bytes ):
38+ image = ScreenShot .from_size (bytearray (raw ), 1024 , 768 )
39+ assert image .width == 1024
40+ assert image .height == 768
41+ assert len (image .pixels ) == 768
42+ assert len (image .pixels [0 ]) == 1024
43+
44+ assert image .pixel (0 , 0 ) == (135 , 152 , 192 )
45+ assert image .pixel (image .width // 2 , image .height // 2 ) == (0 , 0 , 0 )
46+ assert image .pixel (image .width - 1 , image .height - 1 ) == (135 , 152 , 192 )
47+
5448 with pytest .raises (ScreenShotError ):
5549 image .pixel (image .width + 1 , 12 )
0 commit comments