|
8 | 8 | import pytest |
9 | 9 |
|
10 | 10 | import mss |
| 11 | +import mss.tools |
11 | 12 | from mss.base import MSSBase |
12 | 13 | from mss.exception import ScreenShotError |
13 | 14 | from mss.screenshot import ScreenShot |
@@ -93,3 +94,46 @@ def raise_(): |
93 | 94 | with pytest.raises(ScreenShotError): |
94 | 95 | mss.mss() |
95 | 96 | monkeypatch.undo() |
| 97 | + |
| 98 | + |
| 99 | +def test_grab_with_tuple(sct): |
| 100 | + left = 100 |
| 101 | + top = 100 |
| 102 | + right = 500 |
| 103 | + lower = 500 |
| 104 | + width = right - left # 400px width |
| 105 | + height = lower - top # 400px height |
| 106 | + |
| 107 | + # PIL like |
| 108 | + box = (left, top, right, lower) |
| 109 | + im = sct.grab(box) |
| 110 | + assert im.size == (width, height) |
| 111 | + |
| 112 | + # MSS like |
| 113 | + box2 = {'left': left, 'top': top, 'width': width, 'height': height} |
| 114 | + im2 = sct.grab(box2) |
| 115 | + assert im.size == im2.size |
| 116 | + assert im.pos == im2.pos |
| 117 | + assert im.rgb == im2.rgb |
| 118 | + |
| 119 | + |
| 120 | +def test_grab_with_tuple_percents(sct): |
| 121 | + monitor = sct.monitors[1] |
| 122 | + left = monitor['left'] + monitor['width'] * 5 // 100 # 5% from the left |
| 123 | + top = monitor['top'] + monitor['height'] * 5 // 100 # 5% from the top |
| 124 | + right = left + 500 # 500px |
| 125 | + lower = top + 500 # 500px |
| 126 | + width = right - left |
| 127 | + height = lower - top |
| 128 | + |
| 129 | + # PIL like |
| 130 | + box = (left, top, right, lower) |
| 131 | + im = sct.grab(box) |
| 132 | + assert im.size == (width, height) |
| 133 | + |
| 134 | + # MSS like |
| 135 | + box2 = {'left': left, 'top': top, 'width': width, 'height': height} |
| 136 | + im2 = sct.grab(box2) |
| 137 | + assert im.size == im2.size |
| 138 | + assert im.pos == im2.pos |
| 139 | + assert im.rgb == im2.rgb |
0 commit comments