From 78b8f14cf8a7f6c4fba4cb20edd8fa293ae7a602 Mon Sep 17 00:00:00 2001 From: Hind-M <70631848+Hind-M@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:25:30 +0200 Subject: [PATCH] Add test for Jep #65 (#134) * Add test for Jep #65 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add flag to skip iopub welcome message test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add noqa mention --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- jupyter_kernel_test/__init__.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/jupyter_kernel_test/__init__.py b/jupyter_kernel_test/__init__.py index 2e81d17..c917a7c 100644 --- a/jupyter_kernel_test/__init__.py +++ b/jupyter_kernel_test/__init__.py @@ -405,3 +405,38 @@ def test_clear_output(self): if not found: emsg = "clear_output message not found" raise AssertionError(emsg) + + +class IopubWelcomeTests(TestCase): + kernel_name = "python3" + kc: BlockingKernelClient + km: KernelManager + + @classmethod + def setUpClass(cls): + cls.km = KernelManager(kernel_name=cls.kernel_name) + cls.km.start_kernel() + cls.kc = cls.km.client() + + @classmethod + def tearDownClass(cls): + cls.kc.stop_channels() + cls.km.shutdown_kernel() + + support_iopub_welcome = False + + def test_recv_iopub_welcome_msg(self): + if not self.support_iopub_welcome: + raise SkipTest("Iopub welcome messages are not supported") # noqa + + self.kc.start_channels() + while True: + msg = self.kc.get_iopub_msg() + if msg: + self.assertEqual(msg["header"]["msg_type"], "iopub_welcome") + self.assertEqual(msg["msg_type"], "iopub_welcome") + self.assertEqual( + msg["content"]["subscription"], "" + ) # Default: empty topic means subscription to all topics + + break