File: test_smart_thread.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 (43 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download | duplicates (3)
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
import logging
from threading import Thread
from time import sleep

from easyprocess import EasyProcess
from PIL import ImageChops

from pyvirtualdisplay.smartdisplay import SmartDisplay


def func2(results):
    with SmartDisplay(manage_global_env=False) as disp:
        env = disp.env()
        logging.info("env=%s", env)
        sleep(2)
        with EasyProcess(["xmessage", "hello"], env=env):
            im = disp.waitgrab(timeout=1)
            results[0] = im
            sleep(2)


def test_smart():
    results = [None]
    t = Thread(target=func2, args=(results,))
    t.start()
    sleep(1)
    with SmartDisplay(manage_global_env=False) as disp:
        env = disp.env()
        logging.info("env=%s", env)
        with EasyProcess(["xmessage", "hello"], env=env):
            sleep(2)
            im0 = disp.waitgrab(timeout=1)
            assert im0
    t.join()
    im1 = results[0]
    assert im1
    # im0.save('/vagrant/im0.png')
    # im1.save('/vagrant/im1.png')
    img_diff = ImageChops.difference(im0, im1)
    ex = img_diff.getextrema()
    logging.debug("diff getextrema: %s", ex)
    diff_bbox = img_diff.getbbox()
    assert diff_bbox is None