From 6896aacdf6291799e97cb4875303b71d44cc37ca Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 16 Dec 2018 21:06:36 +0100 Subject: [PATCH 1/2] Add failing test for list_running_servers --- notebook/tests/test_notebookapp.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/notebook/tests/test_notebookapp.py b/notebook/tests/test_notebookapp.py index 0c277e80d9..ff34a97776 100644 --- a/notebook/tests/test_notebookapp.py +++ b/notebook/tests/test_notebookapp.py @@ -25,6 +25,8 @@ from notebook.auth.security import passwd_check NotebookApp = notebookapp.NotebookApp +from .launchnotebook import NotebookTestBase + def test_help_output(): """ipython notebook --help-all works""" @@ -183,3 +185,10 @@ def list_running_servers(runtime_dir): app.start() nt.assert_equal(exc.exception.code, 1) nt.assert_equal(len(app.servers_shut_down), 0) + + +class NotebookAppTests(NotebookTestBase): + def test_list_running_servers(self): + servers = list(notebookapp.list_running_servers()) + assert len(servers) >= 1 + assert self.port in {info['port'] for info in servers} From adcb7025cab9ddb73fb54b40be7d50dd67311983 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 16 Dec 2018 21:06:55 +0100 Subject: [PATCH 2/2] Make filename check in list_running_servers more specific Closes gh-4283 --- notebook/notebookapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index c180bea4d2..05e44cf29f 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -1839,7 +1839,7 @@ def list_running_servers(runtime_dir=None): return for file_name in os.listdir(runtime_dir): - if file_name.startswith('nbserver-'): + if re.match('nbserver-(.+).json', file_name): with io.open(os.path.join(runtime_dir, file_name), encoding='utf-8') as f: info = json.load(f)