コード例 #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)
コード例 #2
0
def test_nested():
    with Display():
        p = EasyProcess([python, "-m",
                         "pyvirtualdisplay.examples.nested"]).start()
        sleep(1)
        assert p.is_alive()
        p.stop()
コード例 #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
コード例 #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()
コード例 #5
0
ファイル: test_timeout.py プロジェクト: ponty/EasyProcess
 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, '')
コード例 #6
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)
コード例 #7
0
ファイル: test_timeout.py プロジェクト: Joshuapy/EasyProcess
    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)
コード例 #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
コード例 #9
0
ファイル: fillscreen.py プロジェクト: Denontime/pyscreenshot
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
コード例 #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 == ""
コード例 #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)
コード例 #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, '')
コード例 #13
0
ファイル: fillscreen.py プロジェクト: yaojingzhe/pyscreenshot
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
コード例 #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
コード例 #15
0
ファイル: test_timeout.py プロジェクト: Joshuapy/EasyProcess
 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, '')
コード例 #16
0
 def test_vncserver():
     p = EasyProcess([python, "-m",
                      "pyvirtualdisplay.examples.vncserver"]).start()
     sleep(1)
     assert p.is_alive()
     p.stop()
コード例 #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 == ""
コード例 #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, '')