feat: workflow mock test

This commit is contained in:
Yeuoly
2024-03-10 18:41:01 +08:00
parent 4b37d30c0d
commit b5cb38641a
6 changed files with 311 additions and 6 deletions

View File

@ -0,0 +1,27 @@
import os
import pytest
from typing import Literal
from _pytest.monkeypatch import MonkeyPatch
from core.helper.code_executor.code_executor import CodeExecutor
MOCK = os.getenv('MOCK_SWITCH', 'false') == 'true'
class MockedCodeExecutor:
@classmethod
def invoke(cls, language: Literal['python3', 'javascript', 'jina2'], code: str, inputs: dict) -> dict:
# invoke directly
if language == 'python3':
return {
"result": 3
}
@pytest.fixture
def setup_code_executor_mock(request, monkeypatch: MonkeyPatch):
if not MOCK:
yield
return
monkeypatch.setattr(CodeExecutor, "execute_code", MockedCodeExecutor.invoke)
yield
monkeypatch.undo()