Skip to content

Python scraper based on AI

test: Update coverage improvement test for tests/test_search_graph.py

codebeaver-ai[bot]16c688f09055
diff --git a/tests/test_search_graph.py b/tests/test_search_graph.py
index 1384988d..f8e51c9c 100644
--- a/tests/test_search_graph.py
+++ b/tests/test_search_graph.py
@@ -33,4 +33,28 @@ class TestSearchGraph:
search_graph.run()
# Assert
- assert search_graph.get_considered_urls() == urls
\ No newline at end of file
+ assert search_graph.get_considered_urls() == urls
+
+ @patch('scrapegraphai.graphs.search_graph.BaseGraph')
+ @patch('scrapegraphai.graphs.abstract_graph.AbstractGraph._create_llm')
+ def test_run_no_answer_found(self, mock_create_llm, mock_base_graph):
+ """
+ Test that the run() method returns "No answer found." when the final state
+ doesn't contain an "answer" key.
+ """
+ # Arrange
+ prompt = "Test prompt"
+ config = {"llm": {"model": "test-model"}}
+
+ # Mock the _create_llm method to return a MagicMock
+ mock_create_llm.return_value = MagicMock()
+
+ # Mock the execute method to set the final_state without an "answer" key
+ mock_base_graph.return_value.execute.return_value = ({"urls": []}, {})
+
+ # Act
+ search_graph = SearchGraph(prompt, config)
+ result = search_graph.run()
+
+ # Assert
+ assert result == "No answer found."
\ No newline at end of file