-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4d2c63
commit 2bfbddd
Showing
7 changed files
with
173 additions
and
19 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
{ | ||
"name": "pyodide_test", | ||
"version": "0.0.0", | ||
"main": "test.js", | ||
"scripts": { | ||
"test": "node --experimental-wasm-stack-switching test.mjs" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"description": "", | ||
"dependencies": { | ||
"pyodide": "^0.27.2" | ||
} | ||
} |
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,57 @@ | ||
import {opendir} from 'node:fs/promises' | ||
import path from 'path' | ||
import assert from 'assert' | ||
import { loadPyodide } from 'pyodide' | ||
|
||
|
||
async function runTest() { | ||
const wheelPath = await findWheel(path.join(path.resolve(import.meta.dirname, '..'), 'dist')); | ||
const stdout = [] | ||
const stderr = [] | ||
const pyodide = await loadPyodide({ | ||
|
||
stdout: (msg) => { | ||
stdout.push(msg) | ||
}, | ||
stderr: (msg) => { | ||
stderr.push(msg) | ||
} | ||
}) | ||
await pyodide.loadPackage(['micropip', 'pygments']) | ||
console.log('Running Pyodide test...\n') | ||
await pyodide.runPythonAsync(` | ||
import sys | ||
import micropip | ||
await micropip.install(['file:${wheelPath}']) | ||
import logfire | ||
logfire.configure(token='unknown', inspect_arguments=False) | ||
logfire.info('hello {name}', name='world') | ||
sys.stdout.flush() | ||
sys.stderr.flush() | ||
`) | ||
let out = stdout.join('') | ||
let err = stderr.join('') | ||
console.log('stdout:', out) | ||
console.log('stderr:', err) | ||
assert.ok(out.includes('hello world')) | ||
|
||
assert.ok( | ||
err.includes( | ||
'UserWarning: Logfire API returned status code 401.' | ||
), | ||
) | ||
console.log('\n\nLogfire Pyodide tests passed 🎉') | ||
} | ||
|
||
|
||
async function findWheel(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); | ||
} | ||
} | ||
} | ||
|
||
runTest().catch(console.error) |
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