mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
fix: tests
This commit is contained in:
@@ -22,7 +22,7 @@ class TestAnthropicLLM(unittest.TestCase):
|
|||||||
mock_response = Mock()
|
mock_response = Mock()
|
||||||
mock_response.completion = "test completion"
|
mock_response.completion = "test completion"
|
||||||
|
|
||||||
with patch("application.cache.make_redis") as mock_make_redis:
|
with patch("application.cache.get_redis_instance") as mock_make_redis:
|
||||||
mock_redis_instance = mock_make_redis.return_value
|
mock_redis_instance = mock_make_redis.return_value
|
||||||
mock_redis_instance.get.return_value = None
|
mock_redis_instance.get.return_value = None
|
||||||
mock_redis_instance.set = Mock()
|
mock_redis_instance.set = Mock()
|
||||||
@@ -47,7 +47,7 @@ class TestAnthropicLLM(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
mock_responses = [Mock(completion="response_1"), Mock(completion="response_2")]
|
mock_responses = [Mock(completion="response_1"), Mock(completion="response_2")]
|
||||||
|
|
||||||
with patch("application.cache.make_redis") as mock_make_redis:
|
with patch("application.cache.get_redis_instance") as mock_make_redis:
|
||||||
mock_redis_instance = mock_make_redis.return_value
|
mock_redis_instance = mock_make_redis.return_value
|
||||||
mock_redis_instance.get.return_value = None
|
mock_redis_instance.get.return_value = None
|
||||||
mock_redis_instance.set = Mock()
|
mock_redis_instance.set = Mock()
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class TestSagemakerAPILLM(unittest.TestCase):
|
|||||||
self.response['Body'].read.return_value.decode.return_value = json.dumps(self.result)
|
self.response['Body'].read.return_value.decode.return_value = json.dumps(self.result)
|
||||||
|
|
||||||
def test_gen(self):
|
def test_gen(self):
|
||||||
with patch('application.cache.make_redis') as mock_make_redis:
|
with patch('application.cache.get_redis_instance') as mock_make_redis:
|
||||||
mock_redis_instance = mock_make_redis.return_value
|
mock_redis_instance = mock_make_redis.return_value
|
||||||
mock_redis_instance.get.return_value = None
|
mock_redis_instance.get.return_value = None
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class TestSagemakerAPILLM(unittest.TestCase):
|
|||||||
mock_redis_instance.set.assert_called_once()
|
mock_redis_instance.set.assert_called_once()
|
||||||
|
|
||||||
def test_gen_stream(self):
|
def test_gen_stream(self):
|
||||||
with patch('application.cache.make_redis') as mock_make_redis:
|
with patch('application.cache.get_redis_instance') as mock_make_redis:
|
||||||
mock_redis_instance = mock_make_redis.return_value
|
mock_redis_instance = mock_make_redis.return_value
|
||||||
mock_redis_instance.get.return_value = None
|
mock_redis_instance.get.return_value = None
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ def test_gen_cache_key_invalid_message_format():
|
|||||||
assert str(context.exception) == "All messages must be dictionaries."
|
assert str(context.exception) == "All messages must be dictionaries."
|
||||||
|
|
||||||
# Test for gen_cache decorator
|
# Test for gen_cache decorator
|
||||||
@patch('application.cache.make_redis') # Mock the Redis client
|
@patch('application.cache.get_redis_instance') # Mock the Redis client
|
||||||
def test_gen_cache_hit(mock_make_redis):
|
def test_gen_cache_hit(mock_make_redis):
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_redis_instance = MagicMock()
|
mock_redis_instance = MagicMock()
|
||||||
@@ -50,7 +50,7 @@ def test_gen_cache_hit(mock_make_redis):
|
|||||||
mock_redis_instance.set.assert_not_called() # Ensure the function result is not cached again
|
mock_redis_instance.set.assert_not_called() # Ensure the function result is not cached again
|
||||||
|
|
||||||
|
|
||||||
@patch('application.cache.make_redis') # Mock the Redis client
|
@patch('application.cache.get_redis_instance') # Mock the Redis client
|
||||||
def test_gen_cache_miss(mock_make_redis):
|
def test_gen_cache_miss(mock_make_redis):
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_redis_instance = MagicMock()
|
mock_redis_instance = MagicMock()
|
||||||
@@ -73,7 +73,7 @@ def test_gen_cache_miss(mock_make_redis):
|
|||||||
assert result == "new_result"
|
assert result == "new_result"
|
||||||
mock_redis_instance.get.assert_called_once()
|
mock_redis_instance.get.assert_called_once()
|
||||||
|
|
||||||
@patch('application.cache.make_redis')
|
@patch('application.cache.get_redis_instance')
|
||||||
def test_stream_cache_hit(mock_make_redis):
|
def test_stream_cache_hit(mock_make_redis):
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_redis_instance = MagicMock()
|
mock_redis_instance = MagicMock()
|
||||||
@@ -98,7 +98,7 @@ def test_stream_cache_hit(mock_make_redis):
|
|||||||
mock_redis_instance.set.assert_not_called()
|
mock_redis_instance.set.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@patch('application.cache.make_redis')
|
@patch('application.cache.get_redis_instance')
|
||||||
def test_stream_cache_miss(mock_make_redis):
|
def test_stream_cache_miss(mock_make_redis):
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_redis_instance = MagicMock()
|
mock_redis_instance = MagicMock()
|
||||||
|
|||||||
Reference in New Issue
Block a user