Esempio n. 1
0
 def test_lowres():
     with Display():
         p = EasyProcess([python, "-m", "pyvirtualdisplay.examples.lowres"]).start()
         sleep(1)
         assert p.is_alive()
         # p.stop()
         kill_process_tree(p)
Esempio n. 2
0
def test_nested():
    with Display():
        p = EasyProcess([python, "-m",
                         "pyvirtualdisplay.examples.nested"]).start()
        sleep(1)
        assert p.is_alive()
        p.stop()
Esempio n. 3
0
def test_is_alive1():
    # early exit
    p = EasyProcess("echo hello").start().sleep(0.5)

    assert p.return_code is None
    assert p.stdout is None
    assert p.stderr is None

    assert (p.is_alive(), False)  # is_alive collects ouputs if proc stopped

    assert p.return_code == 0
    assert p.stdout == "hello"
    assert p.stderr == ""

    assert p.is_alive() is False
    assert p.is_alive() is False
Esempio n. 4
0
def test_is_alive2():
    # no exit
    p = EasyProcess("sleep 10").start()

    assert p.return_code is None
    assert p.stdout is None
    assert p.stderr is None

    assert p.is_alive()  # is_alive collects ouputs if proc stopped

    assert p.return_code is None
    assert p.stdout is None
    assert p.stderr is None

    assert p.is_alive()
    assert p.is_alive()
Esempio n. 5
0
 def test_timeout_out(self):
     p = EasyProcess(
         [python, '-c', "import time;print( 'start');time.sleep(5);print( 'end')"]).call(timeout=1)
     eq_(p.is_alive(), False)
     eq_(p.timeout_happened, True)
     ok_(p.return_code < 0)
     eq_(p.stdout, '')
    def test_timeout(self):
        p = EasyProcess('sleep 1').start()
        p.wait(0.2)
        eq_(p.is_alive(), True)
        p.wait(0.2)
        eq_(p.is_alive(), True)
        p.wait(2)
        eq_(p.is_alive(), False)

        eq_(EasyProcess('sleep 0.3').call().return_code == 0, True)
        eq_(EasyProcess('sleep 0.3').call(timeout=0.1).return_code == 0, False)
        eq_(EasyProcess('sleep 0.3').call(timeout=1).return_code == 0, True)

        eq_(EasyProcess('sleep 0.3').call().timeout_happened, False)
        eq_(EasyProcess('sleep 0.3').call(timeout=0.1).timeout_happened, True)
        eq_(EasyProcess('sleep 0.3').call(timeout=1).timeout_happened, False)
Esempio n. 7
0
    def test_timeout(self):
        p = EasyProcess('sleep 1').start()
        p.wait(0.2)
        eq_(p.is_alive(), True)
        p.wait(0.2)
        eq_(p.is_alive(), True)
        p.wait(2)
        eq_(p.is_alive(), False)

        eq_(EasyProcess('sleep 0.3').call().return_code == 0, True)
        eq_(EasyProcess('sleep 0.3').call(timeout=0.1).return_code == 0, False)
        eq_(EasyProcess('sleep 0.3').call(timeout=1).return_code == 0, True)

        eq_(EasyProcess('sleep 0.3').call().timeout_happened, False)
        eq_(EasyProcess('sleep 0.3').call(timeout=0.1).timeout_happened, True)
        eq_(EasyProcess('sleep 0.3').call(timeout=1).timeout_happened, False)
Esempio n. 8
0
def test_timeout():
    p = EasyProcess("sleep 1").start()
    p.wait(0.2)
    assert p.is_alive()
    p.wait(0.2)
    assert p.is_alive()
    p.wait(2)
    assert not p.is_alive()

    assert EasyProcess("sleep 0.3").call().return_code == 0
    assert EasyProcess("sleep 0.3").call(timeout=0.1).return_code != 0
    assert EasyProcess("sleep 0.3").call(timeout=1).return_code == 0

    assert EasyProcess("sleep 0.3").call().timeout_happened is False
    assert EasyProcess("sleep 0.3").call(timeout=0.1).timeout_happened
    assert EasyProcess("sleep 0.3").call(timeout=1).timeout_happened is False
Esempio n. 9
0
def init():
    global refimgpath
    if not refimgpath:
        d = tempfile.mkdtemp(prefix="fillscreen")
        d = Path(d)
        atexit.register(d.rmtree)
        refimgpath = d / "ref.png"

        if not platform_is_win():  # TODO: win image viewer
            im = generate_image()
            im.save(refimgpath)
            cmd = [
                "pqiv",
                "--fullscreen",
                "--hide-info-box",
                "--disable-scaling",
                refimgpath,
            ]
            proc = EasyProcess(cmd).start()
            atexit.register(proc.stop)
            print(refimgpath)
            sleep(5)  # TODO: check image displayed
            if not proc.is_alive():
                raise FillscreenError("pqiv stopped: %s" % proc)

        # if the OS has color correction
        #  then the screenshot has slighly different color than the original image
        # TODO: color correction: linux? win?
        if platform_is_win() or platform_is_osx():
            refimgpath = refimgpath + ".pil.png"
            im = pyscreenshot.grab(backend="pil")
            im.save(refimgpath)
            log.debug("%s saved", refimgpath)

    return refimgpath
Esempio n. 10
0
def test_timeout_out():
    p = EasyProcess([
        python, "-c", "import time;print( 'start');time.sleep(5);print( 'end')"
    ]).call(timeout=1)
    assert p.is_alive() is False
    assert p.timeout_happened
    assert p.return_code != 0
    assert p.stdout == ""
Esempio n. 11
0
 def test_vncserver():
     if worker() == 0:
         p = EasyProcess(
             [python, "-m", "pyvirtualdisplay.examples.vncserver"]
         ).start()
         sleep(1)
         assert p.is_alive()
         # p.stop()
         kill_process_tree(p)
Esempio n. 12
0
 def test_timeout_out(self):
     p = EasyProcess([
         python, '-c',
         "import time;print( 'start');time.sleep(5);print( 'end')"
     ]).call(timeout=1)
     eq_(p.is_alive(), False)
     eq_(p.timeout_happened, True)
     ok_(p.return_code < 0)
     eq_(p.stdout, '')
Esempio n. 13
0
def init():
    global refimgpath
    if not refimgpath:
        d = tempfile.mkdtemp(prefix="fillscreen")
        atexit.register(lambda: rmtree(d))
        refimgpath = join(d, "ref.png")

        im = generate_image()
        im.save(refimgpath)

        if platform_is_win():
            cmd = [
                "C:\\Program Files (x86)\\FastStone Image Viewer\\FSViewer.exe",
                refimgpath,
            ]
        else:
            cmd = [
                "pqiv",
                "--fullscreen",
                "--hide-info-box",
                "--disable-scaling",
                refimgpath,
            ]
        proc = EasyProcess(cmd).start()
        atexit.register(proc.stop)
        print(refimgpath)
        sleep(5)  # wait for image displayed
        if not proc.is_alive():
            raise FillscreenError("pqiv stopped: %s" % proc)

        # if the OS has color correction
        #  then the screenshot has slighly different color than the original image
        if platform_is_win() or platform_is_osx():
            refimgpath = refimgpath + ".pil.png"
            im = pyscreenshot.grab(backend="pil")
            im.save(refimgpath)
            log.debug("%s saved", refimgpath)

    return refimgpath
Esempio n. 14
0
    def start(self):
        """
        start display

        :rtype: self
        """
        if self.use_xauth:
            self._setup_xauth()
        EasyProcess.start(self)
        time.sleep(0.01)

        # https://github.com/ponty/PyVirtualDisplay/issues/2
        # https://github.com/ponty/PyVirtualDisplay/issues/14
        self.old_display_var = os.environ.get("DISPLAY", None)

        self.redirect_display(True)

        # wait until X server is active
        start_time = time.time()
        if self.check_startup:
            rp = self._check_startup_fd
            display_check = None
            rlist, wlist, xlist = select.select((rp, ), (), (),
                                                X_START_TIMEOUT)
            if rlist:
                display_check = os.read(rp, 10).rstrip()
            else:
                msg = "No display number returned by X server"
                raise XStartTimeoutError(msg)
            dnbs = str(self.display)
            if bytes != str:
                dnbs = bytes(dnbs, "ascii")
            if display_check != dnbs:
                msg = 'Display number "%s" not returned by X server' + str(
                    display_check)
                raise XStartTimeoutError(msg % self.display)

        d = self.new_display_var
        ok = False
        while True:
            if not EasyProcess.is_alive(self):
                break

            try:
                xdpyinfo = EasyProcess("xdpyinfo")
                xdpyinfo.enable_stdout_log = False
                xdpyinfo.enable_stderr_log = False
                exit_code = xdpyinfo.call().return_code
            except EasyProcessError:
                log.warning(
                    "xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!"
                )
                time.sleep(X_START_WAIT)  # old method
                ok = True
                break

            if exit_code != 0:
                pass
            else:
                log.info('Successfully started X with display "%s".', d)
                ok = True
                break

            if time.time() - start_time >= X_START_TIMEOUT:
                break
            time.sleep(X_START_TIME_STEP)
        if not EasyProcess.is_alive(self):
            log.warning("process exited early", )
            msg = "Failed to start process: %s"
            raise XStartError(msg % self)
        if not ok:
            msg = 'Failed to start X on display "%s" (xdpyinfo check failed, stderr:[%s]).'
            raise XStartTimeoutError(msg % (d, xdpyinfo.stderr))
        return self
Esempio n. 15
0
 def test_time2(self):
     p = EasyProcess('sleep 5').call(timeout=1)
     eq_(p.is_alive(), False)
     eq_(p.timeout_happened, True)
     ok_(p.return_code < 0)
     eq_(p.stdout, '')
Esempio n. 16
0
 def test_vncserver():
     p = EasyProcess([python, "-m",
                      "pyvirtualdisplay.examples.vncserver"]).start()
     sleep(1)
     assert p.is_alive()
     p.stop()
Esempio n. 17
0
def test_time2():
    p = EasyProcess("sleep 5").call(timeout=1)
    assert p.is_alive() is False
    assert p.timeout_happened
    assert p.return_code != 0
    assert p.stdout == ""
Esempio n. 18
0
 def test_time2(self):
     p = EasyProcess('sleep 5').call(timeout=1)
     eq_(p.is_alive(), False)
     eq_(p.timeout_happened, True)
     ok_(p.return_code < 0)
     eq_(p.stdout, '')