Skip to content

Commit 3ccc212

Browse files
committed
test - add a test to check it errors on display error
1 parent f8122fc commit 3ccc212

File tree

4 files changed

+86
-14
lines changed

4 files changed

+86
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.quarto_ipynb
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: test
3+
format: html
4+
_quarto:
5+
tests:
6+
html:
7+
shouldError: default
8+
---
9+
10+
With default setting, this document should error at rendering because of Exception at IPython.display level.
11+
12+
By default `nbconvert` does not throw exception for error thrown by IPython display, on purpose as document output is still valid as there are other representation.
13+
14+
```{python}
15+
# First cell - create an object with a buggy _repr_html_ method
16+
class BuggyDisplay:
17+
def __init__(self):
18+
self.data = "This works fine"
19+
20+
def _repr_html_(self):
21+
# This error happens during display, not execution
22+
# raise ValueError("Display phase error!")
23+
return "<b>HTML fallback:</b> " + self.data
24+
25+
def _repr_markdown_(self):
26+
# Markdown representation as fallback when HTML fails
27+
# return "**Markdown fallback:** " + self.data
28+
raise ValueError("Display phase error!")
29+
30+
def __repr__(self):
31+
# This ensures the object has a string representation
32+
return self.data
33+
34+
# Create the object
35+
buggy = BuggyDisplay()
36+
```
37+
38+
```{python}
39+
# Second cell - display the object (triggers error in _repr_html_)
40+
# This will show an error in the output but won't stop execution
41+
buggy
42+
```
43+
44+
```{python}
45+
# Third cell - proves execution continues
46+
print("Execution continued despite display error")
47+
```

tests/smoke/smoke-all.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
ensurePptxMaxSlides,
3535
ensureLatexFileRegexMatches,
3636
printsMessage,
37+
shouldError
3738
} from "../verify.ts";
3839
import { readYamlFromMarkdown } from "../../src/core/yaml.ts";
3940
import { findProjectDir, findProjectOutputDir, outputForInput } from "../utils.ts";
@@ -134,7 +135,10 @@ function resolveTestSpecs(
134135
// deno-lint-ignore no-explicit-any
135136
const [key, value] of Object.entries(testObj as Record<string, any>)
136137
) {
137-
if (key === "noErrors") {
138+
if (key == "shouldError") {
139+
checkWarnings = false;
140+
verifyFns.push(shouldError);
141+
} else if (key === "noErrors") {
138142
checkWarnings = false;
139143
verifyFns.push(noErrors);
140144
} else {

tests/verify.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,45 @@ export const withPptxContent = async <T>(
8383
}
8484
};
8585

86+
const checkErrors = (outputs: ExecuteOutput[]): { errors: boolean, messages: string | undefined } => {
87+
const isError = (output: ExecuteOutput) => {
88+
return output.levelName.toLowerCase() === "error";
89+
};
90+
const errors = outputs.some(isError);
91+
92+
const messages = errors ? outputs.filter(isError).map((outputs) => outputs.msg).join("\n") : undefined
93+
94+
return({
95+
errors,
96+
messages
97+
})
98+
}
99+
86100
export const noErrors: Verify = {
87101
name: "No Errors",
88102
verify: (outputs: ExecuteOutput[]) => {
89-
const isError = (output: ExecuteOutput) => {
90-
return output.levelName.toLowerCase() === "error";
91-
};
103+
104+
const { errors, messages } = checkErrors(outputs);
92105

93-
const errors = outputs.some(isError);
106+
assert(
107+
!errors,
108+
`Errors During Execution\n|${messages}|`,
109+
);
94110

95-
// Output an error or warning if it exists
96-
if (errors) {
97-
const messages = outputs.filter(isError).map((outputs) => outputs.msg)
98-
.join("\n");
111+
return Promise.resolve();
112+
},
113+
};
99114

100-
assert(
101-
!errors,
102-
`Errors During Execution\n|${messages}|`,
103-
);
104-
}
115+
export const shouldError: Verify = {
116+
name: "Should Error",
117+
verify: (outputs: ExecuteOutput[]) => {
118+
119+
const { errors } = checkErrors(outputs);
120+
121+
assert(
122+
errors,
123+
`No errors during execution while rendering was expected to fail.`,
124+
);
105125

106126
return Promise.resolve();
107127
},

0 commit comments

Comments
 (0)