forked from e2b-dev/code-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreaming.test.ts
More file actions
46 lines (35 loc) · 1.04 KB
/
streaming.test.ts
File metadata and controls
46 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { expect } from 'vitest'
import { Result, OutputMessage } from '../src'
import { sandboxTest } from './setup'
sandboxTest('streaming output', async ({ sandbox }) => {
const out: OutputMessage[] = []
await sandbox.runCode('print(1)', {
onStdout: (msg) => out.push(msg),
})
expect(out.length).toEqual(1)
expect(out[0].line).toEqual('1\n')
})
sandboxTest('streaming error', async ({ sandbox }) => {
const out: OutputMessage[] = []
await sandbox.runCode('import sys;print(1, file=sys.stderr)', {
onStderr: (msg) => out.push(msg),
})
expect(out.length).toEqual(1)
expect(out[0].line).toEqual('1\n')
})
sandboxTest('streaming result', async ({ sandbox }) => {
const out: Result[] = []
const code = `
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 20, 100)
y = np.sin(x)
plt.plot(x, y)
plt.show()
x
`
await sandbox.runCode(code, {
onResult: (result) => out.push(result),
})
expect(out.length).toEqual(2)
})