Skip to content

Commit 16c688f

Browse files
test: Update coverage improvement test for tests/test_search_graph.py
1 parent 9919e7c commit 16c688f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_search_graph.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,28 @@ def test_get_considered_urls(self, mock_create_llm, mock_base_graph, urls):
3333
search_graph.run()
3434

3535
# Assert
36-
assert search_graph.get_considered_urls() == urls
36+
assert search_graph.get_considered_urls() == urls
37+
38+
@patch('scrapegraphai.graphs.search_graph.BaseGraph')
39+
@patch('scrapegraphai.graphs.abstract_graph.AbstractGraph._create_llm')
40+
def test_run_no_answer_found(self, mock_create_llm, mock_base_graph):
41+
"""
42+
Test that the run() method returns "No answer found." when the final state
43+
doesn't contain an "answer" key.
44+
"""
45+
# Arrange
46+
prompt = "Test prompt"
47+
config = {"llm": {"model": "test-model"}}
48+
49+
# Mock the _create_llm method to return a MagicMock
50+
mock_create_llm.return_value = MagicMock()
51+
52+
# Mock the execute method to set the final_state without an "answer" key
53+
mock_base_graph.return_value.execute.return_value = ({"urls": []}, {})
54+
55+
# Act
56+
search_graph = SearchGraph(prompt, config)
57+
result = search_graph.run()
58+
59+
# Assert
60+
assert result == "No answer found."

0 commit comments

Comments
 (0)