Skip to content

Commit b300ca8

Browse files
test: Add coverage improvement test for tests/test_search_graph.py
1 parent d5c7c9c commit b300ca8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_search_graph.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
3+
from scrapegraphai.graphs.search_graph import SearchGraph
4+
from unittest.mock import MagicMock, patch
5+
6+
class TestSearchGraph:
7+
"""Test class for SearchGraph"""
8+
9+
@pytest.mark.parametrize("urls", [
10+
["https://example.com", "https://test.com"],
11+
[],
12+
["https://single-url.com"]
13+
])
14+
@patch('scrapegraphai.graphs.search_graph.BaseGraph')
15+
@patch('scrapegraphai.graphs.abstract_graph.AbstractGraph._create_llm')
16+
def test_get_considered_urls(self, mock_create_llm, mock_base_graph, urls):
17+
"""
18+
Test that get_considered_urls returns the correct list of URLs
19+
considered during the search process.
20+
"""
21+
# Arrange
22+
prompt = "Test prompt"
23+
config = {"llm": {"model": "test-model"}}
24+
25+
# Mock the _create_llm method to return a MagicMock
26+
mock_create_llm.return_value = MagicMock()
27+
28+
# Mock the execute method to set the final_state
29+
mock_base_graph.return_value.execute.return_value = ({"urls": urls}, {})
30+
31+
# Act
32+
search_graph = SearchGraph(prompt, config)
33+
search_graph.run()
34+
35+
# Assert
36+
assert search_graph.get_considered_urls() == urls

0 commit comments

Comments
 (0)