-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for MemoryCondenser in test_condenser.py (#3379)
* Add unit tests for MemoryCondenser in test_condenser.py * Formatting * Fix formatting etc --------- Co-authored-by: opendevin <[email protected]>
- Loading branch information
1 parent
e33b356
commit 92b19ed
Showing
1 changed file
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
|
||
from opendevin.core.exceptions import LLMResponseError | ||
from opendevin.llm.llm import LLM | ||
from opendevin.memory.condenser import MemoryCondenser | ||
|
||
|
||
@pytest.fixture | ||
def memory_condenser(): | ||
return MemoryCondenser() | ||
|
||
|
||
@pytest.fixture | ||
def mock_llm(): | ||
return Mock(spec=LLM) | ||
|
||
|
||
def test_condense_success(memory_condenser, mock_llm): | ||
mock_llm.completion.return_value = { | ||
'choices': [{'message': {'content': 'Condensed memory'}}] | ||
} | ||
result = memory_condenser.condense('Summarize this', mock_llm) | ||
assert result == 'Condensed memory' | ||
mock_llm.completion.assert_called_once_with( | ||
messages=[{'content': 'Summarize this', 'role': 'user'}] | ||
) | ||
|
||
|
||
def test_condense_exception(memory_condenser, mock_llm): | ||
mock_llm.completion.side_effect = LLMResponseError('LLM error') | ||
with pytest.raises(LLMResponseError, match='LLM error'): | ||
memory_condenser.condense('Summarize this', mock_llm) | ||
|
||
|
||
@patch('opendevin.memory.condenser.logger') | ||
def test_condense_logs_error(mock_logger, memory_condenser, mock_llm): | ||
mock_llm.completion.side_effect = LLMResponseError('LLM error') | ||
with pytest.raises(LLMResponseError): | ||
memory_condenser.condense('Summarize this', mock_llm) | ||
mock_logger.error.assert_called_once_with( | ||
'Error condensing thoughts: %s', 'LLM error', exc_info=False | ||
) |