Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lowres():
with Display():
p = EasyProcess([python, "-m", "pyvirtualdisplay.examples.lowres"]).start()
sleep(1)
assert p.is_alive()
p.stop()
def test_extra_args():
# Unrecognized option
d = Display(extra_args=["willcrash"])
with pytest.raises(XStartError):
d.start()
with Display():
# -c turns off key-click
with Display(visible=True, extra_args=["-c"]) as d:
assert d.is_alive()
assert not d.is_alive()
with XephyrDisplay(extra_args=["-c"]) as d:
assert d.is_alive()
assert not d.is_alive()
def test_disp():
vd = Display().start()
assert vd.is_alive()
# d = Display(visible=True).start().sleep(2).stop()
# .assertEquals(d.return_code, 0)
d = Display(visible=False).start().stop()
assert d.return_code == 0
vd.stop()
assert not vd.is_alive()
def start(self):
self._virtual_display = pyvirtualdisplay.Display(
backend='xvfb', size=(self.width, self.height),
color_depth=self.colordepth, use_xauth=self.xauth,
extra_args=self.args)
self._virtual_display.start()
self.display = self._virtual_display.display
assert self._virtual_display.is_alive()
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):
img = disp.waitgrab(timeout=1)
httpd_thread.daemon = True
httpd_thread.start()
# Start up a virtual display, useful for testing on headless servers.
# -----------------------------------------------------------------------------
VIRTUAL_SIZE = (1024, 2000)
# PhantomJS doesn't need a display
disp = None
if args.virtual and args.browser != "PhantomJS":
from pyvirtualdisplay.smartdisplay import SmartDisplay
try:
disp = SmartDisplay(
visible=0, bgcolor='black', size=VIRTUAL_SIZE).start()
atexit.register(disp.stop)
except:
if disp:
disp.stop()
raise
# Start up the web browser and run the tests.
# ----------------------------------------------------------------------------
from selenium import webdriver
from selenium.common import exceptions as selenium_exceptions
from selenium.webdriver.common.keys import Keys as selenium_keys
driver_arguments = {}
from pyvirtualdisplay.smartdisplay import SmartDisplay
logging.basicConfig(level=logging.DEBUG)
backend1 = "wx"
backend2 = "wx"
with SmartDisplay(visible=False, bgcolor="black") as disp:
disp.pyscreenshot_backend = backend1
with EasyProcess("xmessage test1"):
img1 = disp.waitgrab()
with SmartDisplay(visible=False, bgcolor="black") as disp:
disp.pyscreenshot_backend = backend2
with EasyProcess("xmessage test2"):
img2 = disp.waitgrab()
img1.show()
img2.show()
def test_color_xvfb():
with pytest.raises(XStartError):
vd = Display(color_depth=99).start().stop()
vd = Display(color_depth=16).start().stop()
vd = Display(color_depth=24).start().stop()
vd = Display(color_depth=8).start().stop()
def test_stop_nostart():
with pytest.raises(XStartError):
Display().stop()
def test_is_started():
# d = Display()
# assert not d._is_started
# d.start()
# assert d._is_started
# d.stop()
# assert d._is_started
# with Display() as d:
# assert d._is_started
# assert d._is_started
with XvfbDisplay() as d:
assert d._is_started
assert d._is_started
with Display():
with XephyrDisplay() as d:
assert d._is_started
assert d._is_started