mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 19:53:00 -05:00
* PyodideRuntime should be one of the runtimes * subsume interpreter into runtime API * fix eslint * add comments * move initializers, postInitializers, scriptsQueue, etc. to initialize() of Runtime Super Class * modify comment for initialize * small renaming * change id to default * fix pyscript.py import * try adding tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add inlineDynamicImports option * Make jest happy about ESM modules * Attempt to make jest happy about pyodide * point to version in accordance with node module being used * fix base.ts * fix tests * fix indexURL path determination * edit pyodide.asm.js as a part of setup process * load runtime beforeAll tests * add test for loading a package * use only runPythonAsync underneath for pyodide * import PyodideInterface type directly from pyodide * add some comments Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Philipp Rudiger <prudiger@anaconda.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Runtime } from '../../src/runtime';
|
|
import { PyodideRuntime } from '../../src/pyodide';
|
|
|
|
import { TextEncoder, TextDecoder } from 'util'
|
|
global.TextEncoder = TextEncoder
|
|
global.TextDecoder = TextDecoder
|
|
|
|
describe('PyodideRuntime', () => {
|
|
let runtime: PyodideRuntime;
|
|
beforeAll(async () => {
|
|
runtime = new PyodideRuntime();
|
|
await runtime.initialize();
|
|
});
|
|
|
|
it('should check if runtime is an instance of abstract Runtime', async () => {
|
|
expect(runtime).toBeInstanceOf(Runtime);
|
|
});
|
|
|
|
it('should check if runtime is an instance of PyodideRuntime', async () => {
|
|
expect(runtime).toBeInstanceOf(PyodideRuntime);
|
|
});
|
|
|
|
it('should check if runtime can run python code asynchronously', async () => {
|
|
expect(await runtime.run("2+3")).toBe(5);
|
|
});
|
|
|
|
it('should check if runtime is able to load a package', async () => {
|
|
await runtime.loadPackage("numpy");
|
|
await runtime.run("import numpy as np");
|
|
await runtime.run("x = np.ones((10,))");
|
|
expect(runtime.globals.get('x').toJs()).toBeInstanceOf(Float64Array);
|
|
});
|
|
|
|
});
|