Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/python-wasm/src/extension/hello.test.ts
1067 views
1
import { syncPython } from "../node";
2
import { join } from "path";
3
4
// Test that it is possible to import a dynamic library
5
test("hello extension module loads and works", async () => {
6
const { exec, repr } = await syncPython();
7
const dist = join(__dirname, "..");
8
exec(`import sys; sys.path.insert(0,'${dist}')`);
9
exec("import hello");
10
expect(parseInt(repr("hello.add389(10)"))).toBe(10 + 389);
11
});
12
13
// Test that it is not stupidly slow, which could happen if
14
// we are not sufficiently clever regarding how dynamic
15
// linking works.
16
test("not stupidly slow", async () => {
17
const { exec, repr } = await syncPython();
18
const dist = join(__dirname, "..");
19
exec(`import sys; sys.path.insert(0,'${dist}')`);
20
exec("import hello");
21
const t = new Date().valueOf();
22
repr("sum(hello.add389(10) for _ in range(10**5))");
23
expect(new Date().valueOf() - t).toBeLessThan(1000);
24
});
25
26