Spaces:
Sleeping
Sleeping
File size: 791 Bytes
4d17caa 8428312 82915e5 4d17caa 8428312 4d17caa 8428312 |
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 |
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
@pytest.fixture
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")
|