File: test_process.py

package info (click to toggle)
jupyterlab-server 2.28.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 692 kB
  • sloc: python: 3,532; makefile: 13; sh: 2
file content (49 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download
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
48
49
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import sys
import warnings

import pytest

from jupyterlab_server.process import Process, WatchHelper, which
from jupyterlab_server.process_app import ProcessApp


def test_which():
    assert which("jupyter")


async def test_process():
    p = Process([sys.executable, "--version"])
    p.get_log().info("test")
    assert p.wait() == 0

    p = Process([sys.executable, "--version"])
    p.get_log().info("test")
    assert await p.wait_async() == 0
    assert p.terminate() == 0


@pytest.mark.skipif(os.name == "nt", reason="Fails on Windows")
async def test_watch_helper():
    helper = WatchHelper([sys.executable, "-i"], ">>>")
    helper.terminate()
    helper.wait()


def test_process_app():
    class TestApp(ProcessApp):
        name = "tests"

    app = TestApp()
    app.initialize_server([])
    try:
        app.initialize()
        with pytest.raises(SystemExit):
            app.start()
    # Kandle exception on older versions of server.
    except Exception as e:
        # Convert to warning so the test will pass on min version test.
        warnings.warn(str(e), stacklevel=2)