-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration tests on CodeExecutor with the sandbox service (#…
- Loading branch information
1 parent
b1399cd
commit 4485770
Showing
7 changed files
with
61 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,14 @@ jobs: | |
- name: Run Tool | ||
run: dev/pytest/pytest_tools.sh | ||
|
||
- name: Set up Sandbox | ||
uses: hoverkraft-tech/[email protected] | ||
with: | ||
compose-file: | | ||
docker/docker-compose.middleware.yaml | ||
services: | | ||
sandbox | ||
- name: Run Workflow | ||
run: dev/pytest/pytest_workflow.sh | ||
|
||
|
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
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions
18
api/tests/integration_tests/workflow/nodes/code_executor/test_code_javascript.py
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,18 @@ | ||
from core.helper.code_executor.code_executor import CodeExecutor | ||
|
||
CODE_LANGUAGE = 'javascript' | ||
|
||
|
||
def test_javascript_plain(): | ||
code = 'console.log("Hello World")' | ||
result_message = CodeExecutor.execute_code(language=CODE_LANGUAGE, preload='', code=code) | ||
assert result_message == 'Hello World\n' | ||
|
||
|
||
def test_javascript_json(): | ||
code = """ | ||
obj = {'Hello': 'World'} | ||
console.log(JSON.stringify(obj)) | ||
""" | ||
result = CodeExecutor.execute_code(language=CODE_LANGUAGE, preload='', code=code) | ||
assert result == '{"Hello":"World"}\n' |
14 changes: 14 additions & 0 deletions
14
api/tests/integration_tests/workflow/nodes/code_executor/test_code_jina2.py
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 @@ | ||
import base64 | ||
|
||
from core.helper.code_executor.code_executor import CodeExecutor | ||
from core.helper.code_executor.jinja2_transformer import JINJA2_PRELOAD, PYTHON_RUNNER | ||
|
||
CODE_LANGUAGE = 'jinja2' | ||
|
||
|
||
def test_jinja2(): | ||
template = 'Hello {{template}}' | ||
inputs = base64.b64encode(b'{"template": "World"}').decode('utf-8') | ||
code = PYTHON_RUNNER.replace('{{code}}', template).replace('{{inputs}}', inputs) | ||
result = CodeExecutor.execute_code(language=CODE_LANGUAGE, preload=JINJA2_PRELOAD, code=code) | ||
assert result == '<<RESULT>>Hello World<<RESULT>>\n' |
18 changes: 18 additions & 0 deletions
18
api/tests/integration_tests/workflow/nodes/code_executor/test_code_python3.py
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,18 @@ | ||
from core.helper.code_executor.code_executor import CodeExecutor | ||
|
||
CODE_LANGUAGE = 'python3' | ||
|
||
|
||
def test_python3_plain(): | ||
code = 'print("Hello World")' | ||
result = CodeExecutor.execute_code(language=CODE_LANGUAGE, preload='', code=code) | ||
assert result == 'Hello World\n' | ||
|
||
|
||
def test_python3_json(): | ||
code = """ | ||
import json | ||
print(json.dumps({'Hello': 'World'})) | ||
""" | ||
result = CodeExecutor.execute_code(language=CODE_LANGUAGE, preload='', code=code) | ||
assert result == '{"Hello": "World"}\n' |