Skip to content

Commit 1fe9c9e

Browse files
authored
Fix Deno display_data to use broadcast API (#7)
* Fix Deno display_data to use broadcast API The Deno.jupyter.html tagged template doesn't emit display_data messages. Use Deno.jupyter.broadcast("display_data", ...) which is proven to work. Also clarify evcxr requires trait impl for display_data. * Add execute_stderr test (Tier 1) Tests that kernels can output to stderr stream correctly.
1 parent 87ccfaa commit 1fe9c9e

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/snippets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl LanguageSnippets {
109109
completion_var: "test_variable_for_completion",
110110
completion_setup: "let test_variable_for_completion = 42;",
111111
completion_prefix: "test_variable_for_",
112-
display_data_code: r#"println!("EVCXR_BEGIN_CONTENT text/html\n<b>bold</b>\nEVCXR_END_CONTENT")"#,
112+
display_data_code: "// evcxr requires evcxr_display trait impl for display_data",
113113
update_display_data_code: "// evcxr doesn't support update_display_data (no display_id)",
114114
}
115115
}
@@ -150,7 +150,7 @@ impl LanguageSnippets {
150150
completion_var: "testVariableForCompletion",
151151
completion_setup: "const testVariableForCompletion = 42",
152152
completion_prefix: "testVariableFor",
153-
display_data_code: "Deno.jupyter.html`<b>bold</b>`",
153+
display_data_code: r#"await Deno.jupyter.broadcast("display_data", { data: { "text/html": "<b>bold</b>" }, metadata: {}, transient: {} })"#,
154154
update_display_data_code: r#"await Deno.jupyter.broadcast("display_data", { data: { "text/html": "<b>initial</b>" }, metadata: {}, transient: { display_id: "test_update" } }); await Deno.jupyter.broadcast("update_display_data", { data: { "text/html": "<b>updated</b>" }, metadata: {}, transient: { display_id: "test_update" } })"#,
155155
}
156156
}

src/tests.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,37 @@ fn test_execute_stdout(
126126
})
127127
}
128128

129+
fn test_execute_stderr(
130+
kernel: &mut KernelUnderTest,
131+
) -> Pin<Box<dyn Future<Output = TestResult> + Send + '_>> {
132+
Box::pin(async move {
133+
let code = kernel.snippets().print_stderr.to_string();
134+
match kernel.execute_and_collect(&code).await {
135+
Ok((_, iopub)) => {
136+
let has_stderr = iopub.iter().any(|msg| {
137+
matches!(
138+
&msg.content,
139+
JupyterMessageContent::StreamContent(StreamContent {
140+
name: jupyter_protocol::messaging::Stdio::Stderr,
141+
text,
142+
}) if text.contains("error")
143+
)
144+
});
145+
if has_stderr {
146+
TestResult::Pass
147+
} else {
148+
TestResult::Fail { kind: None,
149+
reason: "No stderr containing 'error'".to_string(),
150+
}
151+
}
152+
}
153+
Err(e) => TestResult::Fail { kind: None,
154+
reason: e.to_string(),
155+
},
156+
}
157+
})
158+
}
159+
129160
fn test_execute_reply_ok(
130161
kernel: &mut KernelUnderTest,
131162
) -> Pin<Box<dyn Future<Output = TestResult> + Send + '_>> {
@@ -845,6 +876,13 @@ pub fn all_tests() -> Vec<ConformanceTest> {
845876
message_type: "execute_request",
846877
run: test_execute_stdout,
847878
},
879+
ConformanceTest {
880+
name: "execute_stderr",
881+
category: TestCategory::Tier1Basic,
882+
description: "Execute code that prints to stderr produces stream message",
883+
message_type: "stream",
884+
run: test_execute_stderr,
885+
},
848886
ConformanceTest {
849887
name: "execute_reply_ok",
850888
category: TestCategory::Tier1Basic,

0 commit comments

Comments
 (0)