def assertXServer(self):
"""Assert that we can connect to an X-Server that is listening
on the display set in the DISPLAY environment variable."""
display = Display.get()
try:
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.settimeout(1)
sock.connect("/tmp/.X11-unix/X%d" % (int(display)))
sock.sendall(b"l\0\x0b\0\0\0\0\0\0\0\0\0")
# ^-- little-endian
# ^^^^--- protocol version (11)
response = sock.recv(8, socket.MSG_WAITALL)
self.assertEqual(len(response), 8)
self.assertNotEqual(response[0], 0) # 0 = Failure
except Exception as e:
raise AssertionError("No X-Server") from e
评论列表
文章目录