diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 658e072568..f4e25a65d9 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -17,17 +17,13 @@ jobs: uses: actions/checkout@v3 - name: Base Setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - name: Install the Python dependencies - run: | - pip install -e ".[test]" - pip install pytest-github-actions-annotate-failures - - name: List installed packages - run: | - pip freeze - pip check - name: Run the tests run: | hatch run cov:integration + - name: Coverage + run: | + pip install codecov + codecov integration_check: # This job does nothing and is only used for the branch protection if: always() diff --git a/pyproject.toml b/pyproject.toml index 6716b42894..713ec1346f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -152,6 +152,7 @@ exclude_lines = [ "def __repr__", "if self.debug:", "if settings.DEBUG", + "if TYPE_CHECKING:", "raise AssertionError", "raise NotImplementedError", "if 0:", diff --git a/tests/test_serverapp.py b/tests/test_serverapp.py index 0da94cffad..e58d2ebaab 100644 --- a/tests/test_serverapp.py +++ b/tests/test_serverapp.py @@ -2,6 +2,7 @@ import logging import os import pathlib +import warnings from unittest.mock import patch import pytest @@ -10,7 +11,13 @@ from traitlets.tests.utils import check_help_all_output from jupyter_server.auth.security import passwd_check -from jupyter_server.serverapp import JupyterPasswordApp, ServerApp, list_running_servers +from jupyter_server.serverapp import ( + JupyterPasswordApp, + ServerApp, + ServerWebApplication, + list_running_servers, + random_ports, +) def test_help_output(): @@ -401,3 +408,32 @@ def test_observed_root_dir_does_not_update_preferred_dir(tmp_path, jp_configurab app = jp_configurable_serverapp(root_dir=path, preferred_dir=path) app.root_dir = new_path assert app.preferred_dir == path + + +def test_random_ports(): + ports = list(random_ports(500, 50)) + assert len(ports) == 50 + + +def test_server_web_application(jp_serverapp): + server: ServerApp = jp_serverapp + server.default_url = "/foo" + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + app = ServerWebApplication( + server, + [], + server.kernel_manager, + server.contents_manager, + server.session_manager, + server.kernel_manager, + server.config_manager, + server.event_logger, + ["jupyter_server.gateway.handlers"], + server.log, + server.base_url, + server.default_url, + {}, + {}, + ) + app.init_handlers([], app.settings) diff --git a/tests/unix_sockets/test_serverapp_integration.py b/tests/unix_sockets/test_serverapp_integration.py index d11a99d60c..e96e42429d 100644 --- a/tests/unix_sockets/test_serverapp_integration.py +++ b/tests/unix_sockets/test_serverapp_integration.py @@ -6,7 +6,12 @@ import pytest -from jupyter_server.serverapp import list_running_servers, shutdown_server +from jupyter_server.serverapp import ( + JupyterServerListApp, + JupyterServerStopApp, + list_running_servers, + shutdown_server, +) from jupyter_server.utils import urlencode_unix_socket, urlencode_unix_socket_path # Skip this module if on Windows. Unix sockets are not available on Windows. @@ -58,6 +63,13 @@ def test_shutdown_sock_server_integration(jp_unix_socket_file): assert encoded_sock_path.encode() in subprocess.check_output(["jupyter-server", "list"]) + # Fake out stopping the server. + app = JupyterServerStopApp(sock=str(jp_unix_socket_file)) + app.initialize([]) + app.shutdown_server = lambda _: True # type:ignore + app._maybe_remove_unix_socket = lambda _: _ # type: ignore + app.start() + subprocess.check_output(["jupyter-server", "stop", jp_unix_socket_file]) assert encoded_sock_path.encode() not in subprocess.check_output(["jupyter-server", "list"]) @@ -195,4 +207,44 @@ def test_shutdown_server(jp_environ): break except ConnectionRefusedError: time.sleep(0.1) - p.wait() + _cleanup_process(p) + + +@pytest.mark.integration_test +def test_jupyter_server_apps(jp_environ): + + # Start a server in another process + # Stop that server + import subprocess + + from jupyter_client.connect import LocalPortCache + + port = LocalPortCache().find_available_port("localhost") + p = subprocess.Popen(["jupyter-server", f"--port={port}"]) + servers = [] + while 1: + servers = list(list_running_servers()) + if len(servers): + break + time.sleep(0.1) + + app = JupyterServerListApp() + app.initialize([]) + app.jsonlist = True + app.start() + app.jsonlist = False + app.json = True + app.start() + app.json = False + app.start() + + app = JupyterServerStopApp() + app.initialize([]) + app.port = port + while 1: + try: + app.start() + break + except ConnectionRefusedError: + time.sleep(0.1) + _cleanup_process(p)