mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-12 21:01:56 +08:00
feat: Add tests for SmartScraperGraph using sample text and configuration fixtures (@tejhande)
- Added pytest fixture to provide sample text from a file. - Added pytest fixture to provide graph configuration. - Implemented test_scraping_pipeline to test the execution of SmartScraperGraph. - Added assertions to verify the result is not None and to check the expected structure of the result. Contributed by @tejhande
This commit is contained in:
parent
08f1be682b
commit
c286b1649e
@ -5,11 +5,10 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
from scrapegraphai.graphs import SmartScraperGraph
|
from scrapegraphai.graphs import SmartScraperGraph
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sample_text():
|
def sample_text():
|
||||||
"""
|
"""
|
||||||
Example of text
|
Example of text fixture.
|
||||||
"""
|
"""
|
||||||
file_name = "inputs/plain_html_example.txt"
|
file_name = "inputs/plain_html_example.txt"
|
||||||
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
@ -20,11 +19,10 @@ def sample_text():
|
|||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def graph_config():
|
def graph_config():
|
||||||
"""
|
"""
|
||||||
Configuration of the graph
|
Configuration of the graph fixture.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"llm": {
|
"llm": {
|
||||||
@ -40,10 +38,9 @@ def graph_config():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def test_scraping_pipeline(sample_text, graph_config):
|
||||||
def test_scraping_pipeline(sample_text: str, graph_config: dict):
|
|
||||||
"""
|
"""
|
||||||
Start of the scraping pipeline
|
Test the SmartScraperGraph scraping pipeline.
|
||||||
"""
|
"""
|
||||||
smart_scraper_graph = SmartScraperGraph(
|
smart_scraper_graph = SmartScraperGraph(
|
||||||
prompt="List me all the news with their description.",
|
prompt="List me all the news with their description.",
|
||||||
@ -54,3 +51,6 @@ def test_scraping_pipeline(sample_text: str, graph_config: dict):
|
|||||||
result = smart_scraper_graph.run()
|
result = smart_scraper_graph.run()
|
||||||
|
|
||||||
assert result is not None
|
assert result is not None
|
||||||
|
# Additional assertions to check the structure of the result can be added here
|
||||||
|
assert isinstance(result, dict) # Assuming the result is a dictionary
|
||||||
|
assert "news" in result # Assuming the result should contain a key "news"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user