From 28ad7610a514476aaa528bbb17120f64e93bfd14 Mon Sep 17 00:00:00 2001 From: qlemaire22 Date: Mon, 27 Jul 2020 15:40:21 +0200 Subject: [PATCH 1/3] Fix iteration over the sessions --- sparkmagic/sparkmagic/serverextension/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparkmagic/sparkmagic/serverextension/handlers.py b/sparkmagic/sparkmagic/serverextension/handlers.py index c94a258ca..581254355 100644 --- a/sparkmagic/sparkmagic/serverextension/handlers.py +++ b/sparkmagic/sparkmagic/serverextension/handlers.py @@ -99,7 +99,7 @@ def _get_kernel_manager(self, path, kernel_name): sessions = self.session_manager.list_sessions() kernel_id = None - for session in sessions: + for session in sessions.result(): if session['notebook']['path'] == path: session_id = session['id'] kernel_id = session['kernel']['id'] From 2b80fa81b2f83fb724c38409e1a4ef5d226778c8 Mon Sep 17 00:00:00 2001 From: qlemaire22 Date: Tue, 28 Jul 2020 09:59:38 +0200 Subject: [PATCH 2/3] Fix test_handlers --- sparkmagic/sparkmagic/serverextension/handlers.py | 8 ++++++-- sparkmagic/sparkmagic/tests/test_handlers.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sparkmagic/sparkmagic/serverextension/handlers.py b/sparkmagic/sparkmagic/serverextension/handlers.py index 581254355..8da7d877f 100644 --- a/sparkmagic/sparkmagic/serverextension/handlers.py +++ b/sparkmagic/sparkmagic/serverextension/handlers.py @@ -94,12 +94,16 @@ def _get_argument_or_raise(self, data, key): except KeyError: raise MissingArgumentError(key) + def _get_list_sessions(self): + sessions = self.session_manager.list_sessions() + return [session for session in sessions.result] + @gen.coroutine def _get_kernel_manager(self, path, kernel_name): - sessions = self.session_manager.list_sessions() + sessions = self._get_list_sessions kernel_id = None - for session in sessions.result(): + for session in sessions: if session['notebook']['path'] == path: session_id = session['id'] kernel_id = session['kernel']['id'] diff --git a/sparkmagic/sparkmagic/tests/test_handlers.py b/sparkmagic/sparkmagic/tests/test_handlers.py index 1e6ad75c8..24be786ac 100644 --- a/sparkmagic/sparkmagic/tests/test_handlers.py +++ b/sparkmagic/sparkmagic/tests/test_handlers.py @@ -69,6 +69,7 @@ def setUp(self): # Create mocked reconnect_handler ReconnectHandler.__bases__ = (SimpleObject,) self.reconnect_handler = ReconnectHandler() + self.reconnect_handler._get_list_sessions = self.session_list self.reconnect_handler.spark_events = self.spark_events self.reconnect_handler.session_manager = self.session_manager self.reconnect_handler.kernel_manager = self.kernel_manager From 42785ffe347571583da1a4645fe648739a4d1285 Mon Sep 17 00:00:00 2001 From: qlemaire22 Date: Fri, 11 Sep 2020 15:40:55 +0200 Subject: [PATCH 3/3] Fix added function --- sparkmagic/sparkmagic/serverextension/handlers.py | 2 +- sparkmagic/sparkmagic/tests/test_handlers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sparkmagic/sparkmagic/serverextension/handlers.py b/sparkmagic/sparkmagic/serverextension/handlers.py index 8da7d877f..0afd7a124 100644 --- a/sparkmagic/sparkmagic/serverextension/handlers.py +++ b/sparkmagic/sparkmagic/serverextension/handlers.py @@ -100,7 +100,7 @@ def _get_list_sessions(self): @gen.coroutine def _get_kernel_manager(self, path, kernel_name): - sessions = self._get_list_sessions + sessions = self._get_list_sessions() kernel_id = None for session in sessions: diff --git a/sparkmagic/sparkmagic/tests/test_handlers.py b/sparkmagic/sparkmagic/tests/test_handlers.py index 24be786ac..94312eff5 100644 --- a/sparkmagic/sparkmagic/tests/test_handlers.py +++ b/sparkmagic/sparkmagic/tests/test_handlers.py @@ -54,7 +54,7 @@ def setUp(self): self.kernel_manager.get_kernel = MagicMock(return_value=self.individual_kernel_manager) # Mock session manager - self.session_list = [self.create_session_dict(self.path, self.kernel_id)] + self.session_list = MagicMock(return_value=[self.create_session_dict(self.path, self.kernel_id)]) self.session_manager = MagicMock() self.session_manager.list_sessions = MagicMock(return_value=self.session_list) self.session_manager.create_session = MagicMock(return_value=self.create_session_dict(self.path, self.kernel_id))