T-213: M2.4b — Add Python stockbot register_signal, batch feature runner, and M2 MarketDataStore methods
This commit is contained in:
parent
d95b0ce9d3
commit
68a53bd489
2 changed files with 46 additions and 0 deletions
44
scripts/test/python-stockbot-sdk.test.ts
Normal file
44
scripts/test/python-stockbot-sdk.test.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue