44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { existsSync } from 'node:fs';
|
|
import { delimiter, dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { expect, test } from 'bun:test';
|
|
|
|
const repoRoot = fileURLToPath(new URL('../../', import.meta.url));
|
|
const pythonDir = join(repoRoot, 'python');
|
|
const venvPython = join(pythonDir, '.venv/bin/python');
|
|
|
|
function buildEnv(baseEnv: NodeJS.ProcessEnv = process.env): Record<string, string> {
|
|
const env: Record<string, string> = {};
|
|
for (const [key, value] of Object.entries(baseEnv)) {
|
|
if (value !== undefined) {
|
|
env[key] = value;
|
|
}
|
|
}
|
|
const bunDir = dirname(process.execPath);
|
|
env.PATH = env.PATH ? `${bunDir}${delimiter}${env.PATH}` : bunDir;
|
|
env.PYTHONPATH = pythonDir;
|
|
env.PYTHONDONTWRITEBYTECODE = '1';
|
|
return env;
|
|
}
|
|
|
|
test(
|
|
'python stockbot SDK offline pytest suite passes',
|
|
() => {
|
|
const cmd = existsSync(venvPython)
|
|
? [venvPython, '-m', 'pytest', '-q', '-rf', join(pythonDir, 'tests')]
|
|
: ['uv', 'run', '--directory', pythonDir, '--offline', '--extra', 'dev', 'pytest', '-q', '-rf'];
|
|
|
|
const spawned = Bun.spawnSync(cmd, {
|
|
cwd: pythonDir,
|
|
env: buildEnv(),
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
});
|
|
|
|
const stdout = new TextDecoder().decode(spawned.stdout);
|
|
const stderr = new TextDecoder().decode(spawned.stderr);
|
|
|
|
expect(spawned.exitCode, `${stdout}\n${stderr}`).toBe(0);
|
|
},
|
|
60_000
|
|
);
|