Fix comand and improve tests

This commit is contained in:
romainx
2022-01-20 09:12:38 +01:00
parent de087bb1a3
commit 1178c33e27
2 changed files with 32 additions and 19 deletions

View File

@@ -18,8 +18,8 @@ if [[ "${RESTARTABLE}" == "yes" ]]; then
wrapper="run-one-constantly" wrapper="run-one-constantly"
fi fi
if [[ -n "${JUPYTER_ENABLE_LAB}" ]]; then if [[ -v JUPYTER_ENABLE_LAB ]]; then
echo "WARNING: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice." echo "WARNING: JUPYTER_ENABLE_LAB is ignored, use JUPYTER_CMD if you want to change the command used to start the server"
fi fi
# shellcheck disable=SC1091,SC2086 # shellcheck disable=SC1091,SC2086

View File

@@ -6,6 +6,7 @@ from typing import Optional
import pytest import pytest
import requests import requests
import re import re
import time
from conftest import TrackedContainer from conftest import TrackedContainer
@@ -13,40 +14,54 @@ LOGGER = logging.getLogger(__name__)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"env,expected_server,expected_warnings", "env,expected_command,expected_start,expected_warnings",
[ [
( (
["JUPYTER_ENABLE_LAB=yes"], ["JUPYTER_ENABLE_LAB=yes"],
"lab", "jupyter lab",
["WARNING: Jupyter Notebook deprecation notice"], True,
["WARNING: JUPYTER_ENABLE_LAB is ignored"],
),
(None, "jupyter lab", True, []),
(["JUPYTER_CMD=lab"], "jupyter lab", True, []),
(["RESTARTABLE=yes"], "run-one-constantly jupyter lab", True, []),
(["JUPYTER_CMD=notebook"], "jupyter notebook", True, []),
(["JUPYTER_CMD=server"], "jupyter server", True, []),
(["JUPYTER_CMD=nbclassic"], "jupyter nbclassic", True, []),
(
["JUPYTERHUB_API_TOKEN=my_token"],
"jupyterhub-singleuser",
False,
["WARNING: using start-singleuser.sh"],
), ),
(None, "lab", []),
(["JUPYTER_CMD=lab"], "lab", []),
(["JUPYTER_CMD=notebook"], "notebook", []),
(["JUPYTER_CMD=server"], "server", []),
(["JUPYTER_CMD=nbclassic"], "nbclassic", []),
], ],
) )
def test_start_notebook( def test_start_notebook(
container: TrackedContainer, container: TrackedContainer,
http_client: requests.Session, http_client: requests.Session,
env: Optional[list], env: Optional[list],
expected_server: str, expected_command: str,
expected_start: bool,
expected_warnings: list, expected_warnings: list,
) -> None: ) -> None:
"""Test the notebook start-notebook script""" """Test the notebook start-notebook script"""
LOGGER.info( LOGGER.info(
f"Test that the start-notebook launches the {expected_server} server from the env {env} ..." f"Test that the start-notebook launches the {expected_command} server from the env {env} ..."
) )
c = container.run( c = container.run(
tty=True, tty=True,
environment=env, environment=env,
command=["start-notebook.sh"], command=["start-notebook.sh"],
) )
resp = http_client.get("http://localhost:8888") # sleeping some time to let the server start
# checking errors and warnings in logs time.sleep(3)
logs = c.logs(stdout=True).decode("utf-8") logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs) LOGGER.debug(logs)
# checking that the expected command is launched
assert (
f"Executing the command: {expected_command}" in logs
), f"Not the expected command ({expected_command}) was launched"
# checking errors and warnings in logs
assert "ERROR" not in logs, "ERROR(s) found in logs" assert "ERROR" not in logs, "ERROR(s) found in logs"
for exp_warning in expected_warnings: for exp_warning in expected_warnings:
assert exp_warning in logs, f"Expected warning {exp_warning} not found in logs" assert exp_warning in logs, f"Expected warning {exp_warning} not found in logs"
@@ -54,12 +69,10 @@ def test_start_notebook(
assert len(expected_warnings) == len( assert len(expected_warnings) == len(
warnings warnings
), "Not found the number of expected warnings in logs" ), "Not found the number of expected warnings in logs"
# checking if the server is listening # checking if the server is listening
assert resp.status_code == 200, "Server is not listening" if expected_start:
assert ( resp = http_client.get("http://localhost:8888")
f"Executing the command: jupyter {expected_server}" in logs assert resp.status_code == 200, "Server is not listening"
), f"Not the expected command (jupyter {expected_server}) was launched"
def test_tini_entrypoint( def test_tini_entrypoint(