Skip to content

Commit 978026e

Browse files
committed
Assert status field and return execution_count
1 parent c67d0cd commit 978026e

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

crates/amalthea/src/fixtures/dummy_frontend.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,25 @@ impl DummyFrontend {
160160
Message::read_from_socket(&self.shell_socket).unwrap()
161161
}
162162

163-
/// Receive from Shell and assert ExecuteReply message
164-
pub fn recv_shell_execute_reply(&self) -> Status {
163+
/// Receive from Shell and assert `ExecuteReply` message.
164+
/// Returns `execution_count`.
165+
pub fn recv_shell_execute_reply(&self) -> u32 {
165166
let msg = self.recv_shell();
166167

167168
assert_match!(msg, Message::ExecuteReply(data) => {
168-
data.content.status
169+
assert_eq!(data.content.status, Status::Ok);
170+
data.content.execution_count
169171
})
170172
}
171173

172-
/// Receive from Shell and assert ExecuteReplyException message
173-
pub fn recv_shell_execute_reply_exception(&self) -> Status {
174-
let msg = Message::read_from_socket(&self.shell_socket).unwrap();
174+
/// Receive from Shell and assert `ExecuteReplyException` message.
175+
/// Returns `execution_count`.
176+
pub fn recv_shell_execute_reply_exception(&self) -> u32 {
177+
let msg = self.recv_shell();
175178

176179
assert_match!(msg, Message::ExecuteReplyException(data) => {
177-
data.content.status
180+
assert_eq!(data.content.status, Status::Error);
181+
data.content.execution_count
178182
})
179183
}
180184

crates/ark/tests/kernel.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use amalthea::wire::jupyter_message::Message;
2-
use amalthea::wire::jupyter_message::Status;
32
use amalthea::wire::kernel_info_request::KernelInfoRequest;
43
use ark::fixtures::DummyArkFrontend;
54
use stdext::assert_match;
@@ -28,12 +27,13 @@ fn test_execute_request() {
2827
frontend.send_execute_request("42");
2928
frontend.recv_iopub_busy();
3029

31-
assert_eq!(frontend.recv_iopub_execute_input().code, "42");
30+
let input = frontend.recv_iopub_execute_input();
31+
assert_eq!(input.code, "42");
3232
assert_eq!(frontend.recv_iopub_execute_result(), "[1] 42");
3333

3434
frontend.recv_iopub_idle();
3535

36-
assert_eq!(frontend.recv_shell_execute_reply(), Status::Ok);
36+
assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count)
3737
}
3838

3939
#[test]
@@ -43,10 +43,14 @@ fn test_execute_request_error() {
4343
frontend.send_execute_request("stop('foobar')");
4444
frontend.recv_iopub_busy();
4545

46-
assert_eq!(frontend.recv_iopub_execute_input().code, "stop('foobar')");
46+
let input = frontend.recv_iopub_execute_input();
47+
assert_eq!(input.code, "stop('foobar')");
4748
assert!(frontend.recv_iopub_execute_error().contains("foobar"));
4849

4950
frontend.recv_iopub_idle();
5051

51-
assert_eq!(frontend.recv_shell_execute_reply_exception(), Status::Error);
52+
assert_eq!(
53+
frontend.recv_shell_execute_reply_exception(),
54+
input.execution_count
55+
);
5256
}

0 commit comments

Comments
 (0)