-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete refactor - must fix broken tests.
- Loading branch information
1 parent
e1548bc
commit 407d4c3
Showing
4 changed files
with
68 additions
and
67 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
|
@@ -21,22 +21,22 @@ def mock_text_completion_with_error(*args, **kwargs): | |
|
||
# Test case for successful summary generation | ||
def test_get_image_summary_success(): | ||
with patch('lucidserver.actions.actions_main.text_completion', side_effect=mock_text_completion_summary): | ||
with patch('lucidserver.actions.main.text_completion', side_effect=mock_text_completion_summary): | ||
dream_entry = "A mysterious dream about a forest" | ||
result = get_image_summary(dream_entry) | ||
assert result == "Generated Summary", f"Expected 'Generated Summary', but got {result}" | ||
|
||
|
||
# Test case for summary generation with GPT-4 error | ||
def test_get_image_summary_gpt4_error(): | ||
with patch('lucidserver.actions.actions_main.text_completion', side_effect=mock_text_completion_with_error): | ||
with patch('lucidserver.actions.main.text_completion', side_effect=mock_text_completion_with_error): | ||
dream_entry = "A mysterious dream about a forest" | ||
result = get_image_summary(dream_entry) | ||
assert result == "Error: Unable to generate a summary.", f"Expected error message, but got {result}" | ||
|
||
# Test case for exception handling | ||
def test_get_image_summary_exception(): | ||
with patch('lucidserver.actions.actions_main.text_completion', side_effect=Exception("An unexpected exception")): | ||
with patch('lucidserver.actions.main.text_completion', side_effect=Exception("An unexpected exception")): | ||
dream_entry = "A mysterious dream about a forest" | ||
result = get_image_summary(dream_entry) | ||
assert result == "Error: Unable to generate a summary.", f"Expected error message, but got {result}" | ||
|
@@ -52,23 +52,23 @@ def mock_text_completion_with_error(*args, **kwargs): | |
|
||
# Test case for successful dream analysis generation | ||
def test_generate_dream_analysis_success(): | ||
with patch('lucidserver.actions.actions_main.text_completion', side_effect=mock_text_completion_analysis): | ||
with patch('lucidserver.actions.main.text_completion', side_effect=mock_text_completion_analysis): | ||
prompt = "A profound dream about a journey" | ||
system_content = "System Content" | ||
result = generate_dream_analysis(prompt, system_content) | ||
assert result == "Generated Analysis", f"Expected 'Generated Analysis', but got {result}" | ||
|
||
# Test case for dream analysis generation with GPT-4 error | ||
def test_generate_dream_analysis_gpt4_error(): | ||
with patch('lucidserver.actions.actions_main.text_completion', side_effect=mock_text_completion_with_error): | ||
with patch('lucidserver.actions.main.text_completion', side_effect=mock_text_completion_with_error): | ||
prompt = "A profound dream about a journey" | ||
system_content = "System Content" | ||
result = generate_dream_analysis(prompt, system_content) | ||
assert result == "Error: Unable to generate a response.", f"Expected error message, but got {result}" | ||
|
||
# Test case for exception handling in dream analysis generation | ||
def test_generate_dream_analysis_exception(): | ||
with patch('lucidserver.actions.actions_main.text_completion', side_effect=Exception("An unexpected exception")): | ||
with patch('lucidserver.actions.main.text_completion', side_effect=Exception("An unexpected exception")): | ||
prompt = "A profound dream about a journey" | ||
system_content = "System Content" | ||
result = generate_dream_analysis(prompt, system_content) | ||
|
@@ -83,7 +83,7 @@ def mock_requests_post(*args, **kwargs): | |
|
||
# Test case for successful dream image generation | ||
def test_generate_dream_image_success(): | ||
with patch('lucidserver.actions.actions_main.get_image_summary', return_value="Generated Summary"): | ||
with patch('lucidserver.actions.main.get_image_summary', return_value="Generated Summary"): | ||
with patch('requests.post', side_effect=mock_requests_post): | ||
dreams = [{"id": "1", "metadata": {"entry": "A mysterious dream about a forest"}}] | ||
dream_id = "1" | ||
|
@@ -99,7 +99,7 @@ def test_generate_dream_image_dream_not_found(): | |
|
||
# Test case for dream image generation with error in OpenAI API response | ||
def test_generate_dream_image_api_error(): | ||
with patch('lucidserver.actions.actions_main.get_image_summary', return_value="Generated Summary"): | ||
with patch('lucidserver.actions.main.get_image_summary', return_value="Generated Summary"): | ||
with patch('requests.post', return_value=Mock(json=lambda: {})): # No 'data' in response | ||
dreams = [{"id": "1", "metadata": {"entry": "A mysterious dream about a forest"}}] | ||
dream_id = "1" | ||
|
@@ -108,7 +108,7 @@ def test_generate_dream_image_api_error(): | |
|
||
# Test case for exception handling in dream image generation | ||
def test_generate_dream_image_exception(): | ||
with patch('lucidserver.actions.actions_main.get_image_summary', side_effect=Exception("An unexpected exception")): | ||
with patch('lucidserver.actions.main.get_image_summary', side_effect=Exception("An unexpected exception")): | ||
dreams = [{"id": "1", "metadata": {"entry": "A mysterious dream about a forest"}}] | ||
dream_id = "1" | ||
result = generate_dream_image(dreams, dream_id) | ||
|
@@ -124,31 +124,31 @@ def mock_chat_completion_with_error(*args, **kwargs): | |
|
||
# Test case for successful regular chat | ||
def test_regular_chat_success(): | ||
with patch('lucidserver.actions.actions_main.chat_completion', side_effect=mock_chat_completion): | ||
with patch('lucidserver.actions.main.chat_completion', side_effect=mock_chat_completion): | ||
message = "Tell me more about lucid dreaming techniques." | ||
user_email = "[email protected]" | ||
result = regular_chat(message, user_email) | ||
assert result == "Generated Chat Response", f"Expected 'Generated Chat Response', but got {result}" | ||
|
||
# Test case for regular chat without user message | ||
def test_regular_chat_default_message(): | ||
with patch('lucidserver.actions.actions_main.chat_completion', side_effect=mock_chat_completion): | ||
with patch('lucidserver.actions.main.chat_completion', side_effect=mock_chat_completion): | ||
message = "" | ||
user_email = "[email protected]" | ||
result = regular_chat(message, user_email) | ||
assert result == "Generated Chat Response", f"Expected 'Generated Chat Response', but got {result}" | ||
|
||
# Test case for regular chat with GPT-4 error | ||
def test_regular_chat_gpt4_error(): | ||
with patch('lucidserver.actions.actions_main.chat_completion', side_effect=mock_chat_completion_with_error): | ||
with patch('lucidserver.actions.main.chat_completion', side_effect=mock_chat_completion_with_error): | ||
message = "Tell me more about lucid dreaming techniques." | ||
user_email = "[email protected]" | ||
result = regular_chat(message, user_email) | ||
assert result == "Error: Unable to generate a response.", f"Expected error message, but got {result}" | ||
|
||
# Test case for exception handling in regular chat | ||
def test_regular_chat_exception(): | ||
with patch('lucidserver.actions.actions_main.chat_completion', side_effect=Exception("An unexpected exception")): | ||
with patch('lucidserver.actions.main.chat_completion', side_effect=Exception("An unexpected exception")): | ||
message = "Tell me more about lucid dreaming techniques." | ||
user_email = "[email protected]" | ||
result = regular_chat(message, user_email) | ||
|
@@ -173,15 +173,15 @@ def mock_count_tokens(*args, **kwargs): | |
|
||
# Test case for search_dreams function | ||
def test_search_dreams(): | ||
with patch('lucidserver.memories.memories_main.search_memory', side_effect=mock_search_memory): | ||
with patch('lucidserver.memories.main.search_memory', side_effect=mock_search_memory): | ||
keyword = "Dream" | ||
user_email = "[email protected]" | ||
result = search_dreams(keyword, user_email) | ||
assert len(result) == 1, f"Expected 1 result, but got {len(result)}" | ||
|
||
# Test case for call_function_by_name function | ||
def test_call_function_by_name(): | ||
with patch('lucidserver.actions.actions_main.function_completion', side_effect=mock_function_completion): | ||
with patch('lucidserver.actions.main.function_completion', side_effect=mock_function_completion): | ||
function_name = "discuss_emotions" | ||
prompt = "Discuss emotions in dreams" | ||
messages = [] | ||
|
@@ -190,9 +190,9 @@ def test_call_function_by_name(): | |
|
||
# Test case for search_chat_with_dreams function with search results | ||
def test_search_chat_with_dreams_with_results(): | ||
with patch('lucidserver.memories.memories_main.search_dreams', side_effect=mock_search_memory), \ | ||
patch('lucidserver.actions.actions_main.count_tokens', side_effect=mock_count_tokens), \ | ||
patch('lucidserver.actions.actions_main.call_function_by_name', side_effect=mock_function_completion): | ||
with patch('lucidserver.memories.main.search_dreams', side_effect=mock_search_memory), \ | ||
patch('lucidserver.actions.main.count_tokens', side_effect=mock_count_tokens), \ | ||
patch('lucidserver.actions.main.call_function_by_name', side_effect=mock_function_completion): | ||
function_name = "discuss_emotions" | ||
prompt = "Discuss emotions in dreams" | ||
user_email = "[email protected]" | ||
|
@@ -202,9 +202,9 @@ def test_search_chat_with_dreams_with_results(): | |
|
||
# Test case for search_chat_with_dreams function without search results | ||
def test_search_chat_with_dreams_without_results(): | ||
with patch('lucidserver.memories.memories_main.search_memory', side_effect=lambda *args, **kwargs: []), \ | ||
patch('lucidserver.actions.actions_main.count_tokens', side_effect=mock_count_tokens), \ | ||
patch('lucidserver.actions.actions_main.call_function_by_name', side_effect=mock_function_completion): | ||
with patch('lucidserver.memories.main.search_memory', side_effect=lambda *args, **kwargs: []), \ | ||
patch('lucidserver.actions.main.count_tokens', side_effect=mock_count_tokens), \ | ||
patch('lucidserver.actions.main.call_function_by_name', side_effect=mock_function_completion): | ||
function_name = "discuss_emotions" | ||
prompt = "Discuss emotions in dreams" | ||
user_email = "[email protected]" | ||
|
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
Oops, something went wrong.