|
| 1 | +"""Comprehensive tests for sync Scorer class.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from types import SimpleNamespace |
| 6 | +from unittest.mock import Mock |
| 7 | + |
| 8 | +from tests.sdk.conftest import MockScorerView |
| 9 | +from runloop_api_client.sdk import Scorer |
| 10 | + |
| 11 | + |
| 12 | +class TestScorer: |
| 13 | + """Tests for Scorer class.""" |
| 14 | + |
| 15 | + def test_init(self, mock_client: Mock) -> None: |
| 16 | + """Test Scorer initialization.""" |
| 17 | + scorer = Scorer(mock_client, "scorer_123") |
| 18 | + assert scorer.id == "scorer_123" |
| 19 | + |
| 20 | + def test_repr(self, mock_client: Mock) -> None: |
| 21 | + """Test Scorer string representation.""" |
| 22 | + scorer = Scorer(mock_client, "scorer_123") |
| 23 | + assert repr(scorer) == "<Scorer id='scorer_123'>" |
| 24 | + |
| 25 | + def test_id_property(self, mock_client: Mock) -> None: |
| 26 | + """Test id property returns the scorer ID.""" |
| 27 | + scorer = Scorer(mock_client, "scorer_123") |
| 28 | + assert scorer.id == "scorer_123" |
| 29 | + |
| 30 | + def test_get_info(self, mock_client: Mock, scorer_view: MockScorerView) -> None: |
| 31 | + """Test get_info method.""" |
| 32 | + mock_client.scenarios.scorers.retrieve.return_value = scorer_view |
| 33 | + |
| 34 | + scorer = Scorer(mock_client, "scorer_123") |
| 35 | + result = scorer.get_info( |
| 36 | + extra_headers={"X-Custom": "value"}, |
| 37 | + extra_query={"param": "value"}, |
| 38 | + extra_body={"key": "value"}, |
| 39 | + timeout=30.0, |
| 40 | + ) |
| 41 | + |
| 42 | + assert result == scorer_view |
| 43 | + mock_client.scenarios.scorers.retrieve.assert_called_once_with( |
| 44 | + "scorer_123", |
| 45 | + extra_headers={"X-Custom": "value"}, |
| 46 | + extra_query={"param": "value"}, |
| 47 | + extra_body={"key": "value"}, |
| 48 | + timeout=30.0, |
| 49 | + ) |
| 50 | + |
| 51 | + def test_update(self, mock_client: Mock) -> None: |
| 52 | + """Test update method.""" |
| 53 | + update_response = SimpleNamespace(id="scorer_123", name="updated-scorer") |
| 54 | + mock_client.scenarios.scorers.update.return_value = update_response |
| 55 | + |
| 56 | + scorer = Scorer(mock_client, "scorer_123") |
| 57 | + result = scorer.update( |
| 58 | + name="updated-scorer", |
| 59 | + extra_headers={"X-Custom": "value"}, |
| 60 | + extra_query={"param": "value"}, |
| 61 | + extra_body={"key": "value"}, |
| 62 | + timeout=30.0, |
| 63 | + ) |
| 64 | + |
| 65 | + assert result == update_response |
| 66 | + mock_client.scenarios.scorers.update.assert_called_once_with( |
| 67 | + "scorer_123", |
| 68 | + name="updated-scorer", |
| 69 | + extra_headers={"X-Custom": "value"}, |
| 70 | + extra_query={"param": "value"}, |
| 71 | + extra_body={"key": "value"}, |
| 72 | + timeout=30.0, |
| 73 | + ) |
| 74 | + |
| 75 | + def test_validate(self, mock_client: Mock) -> None: |
| 76 | + """Test validate method.""" |
| 77 | + validate_response = SimpleNamespace( |
| 78 | + is_valid=True, |
| 79 | + score=0.95, |
| 80 | + reasoning="The output matches expected criteria.", |
| 81 | + ) |
| 82 | + mock_client.scenarios.scorers.validate.return_value = validate_response |
| 83 | + |
| 84 | + scorer = Scorer(mock_client, "scorer_123") |
| 85 | + result = scorer.validate( |
| 86 | + bash_command_output="test output", |
| 87 | + expected_output="test output", |
| 88 | + extra_headers={"X-Custom": "value"}, |
| 89 | + extra_query={"param": "value"}, |
| 90 | + extra_body={"key": "value"}, |
| 91 | + timeout=30.0, |
| 92 | + ) |
| 93 | + |
| 94 | + assert result == validate_response |
| 95 | + assert result.is_valid is True |
| 96 | + assert result.score == 0.95 |
| 97 | + mock_client.scenarios.scorers.validate.assert_called_once_with( |
| 98 | + "scorer_123", |
| 99 | + bash_command_output="test output", |
| 100 | + expected_output="test output", |
| 101 | + extra_headers={"X-Custom": "value"}, |
| 102 | + extra_query={"param": "value"}, |
| 103 | + extra_body={"key": "value"}, |
| 104 | + timeout=30.0, |
| 105 | + ) |
0 commit comments