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