Test improved (review)

This commit is contained in:
romainx
2022-01-19 18:12:15 +01:00
parent 1d8d7df242
commit de087bb1a3

View File

@@ -2,8 +2,10 @@
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
import logging import logging
from typing import Optional
import pytest import pytest
import requests import requests
import re
from conftest import TrackedContainer from conftest import TrackedContainer
@@ -11,22 +13,26 @@ LOGGER = logging.getLogger(__name__)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"env,expected_server,expected_warning", "env,expected_server,expected_warnings",
[ [
(["JUPYTER_ENABLE_LAB=yes"], "lab", True), (
(None, "lab", False), ["JUPYTER_ENABLE_LAB=yes"],
(["JUPYTER_CMD=lab"], "lab", False), "lab",
(["JUPYTER_CMD=notebook"], "notebook", False), ["WARNING: Jupyter Notebook deprecation notice"],
(["JUPYTER_CMD=server"], "server", False), ),
(["JUPYTER_CMD=nbclassic"], "nbclassic", False), (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, env: Optional[list],
expected_server: str, expected_server: str,
expected_warning: bool, expected_warnings: list,
) -> None: ) -> None:
"""Test the notebook start-notebook script""" """Test the notebook start-notebook script"""
LOGGER.info( LOGGER.info(
@@ -38,17 +44,18 @@ def test_start_notebook(
command=["start-notebook.sh"], command=["start-notebook.sh"],
) )
resp = http_client.get("http://localhost:8888") resp = http_client.get("http://localhost:8888")
# checking errors and warnings in logs
logs = c.logs(stdout=True).decode("utf-8") logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs) LOGGER.debug(logs)
assert "ERROR" not in logs assert "ERROR" not in logs, "ERROR(s) found in logs"
if not expected_warning: for exp_warning in expected_warnings:
assert "WARNING" not in logs assert exp_warning in logs, f"Expected warning {exp_warning} not found in logs"
else: warnings = re.findall(r"^WARNING", logs, flags=re.MULTILINE)
warnings = [ assert len(expected_warnings) == len(
warning for warning in logs.split("\n") if warning.startswith("WARNING") warnings
] ), "Not found the number of expected warnings in logs"
assert len(warnings) == 1
assert warnings[0].startswith("WARNING: Jupyter Notebook deprecation notice") # checking if the server is listening
assert resp.status_code == 200, "Server is not listening" assert resp.status_code == 200, "Server is not listening"
assert ( assert (
f"Executing the command: jupyter {expected_server}" in logs f"Executing the command: jupyter {expected_server}" in logs