Path: blob/main/python/python-wasm/src/extension/hello.test.ts
1067 views
import { syncPython } from "../node";1import { join } from "path";23// Test that it is possible to import a dynamic library4test("hello extension module loads and works", async () => {5const { exec, repr } = await syncPython();6const dist = join(__dirname, "..");7exec(`import sys; sys.path.insert(0,'${dist}')`);8exec("import hello");9expect(parseInt(repr("hello.add389(10)"))).toBe(10 + 389);10});1112// Test that it is not stupidly slow, which could happen if13// we are not sufficiently clever regarding how dynamic14// linking works.15test("not stupidly slow", async () => {16const { exec, repr } = await syncPython();17const dist = join(__dirname, "..");18exec(`import sys; sys.path.insert(0,'${dist}')`);19exec("import hello");20const t = new Date().valueOf();21repr("sum(hello.add389(10) for _ in range(10**5))");22expect(new Date().valueOf() - t).toBeLessThan(1000);23});242526