Ejemplo n.º 1
0
def prog_shot(cmd, f, wait, timeout, screen_size, visible, bgcolor, backend):
    '''start process in headless X and create screenshot after 'wait' sec.
    Repeats screenshot until it is not empty if 'repeat_if_empty'=True.

    wait: wait at least N seconds after first window is displayed,
    it can be used to skip splash screen

    :param wait: int
    '''
    # disp = SmartDisplay(visible=visible, size=screen_size, bgcolor=bgcolor)
    #'xvfb', 'xvnc' or 'xephyr',
    disp = SmartDisplay(visible=visible,
                        backend=backend,
                        size=screen_size,
                        bgcolor=bgcolor)
    proc = EasyProcess(cmd)

    def cb_imgcheck(img):
        """accept img if height > minimum."""
        rec = get_black_box(img)
        if not rec:
            return False
        left, upper, right, lower = rec
        accept = lower - upper > 30  # pixel
        log.debug('cropped img size=' + str((left, upper, right, lower)) +
                  ' accepted=' + str(accept))
        return accept

    # def func():
    #     if wait:
    #         proc.sleep(wait)
    #     try:
    #         img = disp.waitgrab(timeout=timeout, cb_imgcheck=cb_imgcheck)
    #     except DisplayTimeoutError as e:
    #         raise DisplayTimeoutError(str(e) + ' ' + str(proc))
    #     return img

    with disp:
        with proc:
            try:
                if wait:
                    proc.sleep(wait)
                img = disp.waitgrab(timeout=timeout, cb_imgcheck=cb_imgcheck)
            except DisplayTimeoutError as e:
                raise DisplayTimeoutError(str(e) + ' ' + str(proc))

    # img = disp.wrap(proc.wrap(func))()
    if img:
        bbox = get_black_box(img)
        assert bbox
        # extend to the left side
        bbox = (0, bbox[1], bbox[2], bbox[3])
        img = img.crop(bbox)

        img.save(f)
    return (proc.stdout, proc.stderr)
Ejemplo n.º 2
0
def test_deadlock():
    d = Display(visible=VISIBLE, size=(600, 400))
    d.start()
    
    p = EasyProcess([python, '-c', 'import Image;Image.new("RGB",(99, 99)).show()'])
    p.start()
    p.sleep(1)
    # hangs with pipes
    p.stop()
    
    d.stop()
Ejemplo n.º 3
0
def test_deadlock():
    d = Display(visible=VISIBLE, size=(600, 400))
    d.start()

    p = EasyProcess(
        [python, '-c', 'import Image;Image.new("RGB",(99, 99)).show()'])
    p.start()
    p.sleep(1)
    # hangs with pipes
    p.stop()

    d.stop()
Ejemplo n.º 4
0
def test_deadlock():
    # skip these tests for Windows/Mac
    if not sys.platform.startswith("linux"):
        return
    d = Display(visible=VISIBLE, size=(600, 400))
    d.start()

    p = EasyProcess(
        [python, "-c", 'import Image;Image.new("RGB",(99, 99)).show()'])
    p.start()
    p.sleep(1)
    # hangs with pipes
    p.stop()

    d.stop()