Skip to content

Commit 6ea1bf2

Browse files
committed
test - check jupyter cache is working and folder can be changed
1 parent 702416e commit 6ea1bf2

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JUPYTERCACHE=".cache/jupyter-cache"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project:
2+
type: default
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: test1
3+
cache: true
4+
---
5+
6+
```{python}
7+
1+1
8+
```

tests/smoke/jupyter/cache.test.ts

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,86 @@
33
*
44
* Copyright (C) 2023 Posit Software, PBC
55
*/
6+
import { dirname, join } from "path";
67
import { quarto } from "../../../src/quarto.ts";
78
import { test } from "../../test.ts";
8-
import { assertEquals } from "testing/asserts";
9+
import { docs } from "../../utils.ts";
10+
import { folderExists, printsMessage } from "../../verify.ts";
11+
import { fileLoader } from "../../utils.ts";
12+
import { safeExistsSync, safeRemoveSync } from "../../../src/core/path.ts";
13+
14+
const testInput = fileLoader("jupyter", "cache")("test.qmd", "html")
15+
const cacheFolder = join(dirname(testInput.input), ".jupyter_cache")
916

1017
test({
11-
name: "jupyter:cache:test-1",
12-
context: {},
18+
name: "Jupyter cache is working",
1319
execute: async () => {
1420
// return await new Promise((_resolve, reject) => {
1521
// setTimeout(reject, 10000, "timed out after 10 seconds");
1622
// })
1723
// https://github.com/quarto-dev/quarto-cli/issues/9618
1824
// repeated executions to trigger jupyter cache
19-
await quarto(["render", "docs/jupyter/cache/test.qmd", "--no-execute-daemon"]);
20-
await quarto(["render", "docs/jupyter/cache/test.qmd", "--no-execute-daemon"]);
25+
await quarto(["render", testInput.input, "--to", "html", "--no-execute-daemon"]);
26+
await quarto(["render", testInput.input, "--to", "html", "--no-execute-daemon"]);
27+
},
28+
context: {
29+
teardown: async () => {
30+
if (safeExistsSync(cacheFolder)) {
31+
safeRemoveSync(cacheFolder, { recursive: true });
32+
}
33+
if (safeExistsSync(testInput.output.outputPath)) {
34+
safeRemoveSync(testInput.output.outputPath);
35+
}
36+
if (safeExistsSync(testInput.output.supportPath)) {
37+
safeRemoveSync(testInput.output.supportPath, { recursive: true });
38+
}
39+
}
2140
},
22-
verify: [],
41+
verify: [
42+
folderExists(cacheFolder),
43+
// this will check only for the second render that should be read from cache
44+
printsMessage("INFO", /Notebook read from cache/)
45+
],
2346
type: "smoke",
2447
});
48+
49+
// -- Testing changing cache folder
50+
51+
const testInput2 = fileLoader("jupyter", "cache-non-default")("test.qmd", "html")
52+
// From value of cache set in _environment in test quarto project
53+
const cacheFolder2 = join(dirname(testInput2.input), ".cache/jupyter-cache")
54+
55+
test({
56+
name: "Jupyter cache folder can be change",
57+
execute: async () => {
58+
// return await new Promise((_resolve, reject) => {
59+
// setTimeout(reject, 10000, "timed out after 10 seconds");
60+
// })
61+
// https://github.com/quarto-dev/quarto-cli/issues/9618
62+
// repeated executions to trigger jupyter cache
63+
await quarto(["render", testInput2.input, "--to", "html", "--no-execute-daemon"]);
64+
await quarto(["render", testInput2.input, "--to", "html", "--no-execute-daemon"]);
65+
},
66+
context: {
67+
teardown: async () => {
68+
if (safeExistsSync(cacheFolder2)) {
69+
safeRemoveSync(cacheFolder2, { recursive: true });
70+
}
71+
if (safeExistsSync(testInput2.output.outputPath)) {
72+
safeRemoveSync(testInput2.output.outputPath);
73+
}
74+
if (safeExistsSync(testInput2.output.supportPath)) {
75+
safeRemoveSync(testInput2.output.supportPath, { recursive: true });
76+
}
77+
if (safeExistsSync(join(dirname(testInput2.input), ".quarto"))) {
78+
safeRemoveSync(join(dirname(testInput2.input), ".quarto"), { recursive: true });
79+
}
80+
}
81+
},
82+
verify: [
83+
folderExists(cacheFolder2),
84+
// this will check only for the second render that should be read from cache
85+
printsMessage("INFO", /Notebook read from cache/)
86+
],
87+
type: "smoke",
88+
});

0 commit comments

Comments
 (0)