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 79 80 81 82 83 84 85 86 87 88 89 90
|
import sys
from pathlib import Path
import pytest
from easyprocess import EasyProcess
from pyvirtualdisplay import Display
from pyvirtualdisplay.smartdisplay import DisplayTimeoutError, SmartDisplay
python = sys.executable
def test_disp():
with Display():
d = SmartDisplay(visible=True).start().stop()
# assert d.return_code == 0
assert not d.is_alive()
d = SmartDisplay(visible=False).start().stop()
# assert d.return_code == 0
assert not d.is_alive()
def test_slowshot():
disp = SmartDisplay(visible=False).start()
py = Path(__file__).parent / ("slowgui.py")
proc = EasyProcess([python, py]).start()
img = disp.waitgrab()
proc.stop()
disp.stop()
assert img is not None
def test_slowshot_with():
disp = SmartDisplay(visible=False)
py = Path(__file__).parent / ("slowgui.py")
proc = EasyProcess([python, py])
with disp:
with proc:
img = disp.waitgrab()
assert img is not None
def test_slowshot_nocrop():
disp = SmartDisplay(visible=False)
py = Path(__file__).parent / ("slowgui.py")
proc = EasyProcess([python, py])
with disp:
with proc:
img = disp.waitgrab(autocrop=False)
assert img is not None
def test_empty():
disp = SmartDisplay(visible=False)
proc = EasyProcess([python])
with disp:
with proc:
with pytest.raises(Exception):
disp.waitgrab(timeout=10)
def test_empty_nocrop():
disp = SmartDisplay(visible=False)
proc = EasyProcess([python])
with disp:
with proc:
with pytest.raises(Exception):
disp.waitgrab(autocrop=False, timeout=10)
def test_slowshot_timeout():
disp = SmartDisplay(visible=False)
py = Path(__file__).parent / ("slowgui.py")
proc = EasyProcess([python, py])
with disp:
with proc:
with pytest.raises(DisplayTimeoutError):
disp.waitgrab(timeout=1)
def test_slowshot_timeout_nocrop():
disp = SmartDisplay(visible=False)
py = Path(__file__).parent / ("slowgui.py")
proc = EasyProcess([python, py])
with disp:
with proc:
with pytest.raises(DisplayTimeoutError):
disp.waitgrab(timeout=1, autocrop=False)
|