Skip to content

Commit 9141f3e

Browse files
authored
Fix async contents handling and add test (#6616)
* Fix async contents handling and add test * cleanup * fix arg * add another ignore
1 parent 6dd6022 commit 9141f3e

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ jobs:
5858
jupyter server extension list 2>&1 | grep -ie "notebook.*enabled" -
5959
python -m jupyterlab.browser_check
6060
61+
test_prerelease:
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 10
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v3
67+
68+
- name: Base Setup
69+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
70+
with:
71+
python_version: "3.10"
72+
73+
- name: Install the Python dependencies
74+
run: |
75+
pip install --no-deps .
76+
pip install --pre --upgrade ".[dev,test]"
77+
python -m pip install ".[dev,test]"
78+
jlpm run build:test
79+
80+
- name: Python Unit tests
81+
run: |
82+
pytest -vv || pytest -vv --lf
83+
6184
install:
6285
needs: [build]
6386
runs-on: ${{ matrix.os }}
@@ -116,7 +139,7 @@ jobs:
116139
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
117140
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1
118141
with:
119-
ignore_links: "https://playwright.dev/docs/test-cli/"
142+
ignore_links: "https://playwright.dev/docs/test-cli/ https://blog.jupyter.org/the-big-split-9d7b88a031a7 https://blog.jupyter.org/jupyter-ascending-1bf5b362d97e"
120143

121144
pre_commit:
122145
runs-on: ubuntu-latest

notebook/app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from os.path import join as pjoin
33

4+
from jupyter_client.utils import ensure_async
45
from jupyter_core.application import base_aliases
56
from jupyter_server.base.handlers import JupyterHandler
67
from jupyter_server.extension.handler import (
@@ -16,7 +17,6 @@
1617
from jupyterlab_server.handlers import _camelCase, is_url
1718
from notebook_shim.shim import NotebookConfigShimMixin
1819
from tornado import web
19-
from tornado.gen import maybe_future
2020
from traitlets import Bool, default
2121

2222
from ._version import __version__
@@ -129,8 +129,8 @@ async def get(self, path=None):
129129
path = path.strip("/")
130130
cm = self.contents_manager
131131

132-
if await maybe_future(cm.dir_exists(path=path)):
133-
if await maybe_future(cm.is_hidden(path)) and not cm.allow_hidden:
132+
if await ensure_async(cm.dir_exists(path=path)):
133+
if await ensure_async(cm.is_hidden(path)) and not cm.allow_hidden:
134134
self.log.info("Refusing to serve hidden directory, via 404 Error")
135135
raise web.HTTPError(404)
136136

@@ -140,9 +140,9 @@ async def get(self, path=None):
140140

141141
tpl = self.render_template("tree.html", page_config=page_config)
142142
return self.write(tpl)
143-
elif await maybe_future(cm.file_exists(path)):
143+
elif await ensure_async(cm.file_exists(path)):
144144
# it's not a directory, we have redirecting to do
145-
model = await maybe_future(cm.get(path, content=False))
145+
model = await ensure_async(cm.get(path, content=False))
146146
if model["type"] == "notebook":
147147
url = ujoin(self.base_url, "notebooks", url_escape(path))
148148
else:

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glob
12
import json
23
import os
34
import os.path as osp
@@ -49,7 +50,11 @@ def _make_notebook_app(**kwargs):
4950
extra_labextensions_path=[str(labextensions_dir)],
5051
)
5152

52-
# Create the index files.
53+
# Copy the template files.
54+
for html_path in glob.glob(f"{path('notebook', 'templates')}/*.html"):
55+
shutil.copy(html_path, jp_template_dir)
56+
57+
# Create the index file.
5358
index = jp_template_dir.joinpath("index.html")
5459
index.write_text(
5560
"""

tests/test_app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ async def test_notebook_handler(notebooks, jp_fetch):
2020
# Check that the lab template is loaded
2121
html = r.body.decode()
2222
assert "Jupyter Notebook" in html
23+
24+
25+
async def test_tree_handler(notebooks, jp_fetch):
26+
r = await jp_fetch("tree", "jlab_test_notebooks")
27+
assert r.code == 200
28+
29+
# Check that the tree template is loaded
30+
html = r.body.decode()
31+
assert "- Tree</title>" in html

0 commit comments

Comments
 (0)