Spaces:
Sleeping
Sleeping
import pytest | |
from unittest.mock import Mock, patch | |
import json | |
from io import StringIO | |
from pydantic import ValidationError | |
from app.pipeline import Pipeline | |
from app.models import PydanticEncoder, Message, Card, parse_message | |
# Tests for Pipeline class | |
def mock_pipeline(): | |
with patch('app.pipeline') as mock_pipe: | |
mock_pipe.return_value = Mock() | |
yield Pipeline("mock_model") | |
# Test for PydanticEncoder | |
def test_pydantic_encoder(): | |
card = Card(question="Q", answer="A") | |
encoded = json.dumps(card, cls=PydanticEncoder) | |
assert json.loads(encoded) == {"question": "Q", "answer": "A"} | |
# Test error cases | |
def test_message_invalid_content(): | |
with pytest.raises(ValidationError): | |
Message(role="assistant", content="Invalid content") | |