Skip to content

Commit eb6333f

Browse files
diningPhilosopher64prabhakk-mw
authored andcommitted
Test refactoring
1 parent 7c3edbf commit eb6333f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/jupyter_matlab_kernel/kernels/comms/labextension.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def comm_open(self, stream, ident, msg):
2323
)
2424
comm = Comm(comm_id=comm_id, primary=False, target_name=target_name)
2525
self.comms[comm_id] = comm
26-
self.log.info("Successfully created communication channel with labextension")
26+
self.log.debug(
27+
f"Successfully created communication channel with labextension on: {comm_id}"
28+
)
2729

2830
async def comm_msg(self, stream, ident, msg):
2931
"""Handler to execute when labextension sends a message with 'comm_msg' type."""

tests/unit/jupyter_matlab_kernel/comms/test_labextension.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
LabExtensionCommunication,
66
)
77

8+
from unittest.mock import call
9+
810

911
@pytest.fixture
1012
def mock_kernel(mocker):
@@ -74,14 +76,17 @@ def test_comm_open_creates_comm(
7476

7577
# Verify comm is set
7678
assert labext_comm.comms[test_comm_id] is mock_comm
77-
78-
# Verify logging
79-
labext_comm.log.debug.assert_called_once_with(
80-
f"Received comm_open message with id: {test_comm_id} and target_name: {test_target_name}"
81-
)
82-
labext_comm.log.info.assert_called_once_with(
83-
"Successfully created communication channel with labextension"
84-
)
79+
# Verify debug is called twice and with the right messages
80+
assert labext_comm.log.debug.call_count == 2
81+
expected_calls = [
82+
call(
83+
f"Received comm_open message with id: {test_comm_id} and target_name: {test_target_name}"
84+
),
85+
call(
86+
f"Successfully created communication channel with labextension on: {test_comm_id}"
87+
),
88+
]
89+
labext_comm.log.debug.assert_has_calls(expected_calls, any_order=True)
8590

8691

8792
@pytest.mark.asyncio

0 commit comments

Comments
 (0)