-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Samuel Colvin <[email protected]>
- Loading branch information
1 parent
4cefa8b
commit 9983083
Showing
5 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "jiter", | ||
"version": "1.0.0", | ||
"description": "for running wasm tests.", | ||
"author": "Samuel Colvin", | ||
"license": "MIT", | ||
"homepage": "https://github.com/pydantic/jiter#readme", | ||
"main": "tests/emscripten_runner.js", | ||
"dependencies": { | ||
"prettier": "^2.7.1", | ||
"pyodide": "^0.26.3" | ||
}, | ||
"scripts": { | ||
"test": "node tests/emscripten_runner.js", | ||
"format": "prettier --write 'tests/emscripten_runner.js' 'wasm-preview/*.{html,js}'", | ||
"lint": "prettier --check 'tests/emscripten_runner.js' 'wasm-preview/*.{html,js}'" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"printWidth": 119, | ||
"bracketSpacing": false, | ||
"arrowParens": "avoid" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const {opendir} = require('node:fs/promises'); | ||
const {loadPyodide} = require('pyodide'); | ||
const path = require('path'); | ||
|
||
async function find_wheel(dist_dir) { | ||
const dir = await opendir(dist_dir); | ||
for await (const dirent of dir) { | ||
if (dirent.name.endsWith('.whl')) { | ||
return path.join(dist_dir, dirent.name); | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
const root_dir = path.resolve(__dirname, '..'); | ||
const wheel_path = await find_wheel(path.join(root_dir, 'dist')); | ||
const stdout = [] | ||
const stderr = [] | ||
let errcode = 1; | ||
try { | ||
const pyodide = await loadPyodide({ | ||
stdout: (msg) => { | ||
stdout.push(msg) | ||
}, | ||
stderr: (msg) => { | ||
stderr.push(msg) | ||
} | ||
}); | ||
const FS = pyodide.FS; | ||
FS.mkdir('/test_dir'); | ||
FS.mount(FS.filesystems.NODEFS, {root: path.join(root_dir, 'tests')}, '/test_dir'); | ||
FS.chdir('/test_dir'); | ||
|
||
// mount jiter crate source for benchmark data | ||
FS.mkdir('/jiter'); | ||
FS.mount(FS.filesystems.NODEFS, {root: path.resolve(root_dir, "..", "jiter")}, '/jiter'); | ||
|
||
await pyodide.loadPackage(['micropip', 'pytest']); | ||
// language=python | ||
errcode = await pyodide.runPythonAsync(` | ||
import micropip | ||
import importlib | ||
# ugly hack to get tests to work on arm64 (my m1 mac) | ||
# see https://github.com/pyodide/pyodide/issues/2840 | ||
# import sys; sys.setrecursionlimit(200) | ||
await micropip.install([ | ||
'dirty_equals', | ||
'file:${wheel_path}' | ||
]) | ||
importlib.invalidate_caches() | ||
print('installed packages:', micropip.list()) | ||
import pytest | ||
pytest.main() | ||
`); | ||
} catch (e) { | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
let out = stdout.join('\n') | ||
let err = stderr.join('\n') | ||
console.log('stdout:\n', out) | ||
console.log('stderr:\n', err) | ||
|
||
process.exit(errcode); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters