Skip to content

Commit

Permalink
Add tests for incompete inputs and browser prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Oct 4, 2024
1 parent adaf4e7 commit 70b5a59
Showing 1 changed file with 179 additions and 2 deletions.
181 changes: 179 additions & 2 deletions crates/ark/tests/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,195 @@ fn test_kernel_info() {
fn test_execute_request() {
let frontend = DummyArkFrontend::lock();

frontend.send_execute_request("42", ExecuteRequestOptions::default());
let code = "42";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, "42");
assert_eq!(input.code, code);
assert_eq!(frontend.recv_iopub_execute_result(), "[1] 42");

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);
}

#[test]
fn test_execute_request_empty() {
let frontend = DummyArkFrontend::lock();

let code = "";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);

// Equivalent to invisible output
let code = "invisible(1)";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);
}

#[test]
fn test_execute_request_multiple_lines() {
let frontend = DummyArkFrontend::lock();

let code = "1 +\n 2+\n 3";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);
assert_eq!(frontend.recv_iopub_execute_result(), "[1] 6");

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count)
}

#[test]
fn test_execute_request_incomplete() {
let frontend = DummyArkFrontend::lock();

let code = "1 +";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

assert!(frontend
.recv_iopub_execute_error()
.contains("Can't execute incomplete input"));

frontend.recv_iopub_idle();

assert_eq!(
frontend.recv_shell_execute_reply_exception(),
input.execution_count
)
}

#[test]
fn test_execute_request_incomplete_multiple_lines() {
let frontend = DummyArkFrontend::lock();

let code = "1 +\n2 +";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

assert!(frontend
.recv_iopub_execute_error()
.contains("Can't execute incomplete input"));

frontend.recv_iopub_idle();

assert_eq!(
frontend.recv_shell_execute_reply_exception(),
input.execution_count
)
}

#[test]
fn test_execute_request_browser() {
let frontend = DummyArkFrontend::lock();

let code = "browser()";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

assert!(frontend
.recv_iopub_execute_result()
.contains("Called from: top level"));

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);

let code = "Q";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);
}

#[test]
fn test_execute_request_browser_incomplete() {
let frontend = DummyArkFrontend::lock();

let code = "browser()";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

assert!(frontend
.recv_iopub_execute_result()
.contains("Called from: top level"));

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);

let code = "1 +";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

// TODO!: Why do we get the message as a stream?
frontend.recv_iopub_stream_stderr("Error: \nCan't execute incomplete input:\n1 +\n");

// assert!(frontend
// .recv_iopub_execute_error()
// .contains("Can't execute incomplete input"));

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);

// assert_eq!(
// frontend.recv_shell_execute_reply_exception(),
// input.execution_count
// );

let code = "Q";
frontend.send_execute_request(code, ExecuteRequestOptions::default());
frontend.recv_iopub_busy();

let input = frontend.recv_iopub_execute_input();
assert_eq!(input.code, code);

frontend.recv_iopub_idle();

assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count);
}

#[test]
fn test_execute_request_error() {
let frontend = DummyArkFrontend::lock();
Expand Down

0 comments on commit 70b5a59

Please sign in to comment.