File: test_xvnc.py

package info (click to toggle)
pyvirtualdisplay 3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 388 kB
  • sloc: python: 1,396; sh: 62; ruby: 39; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 1,917 bytes parent folder | download | duplicates (2)
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
import tempfile
from pathlib import Path

from tutil import has_xvnc, rfbport, worker
from vncdotool import api

from pyvirtualdisplay import Display
from pyvirtualdisplay.xvnc import XvncDisplay

if has_xvnc():

    def test_xvnc():
        with tempfile.TemporaryDirectory() as temp_dir:
            vnc_png = Path(temp_dir) / "vnc.png"
            password = "123456"
            passwd_file = Path(temp_dir) / "pwd.txt"
            vncpasswd_generated = b"\x49\x40\x15\xf9\xa3\x5e\x8b\x22"
            passwd_file.write_bytes(vncpasswd_generated)

            if worker() == 0:
                with Display(backend="xvnc"):
                    with api.connect("localhost:0") as client:
                        client.timeout = 1
                        client.captureScreen(vnc_png)
                with XvncDisplay():
                    with api.connect("localhost:0") as client:
                        client.timeout = 1
                        client.captureScreen(vnc_png)

            sconnect = "localhost:%s" % (rfbport() - 5900)
            with Display(backend="xvnc", rfbport=rfbport()):
                with api.connect(sconnect) as client:
                    client.timeout = 1
                    client.captureScreen(vnc_png)
            with XvncDisplay(rfbport=rfbport()):
                with api.connect(sconnect) as client:
                    client.timeout = 1
                    client.captureScreen(vnc_png)

            with Display(backend="xvnc", rfbport=rfbport(), rfbauth=passwd_file):
                with api.connect(sconnect, password=password) as client:
                    client.timeout = 1
                    client.captureScreen(vnc_png)
            with XvncDisplay(rfbport=rfbport(), rfbauth=passwd_file):
                with api.connect(sconnect, password=password) as client:
                    client.timeout = 1
                    client.captureScreen(vnc_png)