Skip to content

Commit 8898a19

Browse files
committed
Add test for kernel filtering
1 parent 5bc2793 commit 8898a19

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

jupyter_server/services/api/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def test_get_status(self):
2929
assert data['kernels'] == 0
3030
assert data['last_activity'].endswith('Z')
3131
assert data['started'].endswith('Z')
32-
assert data['started'] == isoformat(self.notebook.web_app.settings['started'])
32+
assert data['started'] == isoformat(self.server.web_app.settings['started'])

jupyter_server/services/contents/tests/test_contents_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ def patch_cp_root(self, dirname):
681681
"""
682682
Temporarily patch the root dir of our checkpoint manager.
683683
"""
684-
cpm = self.notebook.contents_manager.checkpoints
684+
cpm = self.server.contents_manager.checkpoints
685685
old_dirname = cpm.root_dir
686686
cpm.root_dir = dirname
687687
try:
@@ -717,7 +717,7 @@ class GenericFileCheckpointsAPITest(APITest):
717717
def test_config_did_something(self):
718718

719719
self.assertIsInstance(
720-
self.notebook.contents_manager.checkpoints,
720+
self.server.contents_manager.checkpoints,
721721
GenericFileCheckpoints,
722722
)
723723

jupyter_server/services/kernels/tests/test_kernels_api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import json
44
import time
55

6+
from traitlets.config import Config
7+
68
from tornado.httpclient import HTTPRequest
79
from tornado.ioloop import IOLoop
810
from tornado.websocket import websocket_connect
@@ -184,3 +186,20 @@ def test_connections(self):
184186
break
185187
model = self.kern_api.get(kid).json()
186188
self.assertEqual(model['connections'], 0)
189+
190+
191+
class KernelFilterTest(ServerTestBase):
192+
# A special install of ServerTestBase where only `kernel_info_request`
193+
# messages are allowed.
194+
195+
config = Config({
196+
'ServerApp': {
197+
'MappingKernelManager': {
198+
'allowed_message_types': ['kernel_info_request']
199+
}
200+
}
201+
})
202+
203+
# Sanity check verifying that the configurable was properly set.
204+
def test_config(self):
205+
self.assertEqual(self.server.kernel_manager.allowed_message_types, ['kernel_info_request'])

jupyter_server/tests/launchserver.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def wait_until_alive(cls):
5959
try:
6060
requests.get(url)
6161
except Exception as e:
62-
if not cls.notebook_thread.is_alive():
62+
if not cls.server_thread.is_alive():
6363
raise RuntimeError("The Jupyter server failed to start")
6464
time.sleep(POLL_INTERVAL)
6565
else:
@@ -70,8 +70,8 @@ def wait_until_alive(cls):
7070
@classmethod
7171
def wait_until_dead(cls):
7272
"""Wait for the server process to terminate after shutdown"""
73-
cls.notebook_thread.join(timeout=MAX_WAITTIME)
74-
if cls.notebook_thread.is_alive():
73+
cls.server_thread.join(timeout=MAX_WAITTIME)
74+
if cls.server_thread.is_alive():
7575
raise TimeoutError("Undead Jupyter server")
7676

7777
@classmethod
@@ -110,11 +110,10 @@ def tmp(*parts):
110110
data_dir = cls.data_dir = tmp('data')
111111
config_dir = cls.config_dir = tmp('config')
112112
runtime_dir = cls.runtime_dir = tmp('runtime')
113-
cls.root_dir = tmp('notebooks')
113+
cls.root_dir = tmp('root_dir')
114114
cls.env_patch = patch.dict('os.environ', {
115115
'HOME': cls.home_dir,
116116
'PYTHONPATH': os.pathsep.join(sys.path),
117-
'IPYTHONDIR': pjoin(cls.home_dir, '.ipython'),
118117
'JUPYTER_NO_CONFIG': '1', # needed in the future
119118
'JUPYTER_CONFIG_DIR' : config_dir,
120119
'JUPYTER_DATA_DIR' : data_dir,
@@ -140,7 +139,7 @@ def start_thread():
140139
if 'asyncio' in sys.modules:
141140
import asyncio
142141
asyncio.set_event_loop(asyncio.new_event_loop())
143-
app = cls.notebook = ServerApp(
142+
app = cls.server = ServerApp(
144143
port=cls.port,
145144
port_retries=0,
146145
open_browser=False,
@@ -170,15 +169,15 @@ def start_thread():
170169
# set the event, so failure to start doesn't cause a hang
171170
started.set()
172171
app.session_manager.close()
173-
cls.notebook_thread = Thread(target=start_thread)
174-
cls.notebook_thread.daemon = True
175-
cls.notebook_thread.start()
172+
cls.server_thread = Thread(target=start_thread)
173+
cls.server_thread.daemon = True
174+
cls.server_thread.start()
176175
started.wait()
177176
cls.wait_until_alive()
178177

179178
@classmethod
180179
def teardown_class(cls):
181-
cls.notebook.stop()
180+
cls.server.stop()
182181
cls.wait_until_dead()
183182
cls.env_patch.stop()
184183
cls.path_patch.stop()

jupyter_server/tests/test_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_hidden_files(self):
5757
r = self.request('GET', url_path_join('files', d, foo))
5858
self.assertEqual(r.status_code, 404)
5959

60-
self.notebook.contents_manager.allow_hidden = True
60+
self.server.contents_manager.allow_hidden = True
6161
try:
6262
for d in not_hidden:
6363
path = pjoin(rootdir, d.replace('/', os.sep))
@@ -75,7 +75,7 @@ def test_hidden_files(self):
7575
r.raise_for_status()
7676
self.assertEqual(r.text, foo)
7777
finally:
78-
self.notebook.contents_manager.allow_hidden = False
78+
self.server.contents_manager.allow_hidden = False
7979

8080
def test_contents_manager(self):
8181
"make sure ContentsManager returns right files (ipynb, bin, txt)."

0 commit comments

Comments
 (0)