Skip to content

Commit f315f3a

Browse files
committed
feat: add new tests
1 parent 909a0c9 commit f315f3a

17 files changed

Lines changed: 3408 additions & 3520 deletions

examples/markdownify/markdownify_scrapegraphai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def main():
1111
# Load environment variables
1212
load_dotenv()
13-
13+
1414
# Set up logging
1515
sgai_logger.set_logging(level="INFO")
1616

examples/search_graph/scrapegraphai/searchscraper_scrapegraphai.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
def format_response(response: Dict[str, Any]) -> None:
1313
"""
1414
Format and print the search response in a readable way.
15-
15+
1616
Args:
1717
response (Dict[str, Any]): The response from the search API
1818
"""
1919
print("\n" + "="*50)
2020
print("SEARCH RESULTS")
2121
print("="*50)
22-
22+
2323
# Print request ID
2424
print(f"\nRequest ID: {response['request_id']}")
25-
25+
2626
# Print number of sources
2727
urls = response.get('reference_urls', [])
2828
print(f"\nSources Processed: {len(urls)}")
29-
29+
3030
# Print the extracted information
3131
print("\nExtracted Information:")
3232
print("-"*30)
@@ -40,7 +40,7 @@ def format_response(response: Dict[str, Any]) -> None:
4040
print(f" {value}")
4141
else:
4242
print(response['result'])
43-
43+
4444
# Print source URLs
4545
if urls:
4646
print("\nSources:")
@@ -52,7 +52,7 @@ def format_response(response: Dict[str, Any]) -> None:
5252
def main():
5353
# Load environment variables
5454
load_dotenv()
55-
55+
5656
# Get API key
5757
api_key = os.getenv("SCRAPEGRAPH_API_KEY")
5858
if not api_key:
@@ -67,7 +67,7 @@ def main():
6767
try:
6868
# Basic search scraper example
6969
print("\nSearching for information...")
70-
70+
7171
search_response = sgai_client.searchscraper(
7272
user_prompt="Extract webpage information"
7373
)

examples/smart_scraper_graph/scrapegraphai/smartscraper_scrapegraphai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def main():
1111
# Load environment variables from .env file
1212
load_dotenv()
13-
13+
1414
# Get API key from environment variables
1515
api_key = os.getenv("SCRAPEGRAPH_API_KEY")
1616
if not api_key:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414
"langchain-classic>=1.0.0",
1515
"langchain-openai>=1.1.6",
1616
"langchain-mistralai>=1.1.1",
17-
"langchain_community>=0.3.31",
17+
"langchain_community>=0.4.0",
1818
"langchain-aws>=1.1.0",
1919
"langchain-ollama>=1.0.1",
2020
"html2text>=2025.4.15",

scrapegraphai/telemetry/telemetry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,4 @@ def wrapped_fn(*args, **kwargs):
177177
finally:
178178
if is_telemetry_enabled():
179179
log_event("function_usage", {"function_name": call_fn.__name__})
180-
return wrapped_fn
180+
return wrapped_fn

tests/fixtures/benchmarking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def generate_report(self) -> str:
133133
return "No benchmark results available."
134134

135135
# Get unique test names
136-
test_names = list(set(r.test_name for r in self.results))
136+
test_names = list({r.test_name for r in self.results})
137137

138138
report = ["=" * 80, "Performance Benchmark Report", "=" * 80, ""]
139139

tests/fixtures/mock_server/server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import json
1313
import time
1414
from http.server import BaseHTTPRequestHandler, HTTPServer
15-
from pathlib import Path
1615
from threading import Thread
1716
from typing import Dict, Optional
1817
from urllib.parse import parse_qs, urlparse

tests/graphs/abstract_graph_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_burr_kwargs():
4141
"llm": {"model": "openai/gpt-3.5-turbo", "openai_api_key": "sk-test"},
4242
"burr_kwargs": {"some_key": "some_value"},
4343
}
44-
graph = TestGraph("Test prompt", config)
44+
TestGraph("Test prompt", config)
4545
# Check that the burr_kwargs have been applied and an app_instance_id added if missing
4646
assert dummy_graph.use_burr is True
4747
assert dummy_graph.burr_config["some_key"] == "some_value"
@@ -59,14 +59,14 @@ def test_set_common_params():
5959
mock_node2 = Mock()
6060
mock_graph.nodes = [mock_node1, mock_node2]
6161
# Create a TestGraph instance with the mock graph
62-
with patch(
63-
"scrapegraphai.graphs.abstract_graph.AbstractGraph._create_graph",
64-
return_value=mock_graph,
65-
):
62+
with patch.object(TestGraph, "_create_graph", return_value=mock_graph):
6663
graph = TestGraph(
6764
"Test prompt",
6865
{"llm": {"model": "openai/gpt-3.5-turbo", "openai_api_key": "sk-test"}},
6966
)
67+
# Reset mock call counts before testing set_common_params
68+
mock_node1.update_config.reset_mock()
69+
mock_node2.update_config.reset_mock()
7070
# Call set_common_params with test parameters
7171
test_params = {"param1": "value1", "param2": "value2"}
7272
graph.set_common_params(test_params)

tests/graphs/scrape_graph_test.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/graphs/xml_scraper_openai_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dotenv import load_dotenv
99

1010
from scrapegraphai.graphs import XMLScraperGraph
11-
from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info
11+
from scrapegraphai.utils import export_to_csv, export_to_json, prettify_exec_info
1212

1313
load_dotenv()
1414

@@ -96,8 +96,8 @@ def test_xml_scraper_save_results(graph_config: dict, xml_content: str):
9696
result = xml_scraper_graph.run()
9797

9898
# Save to csv and json
99-
convert_to_csv(result, "result")
100-
convert_to_json(result, "result")
99+
export_to_csv(result, "result.csv")
100+
export_to_json(result, "result.json")
101101

102102
assert os.path.exists("result.csv")
103103
assert os.path.exists("result.json")

0 commit comments

Comments
 (0)