From ffd6bc82f60762dbbc59b019a55d91489dc40fea Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 12 Nov 2022 12:22:02 -0600 Subject: [PATCH 01/13] Add more coverage --- jupyter_server/files/handlers.py | 2 +- tests/extension/test_serverextension.py | 22 ++++++++++++++++++++++ tests/extension/test_utils.py | 22 +++++++++++++++++++++- tests/test_files.py | 12 +++++++++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/jupyter_server/files/handlers.py b/jupyter_server/files/handlers.py index de60117324..acd2828229 100644 --- a/jupyter_server/files/handlers.py +++ b/jupyter_server/files/handlers.py @@ -15,7 +15,7 @@ AUTH_RESOURCE = "contents" -class FilesHandler(JupyterHandler): +class FilesHandler(JupyterHandler, web.StaticFileHandler): """serve files via ContentsManager Normally used when ContentsManager is not a FileContentsManager. diff --git a/tests/extension/test_serverextension.py b/tests/extension/test_serverextension.py index 0953504c07..95f74eab80 100644 --- a/tests/extension/test_serverextension.py +++ b/tests/extension/test_serverextension.py @@ -11,6 +11,10 @@ from jupyter_server.config_manager import BaseJSONConfigManager from jupyter_server.extension.serverextension import ( + DisableServerExtensionApp, + ListServerExtensionsApp, + ServerExtensionApp, + ToggleServerExtensionApp, _get_config_dir, toggle_server_extension_python, ) @@ -112,3 +116,21 @@ def test_load_ordered(jp_serverapp, jp_server_config): assert jp_serverapp.mockII is True, "Mock II should have been loaded" assert jp_serverapp.mockI is True, "Mock I should have been loaded" assert jp_serverapp.mock_shared == "II", "Mock II should be loaded after Mock I" + + +def test_server_extension_apps(jp_env_config_path, jp_extension_environ): + app = ToggleServerExtensionApp() + app.extra_args = "mock1" + app.start() + + app = DisableServerExtensionApp() + app.extra_args = "mock1" + app.start() + + app = ListServerExtensionsApp() + app.start() + + +def test_server_extension_app(): + app = ServerExtensionApp() + app.launch_instance(["list"]) diff --git a/tests/extension/test_utils.py b/tests/extension/test_utils.py index 49a36b20ee..00849de267 100644 --- a/tests/extension/test_utils.py +++ b/tests/extension/test_utils.py @@ -1,6 +1,10 @@ +import logging +import warnings + import pytest -from jupyter_server.extension.utils import validate_extension +from jupyter_server.extension.utils import get_loader, get_metadata, validate_extension +from tests.extension.mockextensions import mockext_sys # Use ServerApps environment because it monkeypatches # jupyter_core.paths and provides a config directory @@ -17,3 +21,19 @@ def test_validate_extension(): assert validate_extension("tests.extension.mockextensions.mockext_user") # enabled at Python assert validate_extension("tests.extension.mockextensions.mockext_py") + + +def test_get_loader(): + get_loader(mockext_sys) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + assert get_loader(object()) is None + + +def test_get_metadata(): + _, ext_points = get_metadata("tests.extension.mockextensions.mockext_sys") + assert len(ext_points) + _, ext_points = get_metadata("tests", logger=logging.getLogger()) + point = ext_points[0] + assert point["module"] == "tests" + assert point["name"] == "tests" diff --git a/tests/test_files.py b/tests/test_files.py index 06f1932591..06f8e26bae 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -10,6 +10,16 @@ from .utils import expected_http_error +@pytest.fixture( + params=[ + "jupyter_server.files.handlers.FilesHandler", + "jupyter_server.base.handlers.AuthenticatedFileHandler", + ] +) +def jp_argv(request): + return ["--ContentsManager.files_handler_class=" + request.param] + + @pytest.fixture( params=[ [False, ["å b"]], @@ -85,7 +95,7 @@ async def test_contents_manager(jp_fetch, jp_serverapp, jp_root_dir): r = await jp_fetch("files/test.txt", method="GET") assert r.code == 200 - assert r.headers["content-type"] == "text/plain; charset=UTF-8" + assert "text/plain" in r.headers["content-type"] assert r.body.decode() == "foobar" From 42906d2cf0e9c66ac057977666794f2c5ba37021 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 12 Nov 2022 15:22:15 -0600 Subject: [PATCH 02/13] get windows coverage --- .github/workflows/python-tests.yml | 13 ++++++++----- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 3cdea3eec0..2059a021ff 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -37,12 +37,15 @@ jobs: sudo apt-get update sudo apt-get install texlive-plain-generic inkscape texlive-xetex sudo apt-get install xvfb x11-utils libxkbcommon-x11-0 pandoc - - name: Run the tests + - name: Run the tests on posix if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }} - run: hatch run cov:test -W default || hatch run test:test -W default --lf - - name: Run the tests on pypy and windows - if: ${{ startsWith(matrix.python-version, 'pypy') || startsWith(matrix.os, 'windows') }} - run: hatch run test:test -W default || hatch run test:test -W default --lf + run: hatch run cov:test --cov-fail-under 75 -W default || hatch run cov:test -W default --lf + - name: Run the tests on pypy + if: ${{ startsWith(matrix.python-version, 'pypy' }} + run: hatch run test:test -W default || hatch run test:test -W default --lf + - name: Run the tests on windows + if: ${{ startsWith(matrix.python-version, 'windows' }} + run: hatch run cov:test -s -W default || hatch run cov:test -W default --lf - name: Coverage run: | pip install codecov diff --git a/pyproject.toml b/pyproject.toml index 38a4f3fc99..e50a1fe0ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,7 +104,7 @@ dependencies = ["coverage", "pytest-cov"] [tool.hatch.envs.cov.env-vars] ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered" [tool.hatch.envs.cov.scripts] -test = "python -m pytest $ARGS --cov-fail-under 75 {args}" +test = "python -m pytest $ARGS {args}" integration = "python -m pytest $ARGS --integration_tests=true {args}" [tool.hatch.version] From 356a9d3967a953fbeb5f303841d182b98acdc0dc Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 12 Nov 2022 15:24:04 -0600 Subject: [PATCH 03/13] formatting --- .github/workflows/python-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 2059a021ff..c01cc0558c 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -41,10 +41,10 @@ jobs: if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }} run: hatch run cov:test --cov-fail-under 75 -W default || hatch run cov:test -W default --lf - name: Run the tests on pypy - if: ${{ startsWith(matrix.python-version, 'pypy' }} + if: ${{ startsWith(matrix.python-version, 'pypy') }} run: hatch run test:test -W default || hatch run test:test -W default --lf - name: Run the tests on windows - if: ${{ startsWith(matrix.python-version, 'windows' }} + if: ${{ startsWith(matrix.python-version, 'windows') }} run: hatch run cov:test -s -W default || hatch run cov:test -W default --lf - name: Coverage run: | From 5625abb1fc3e68dcf331994cbe35d1400278eda6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 12 Nov 2022 15:59:14 -0600 Subject: [PATCH 04/13] more cleanup --- jupyter_server/files/handlers.py | 2 -- tests/test_files.py | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jupyter_server/files/handlers.py b/jupyter_server/files/handlers.py index acd2828229..4f3bea2ae4 100644 --- a/jupyter_server/files/handlers.py +++ b/jupyter_server/files/handlers.py @@ -85,8 +85,6 @@ async def get(self, path, include_body=True): if model["format"] == "base64": b64_bytes = model["content"].encode("ascii") self.write(decodebytes(b64_bytes)) - elif model["format"] == "json": - self.write(json.dumps(model["content"])) else: self.write(model["content"]) self.flush() diff --git a/tests/test_files.py b/tests/test_files.py index 06f8e26bae..8a93557577 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -43,6 +43,15 @@ async def fetch_expect_404(jp_fetch, *path_parts): assert expected_http_error(e, 404), [path_parts, e] +async def test_file_types(jp_fetch, jp_root_dir): + path = Path(jp_root_dir, "test") + path.mkdir(parents=True, exist_ok=True) + foos = ["foo.tar.gz", "foo.bz", "foo.foo"] + for foo in foos: + (path / foo).write_text(foo) + await fetch_expect_200(jp_fetch, "test", foo) + + async def test_hidden_files(jp_fetch, jp_serverapp, jp_root_dir, maybe_hidden): is_hidden, path_parts = maybe_hidden path = Path(jp_root_dir, *path_parts) From 05d04c4d5a4d28ca2560d4edeec8bde0f409d220 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 12 Nov 2022 16:10:36 -0600 Subject: [PATCH 05/13] try uuid --- jupyter_server/files/handlers.py | 1 - tests/test_utils.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_server/files/handlers.py b/jupyter_server/files/handlers.py index 4f3bea2ae4..1c065ab38a 100644 --- a/jupyter_server/files/handlers.py +++ b/jupyter_server/files/handlers.py @@ -1,7 +1,6 @@ """Serve files directly from the ContentsManager.""" # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -import json import mimetypes from base64 import decodebytes from typing import List diff --git a/tests/test_utils.py b/tests/test_utils.py index d3e168ff60..48e0986e23 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,6 +2,7 @@ import socket import subprocess import sys +import uuid import warnings from pathlib import Path from unittest.mock import patch @@ -116,7 +117,7 @@ async def foo(): @pytest.mark.skipif(os.name != "posix", reason="Requires unix sockets") def test_unix_socket_in_use(tmp_path): root_tmp_dir = Path("/tmp").resolve() - server_address = os.path.join(root_tmp_dir, os.path.basename(tmp_path)) + server_address = os.path.join(root_tmp_dir, uuid.uuid4().hex) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.bind(server_address) sock.listen(0) From 9c57c30f1cab0b41a10ab04b1a8e862f586e379e Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 16 Nov 2022 16:36:32 -0600 Subject: [PATCH 06/13] clean up workflow --- .github/workflows/python-tests.yml | 49 ++++++++---------------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index c01cc0558c..3f76f02427 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -39,10 +39,10 @@ jobs: sudo apt-get install xvfb x11-utils libxkbcommon-x11-0 pandoc - name: Run the tests on posix if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }} - run: hatch run cov:test --cov-fail-under 75 -W default || hatch run cov:test -W default --lf + run: hatch run cov:test --cov-fail-under 75 || hatch run cov:test --lf - name: Run the tests on pypy if: ${{ startsWith(matrix.python-version, 'pypy') }} - run: hatch run test:test -W default || hatch run test:test -W default --lf + run: hatch run test:test || hatch run test:test --lf - name: Run the tests on windows if: ${{ startsWith(matrix.python-version, 'windows') }} run: hatch run cov:test -s -W default || hatch run cov:test -W default --lf @@ -51,23 +51,6 @@ jobs: pip install codecov codecov - client8: - runs-on: ${{ matrix.os }} - timeout-minutes: 20 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.10"] - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Base Setup - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - run: | - pip install -U pre jupyter_client - hatch run test:test || hatch run test:test --lf - pre-commit: name: pre-commit runs-on: ubuntu-latest @@ -105,38 +88,30 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Base Setup - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 with: python_version: "3.8" - - name: Install miniumum versions - uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1 + - uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1 + with: + only_create_file: 1 - name: Run the unit tests run: | - pytest -vv -W default || pytest -vv -W default --lf + export PIP_CONSTRAINT="./contraints_file.txt" + hatch run test:test || hatch run test:test --lf test_prereleases: name: Test Prereleases runs-on: ubuntu-latest timeout-minutes: 20 steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Base Setup - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + - uses: actions/checkout@v3 + - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 with: python_version: "3.11" - - name: Install the Python dependencies - run: | - pip install --no-deps . - pip install --pre --upgrade ".[test]" - - name: List installed packages - run: | - pip freeze - pip check - name: Run the tests run: | - pytest -vv -W default || pytest -vv -W default --lf + export PIP_PRE=1 + hatch run test:test || hatch run test:test --lf make_sdist: name: Make SDist From 2cd16967b767b83336f11182de722c53e07afeba Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 16 Nov 2022 16:44:46 -0600 Subject: [PATCH 07/13] fix workflow --- .github/workflows/python-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 3f76f02427..a0ae5660ec 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -151,7 +151,6 @@ jobs: - test_docs - test_minimum_versions - test_prereleases - - client8 - check_links - test_sdist runs-on: ubuntu-latest From aff0d96aba55cd1bf6ee0642c24de5084fb8faa6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 16 Nov 2022 16:58:16 -0600 Subject: [PATCH 08/13] cleanup --- .github/workflows/python-tests.yml | 8 ++++---- pyproject.toml | 18 ++---------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index a0ae5660ec..8492e036b1 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -39,13 +39,13 @@ jobs: sudo apt-get install xvfb x11-utils libxkbcommon-x11-0 pandoc - name: Run the tests on posix if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }} - run: hatch run cov:test --cov-fail-under 75 || hatch run cov:test --lf + run: hatch run cov:test --cov-fail-under 75 || hatch run test:test --lf - name: Run the tests on pypy if: ${{ startsWith(matrix.python-version, 'pypy') }} run: hatch run test:test || hatch run test:test --lf - name: Run the tests on windows if: ${{ startsWith(matrix.python-version, 'windows') }} - run: hatch run cov:test -s -W default || hatch run cov:test -W default --lf + run: hatch run cov:nowarn -s || hatch run cov:nowarn --lf - name: Coverage run: | pip install codecov @@ -97,7 +97,7 @@ jobs: - name: Run the unit tests run: | export PIP_CONSTRAINT="./contraints_file.txt" - hatch run test:test || hatch run test:test --lf + hatch run test:nowarn || hatch run test:nowarn --lf test_prereleases: name: Test Prereleases @@ -111,7 +111,7 @@ jobs: - name: Run the tests run: | export PIP_PRE=1 - hatch run test:test || hatch run test:test --lf + hatch run test:nowarn || hatch run test:nowarn --lf make_sdist: name: Make SDist diff --git a/pyproject.toml b/pyproject.toml index e50a1fe0ff..9ccced209c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,10 +102,10 @@ nowarn = "python -m pytest -vv -W default {args}" features = ["test"] dependencies = ["coverage", "pytest-cov"] [tool.hatch.envs.cov.env-vars] -ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered" +ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered --cov-fail-under 70" [tool.hatch.envs.cov.scripts] test = "python -m pytest $ARGS {args}" -integration = "python -m pytest $ARGS --integration_tests=true {args}" +nwarn = "python -m pytest $ARGS -W default {args}" [tool.hatch.version] path = "jupyter_server/_version.py" @@ -146,20 +146,6 @@ filterwarnings = [ "module:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning", ] -[tool.coverage.report] -exclude_lines = [ - "pragma: no cover", - "def __repr__", - "if self.debug:", - "if settings.DEBUG", - "raise AssertionError", - "raise NotImplementedError", - "if 0:", - "if __name__ == .__main__.:", - "class .*\bProtocol\\):", -"@(abc\\.)?abstractmethod", -] - [tool.jupyter-releaser.hooks] before-build-python = ["npm install", "npm run build"] From 727a856ae2a636790da3a89b0df206378b245f68 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 16 Nov 2022 17:12:43 -0600 Subject: [PATCH 09/13] reinstate script --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2f96c33ea5..13810b5d89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ dependencies = [ "Send2Trash", "terminado>=0.8.3", "tornado>=6.2.0", - "traitlets>=5.3.0", + "traitlets>=5.1", "websocket-client", "jupyter_events>=0.4.0" ] @@ -106,6 +106,7 @@ ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-cov [tool.hatch.envs.cov.scripts] test = "python -m pytest $ARGS {args}" nwarn = "python -m pytest $ARGS -W default {args}" +integration = "python -m pytest $ARGS --integration_tests=true {args}" [tool.hatch.version] path = "jupyter_server/_version.py" From a92941d29d462cab74d8ead853a217599566d225 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 16 Nov 2022 17:23:17 -0600 Subject: [PATCH 10/13] fix script --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 13810b5d89..8fc822771c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,7 @@ nowarn = "python -m pytest -vv -W default {args}" features = ["test"] dependencies = ["coverage", "pytest-cov"] [tool.hatch.envs.cov.env-vars] -ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered --cov-fail-under 70" +ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered " [tool.hatch.envs.cov.scripts] test = "python -m pytest $ARGS {args}" nwarn = "python -m pytest $ARGS -W default {args}" From 340502b56e78014e8ebe8cb7951102ab60ad05ec Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Nov 2022 17:35:47 -0600 Subject: [PATCH 11/13] restore missing coverage config --- pyproject.toml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8fc822771c..53499330ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,7 @@ nowarn = "python -m pytest -vv -W default {args}" features = ["test"] dependencies = ["coverage", "pytest-cov"] [tool.hatch.envs.cov.env-vars] -ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered " +ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered" [tool.hatch.envs.cov.scripts] test = "python -m pytest $ARGS {args}" nwarn = "python -m pytest $ARGS -W default {args}" @@ -147,6 +147,20 @@ filterwarnings = [ "module:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning", ] +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "if self.debug:", + "if settings.DEBUG", + "raise AssertionError", + "raise NotImplementedError", + "if 0:", + "if __name__ == .__main__.:", + "class .*\bProtocol\\):", +"@(abc\\.)?abstractmethod", +] + [tool.jupyter-releaser.hooks] before-build-python = ["npm install", "npm run build"] From 950876beb9120b38d76cd7081b16cd2db72050a5 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Nov 2022 17:36:24 -0600 Subject: [PATCH 12/13] undo traitlets change --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 53499330ad..3b0e37242a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ dependencies = [ "Send2Trash", "terminado>=0.8.3", "tornado>=6.2.0", - "traitlets>=5.1", + "traitlets>=5.3.0", "websocket-client", "jupyter_events>=0.4.0" ] From ad66cb974027e07f14b45438bc0d36bf858be465 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Nov 2022 17:43:06 -0600 Subject: [PATCH 13/13] add a guard on the test_unix_socket_in_use test --- tests/test_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 48e0986e23..53e3acbc05 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -118,6 +118,8 @@ async def foo(): def test_unix_socket_in_use(tmp_path): root_tmp_dir = Path("/tmp").resolve() server_address = os.path.join(root_tmp_dir, uuid.uuid4().hex) + if os.path.exists(server_address): + os.remove(server_address) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.bind(server_address) sock.listen(0)