forked from Chainlit/chainlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,172 additions
and
689 deletions.
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
2 changes: 1 addition & 1 deletion
2
.github/workflows/tests.yaml → .github/workflows/e2e-tests.yaml
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Tests | ||
name: E2ETests | ||
|
||
on: [workflow_call] | ||
|
||
|
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,23 @@ | ||
name: Pytest | ||
|
||
on: [workflow_call] | ||
|
||
jobs: | ||
mypy: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./backend | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
cache: 'pip' | ||
- name: Install Poetry | ||
run: pip install poetry | ||
- name: Install dependencies | ||
run: poetry install --with tests --with mypy --with custom-data | ||
- name: Run Pytest | ||
run: poetry run pytest --cov=chainlit/ |
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 |
---|---|---|
|
@@ -55,3 +55,6 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.aider* | ||
.coverage |
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 @@ | ||
|
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,80 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from chainlit.context import ( | ||
ChainlitContext, | ||
ChainlitContextException, | ||
get_context, | ||
init_http_context, | ||
init_ws_context, | ||
) | ||
from chainlit.emitter import BaseChainlitEmitter, ChainlitEmitter | ||
from chainlit.session import HTTPSession, WebsocketSession | ||
|
||
|
||
@pytest.fixture | ||
def mock_websocket_session(): | ||
return Mock(spec=WebsocketSession) | ||
|
||
|
||
@pytest.fixture | ||
def mock_http_session(): | ||
return Mock(spec=HTTPSession) | ||
|
||
|
||
@pytest.fixture | ||
def mock_emitter(): | ||
return Mock(spec=BaseChainlitEmitter) | ||
|
||
|
||
async def test_chainlit_context_init_with_websocket( | ||
mock_websocket_session, mock_emitter | ||
): | ||
context = ChainlitContext(mock_websocket_session, mock_emitter) | ||
assert isinstance(context.emitter, BaseChainlitEmitter) | ||
assert context.session == mock_websocket_session | ||
assert context.active_steps == [] | ||
|
||
|
||
async def test_chainlit_context_init_with_http(mock_http_session): | ||
context = ChainlitContext(mock_http_session) | ||
assert isinstance(context.emitter, BaseChainlitEmitter) | ||
assert context.session == mock_http_session | ||
assert context.active_steps == [] | ||
|
||
|
||
async def test_init_ws_context(mock_websocket_session): | ||
context = init_ws_context(mock_websocket_session) | ||
assert isinstance(context, ChainlitContext) | ||
assert context.session == mock_websocket_session | ||
assert isinstance(context.emitter, ChainlitEmitter) | ||
|
||
|
||
async def test_init_http_context(): | ||
context = init_http_context() | ||
assert isinstance(context, ChainlitContext) | ||
assert isinstance(context.session, HTTPSession) | ||
assert isinstance(context.emitter, BaseChainlitEmitter) | ||
|
||
|
||
async def test_get_context(): | ||
with pytest.raises(ChainlitContextException): | ||
get_context() | ||
|
||
init_http_context() # Initialize a context | ||
context = get_context() | ||
assert isinstance(context, ChainlitContext) | ||
|
||
|
||
async def test_current_step_and_run(): | ||
context = init_http_context() | ||
assert context.current_step is None | ||
assert context.current_run is None | ||
|
||
# Mock a step | ||
mock_step = Mock() | ||
mock_step.name = "on_chat_start" | ||
context.active_steps.append(mock_step) | ||
|
||
assert context.current_step == mock_step | ||
assert context.current_run == mock_step |
Oops, something went wrong.