From 16c688f090559497175677010bbb285c9d53cf22 Mon Sep 17 00:00:00 2001 From: "codebeaver-ai[bot]" <192081515+codebeaver-ai[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:02:17 +0000 Subject: [PATCH] test: Update coverage improvement test for tests/test_search_graph.py --- tests/test_search_graph.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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