@@ -116,13 +116,18 @@ async def test_deprecated_features(kernel):
116116 kernel .shell_streams = [kernel .shell_stream , kernel .shell_stream ]
117117
118118
119- async def test_process_control (kernel ):
119+ async def test_process_control (kernel , caplog ):
120120 from jupyter_client .session import DELIM
121121
122122 class FakeMsg :
123123 def __init__ (self , bytes ):
124124 self .bytes = bytes
125125
126+ caplog .clear ()
127+ await kernel .process_control ([FakeMsg (b"bad" )])
128+ assert "Invalid Control Message" in caplog .text
129+ assert "DELIM not in msg_list" in caplog .text
130+
126131 await kernel .process_control ([FakeMsg (DELIM ), 1 ])
127132 msg = kernel ._prep_msg ("does_not_exist" )
128133 await kernel .process_control (msg )
@@ -133,18 +138,48 @@ def test_should_handle(kernel):
133138 assert kernel .should_handle (kernel .control_stream , msg , []) is True
134139
135140
136- async def test_dispatch_shell (kernel ):
141+ async def test_dispatch_shell (kernel , caplog ):
137142 from jupyter_client .session import DELIM
138143
139144 class FakeMsg :
140145 def __init__ (self , bytes ):
141146 self .bytes = bytes
147+ self .buffer = bytes
148+
149+ caplog .clear ()
150+ await kernel .dispatch_shell ([FakeMsg (b"bad" )])
151+ assert "Invalid Message" in caplog .text
152+ assert "DELIM not in msg_list" in caplog .text
142153
143154 await kernel .dispatch_shell ([FakeMsg (DELIM ), 1 ])
144155 msg = kernel ._prep_msg ("does_not_exist" )
145156 await kernel .dispatch_shell (msg )
146157
147158
159+ async def test_shell_channel_thread_main (kernel , monkeypatch , caplog ):
160+ import asyncio
161+ import threading
162+
163+ from jupyter_client .session import DELIM
164+
165+ class FakeMsg :
166+ def __init__ (self , bytes ):
167+ self .bytes = bytes
168+
169+ current = threading .current_thread ()
170+ monkeypatch .setattr (current , "asyncio_lock" , asyncio .Lock (), raising = False )
171+ monkeypatch .setattr (kernel , "shell_channel_thread" , current )
172+
173+ caplog .clear ()
174+ await kernel .shell_channel_thread_main ([FakeMsg (b"bad" )])
175+ assert "Invalid message" in caplog .text
176+ assert "DELIM not in msg_list" in caplog .text
177+
178+ caplog .clear ()
179+ await kernel .shell_channel_thread_main ([FakeMsg (DELIM ), 1 ])
180+ assert "Invalid message" in caplog .text
181+
182+
148183async def test_publish_debug_event (kernel ):
149184 kernel ._publish_debug_event ({})
150185
0 commit comments