Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/python-wasm/src/test/posix/stdlib.test.ts
1067 views
1
import { syncPython } from "../../node";
2
3
test("mkstemp system call -- hitting the memfs filesystem", async () => {
4
const { kernel } = await syncPython({ fs: "everything" });
5
const fd = kernel.callWithString("mkstemp", "/usr/lib/python3.11/fooXXXXXX");
6
expect(fd).toBeGreaterThan(0);
7
const path = kernel.wasi?.FD_MAP.get(fd)?.path;
8
if (path == null) throw Error("bug");
9
expect(path.startsWith("/usr/lib/python3.11/foo")).toBe(true);
10
kernel.fs?.unlinkSync(path);
11
});
12
13
test("mkstemp system call -- hitting native fs (this tests that fs.constants is mapped properly on non-linux at least)", async () => {
14
const { kernel } = await syncPython();
15
const mkstemp = kernel.getFunction("mkstemp");
16
if (mkstemp == null) throw Error("bug");
17
const fd = mkstemp(kernel.send.string("/tmp/fooXXXXXX"));
18
expect(fd).toBeGreaterThan(0);
19
const path = kernel.wasi?.FD_MAP.get(fd)?.path;
20
if (path == null) throw Error("bug");
21
expect(path.startsWith("/tmp/foo")).toBe(true);
22
kernel.fs?.unlinkSync(path);
23
});
24
25
// >>> import os; os.getloadavg()
26
// (6.1474609375, 4.72021484375, 4.55126953125)
27
test("getting load average works", async () => {
28
const { exec, repr } = await syncPython();
29
exec("import os");
30
const v = eval(repr("list(os.getloadavg())"));
31
expect(v.length).toBe(3);
32
expect(typeof v[0]).toBe("number");
33
});
34
35