forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyodide.test.ts
47 lines (44 loc) · 1.51 KB
/
pyodide.test.ts
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
47
import { describe, it, vi, expect } from 'vitest';
import PyodideNodeV0, { pyodide_node_data } from '$lib/compute/pyodide_v0';
import deepCopy from 'deep-copy';
import _ from 'lodash';
describe('PyodideNodeV0 tests', () => {
it('should execute python script and return outputData', async () => {
const node = new PyodideNodeV0(deepCopy(pyodide_node_data));
node.data.text = 'outputData = 123';
const output = await node.compute({}, 'run', vi.fn(), vi.fn(), vi.fn(), 'test_slug', vi.fn());
expect(output).toEqual(123);
}, 10000);
it('should be able to pass input to outputData', async () => {
const node = new PyodideNodeV0(deepCopy(pyodide_node_data));
node.data.text = 'outputData = inputData["input_0"]';
node.data.input_ids['input_0'] = 'some_node';
const output = await node.compute(
{ some_node: 123 },
'run',
vi.fn(),
vi.fn(),
vi.fn(),
'test_slug',
vi.fn()
);
expect(output).toEqual(123);
}, 10000);
it('test passing in complex data from jsonapi', async () => {
const data = await fetch('https://dummyjson.com/products');
const json = await data.json();
const node = new PyodideNodeV0(deepCopy(pyodide_node_data));
node.data.text = 'outputData = inputData["input_0"]';
node.data.input_ids['input_0'] = 'some_node';
const output = await node.compute(
{ some_node: json },
'run',
vi.fn(),
vi.fn(),
vi.fn(),
'test_slug',
vi.fn()
);
expect(output).toEqual(json);
}, 10000);
});