Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/python-wasm/src/test/python-async.test.ts
1067 views
1
import { asyncPython } from "../node";
2
3
// TODO: I have seen this test random fail sometimes, where
4
// it hangs. Not sure why. Hence skipping.
5
//
6
// Error is ENOENT: no such file or directory, uv_cwd so I suspect conflict
7
// between node threads.
8
9
10
test.skip("add 2+3 (async version)", async () => {
11
const { exec, repr, kernel } = await asyncPython();
12
await exec("a = 2+3");
13
expect(await repr("a")).toBe("5");
14
kernel.terminate();
15
});
16
17
test.skip("sleeping for a quarter of a second (async version)", async () => {
18
const { exec, kernel } = await asyncPython();
19
const t0 = new Date().valueOf();
20
await exec("import time; time.sleep(0.25)");
21
const t = new Date().valueOf() - t0;
22
expect(t >= 240 && t <= 1000).toBe(true);
23
kernel.terminate();
24
});
25
26
27