Skip to content

Commit 5f20299

Browse files
committed
add tests
1 parent ac692d3 commit 5f20299

File tree

4 files changed

+112
-107
lines changed

4 files changed

+112
-107
lines changed

tests/graphs/custom_graph_test.py

-58
This file was deleted.

tests/graphs/results.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"imageUrl": "https://picsum.photos/200/300?random=1",
4+
"name": "T-shirt with Owl Print",
5+
"description": "Comfortable cotton t-shirt featuring an owl print.",
6+
"price": "€20.00"
7+
},
8+
{
9+
"imageUrl": "https://picsum.photos/200/300?random=2",
10+
"name": "Classic Leather Wallet",
11+
"description": "Genuine leather wallet with multiple compartments.",
12+
"price": "€35.00"
13+
},
14+
{
15+
"imageUrl": "https://picsum.photos/200/300?random=3",
16+
"name": "Canvas Backpack",
17+
"description": "Spacious canvas backpack perfect for daily use.",
18+
"price": "€45.00"
19+
},
20+
{
21+
"imageUrl": "https://picsum.photos/200/300?random=4",
22+
"name": "Stainless Steel Water Bottle",
23+
"description": "Durable stainless steel water bottle, eco-friendly.",
24+
"price": "€15.00"
25+
},
26+
{
27+
"imageUrl": "https://picsum.photos/200/300?random=5",
28+
"name": "Wooden Desk Organizer",
29+
"description": "Handcrafted wooden desk organizer with compartments.",
30+
"price": "€25.00"
31+
},
32+
{
33+
"imageUrl": "https://picsum.photos/200/300?random=6",
34+
"name": "Ceramic Coffee Mug",
35+
"description": "Stylish ceramic coffee mug, microwave safe.",
36+
"price": "€10.00"
37+
},
38+
{
39+
"imageUrl": "https://picsum.photos/200/300?random=7",
40+
"name": "Smartphone Stand",
41+
"description": "Adjustable smartphone stand for hands-free viewing.",
42+
"price": "€8.00"
43+
},
44+
{
45+
"imageUrl": "https://picsum.photos/200/300?random=8",
46+
"name": "Soft Cotton Bath Towel",
47+
"description": "Luxuriously soft cotton bath towel for spa-like comfort.",
48+
"price": "€18.00"
49+
},
50+
{
51+
"imageUrl": "https://picsum.photos/200/300?random=9",
52+
"name": "Wireless Bluetooth Earphones",
53+
"description": "High-quality wireless Bluetooth earphones with noise cancellation.",
54+
"price": "€50.00"
55+
},
56+
{
57+
"imageUrl": "https://picsum.photos/200/300?random=10",
58+
"name": "Glass Fruit Bowl",
59+
"description": "Elegant glass fruit bowl to display fruits beautifully.",
60+
"price": "€30.00"
61+
}
62+
]

tests/graphs/smart_scraper_test.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
"""
2-
Module for testing the class SmartScraperGraph
3-
"""
4-
import unittest
51
import os
2+
import unittest
63
from dotenv import load_dotenv
74
from scrapegraphai.graphs import SmartScraperGraph
85

6+
load_dotenv()
97

10-
class TestSmartScraperGraph(unittest.TestCase):
11-
"""
12-
class for testing the class SmartScraperGraph
13-
"""
148

15-
@classmethod
16-
def setUpClass(cls):
17-
load_dotenv()
9+
class TestScrapingPipeline(unittest.TestCase):
10+
"""Test class for SmartScraperGraph"""
11+
12+
def setUp(self):
13+
# Define the configuration for the language model
1814
openai_key = os.getenv("OPENAI_APIKEY")
19-
cls.llm_config = {
15+
llm_config = {
2016
"api_key": openai_key,
2117
"model_name": "gpt-3.5-turbo",
2218
}
23-
cls.URL = "https://perinim.github.io/projects/"
24-
cls.PROMPT = "List me all the titles and project descriptions and give me an audio"
25-
cls.smart_scraper_graph = SmartScraperGraph(
26-
cls.PROMPT, cls.URL, cls.llm_config)
27-
28-
def test_scraper_execution(self):
29-
"""
30-
Execution of the test
31-
"""
32-
answer = self.smart_scraper_graph.run()
33-
self.assertIsNotNone(answer)
34-
self.assertNotEqual(answer, "")
19+
20+
# Define URL and PROMPT
21+
url = "https://perinim.github.io/projects/"
22+
prompt = "List me all the titles and project descriptions"
23+
24+
# Create the SmartScraperGraph instance
25+
self.smart_scraper_graph = SmartScraperGraph(prompt, url, llm_config)
26+
27+
def test_scraping(self):
28+
"""Main test method"""
29+
# Run the scraper
30+
result = self.smart_scraper_graph.run()
31+
print(result)
32+
33+
# Check if the result is not empty
34+
self.assertNotEqual(result, {})
3535

3636

3737
if __name__ == '__main__':

tests/graphs/speech_summary_test.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
"""
2-
Module for testing the class SpeechSummaryGraph
3-
"""
4-
import unittest
51
import os
2+
import unittest
63
from dotenv import load_dotenv
74
from scrapegraphai.graphs import SpeechSummaryGraph
85

6+
load_dotenv()
7+
98

109
class TestSpeechSummaryGraph(unittest.TestCase):
11-
"""
12-
class for testing the class SpeechSummaryGraph
13-
"""
10+
"""Test class for SpeechSummaryGraph"""
1411

1512
def setUp(self):
16-
load_dotenv()
13+
# Define the configuration for the language model
1714
openai_key = os.getenv("OPENAI_APIKEY")
18-
self.llm_config = {
15+
llm_config = {
1916
"api_key": openai_key,
2017
}
21-
self.curr_dir = os.path.dirname(os.path.realpath(__file__))
22-
self.output_file_path = os.path.join(
23-
self.curr_dir, "website_summary.mp3")
18+
19+
# Save the audio to a file
20+
curr_dir = os.path.dirname(os.path.realpath(__file__))
21+
output_file_path = os.path.join(curr_dir, "website_summary.mp3")
22+
23+
# Initialize SpeechSummaryGraph instance
24+
self.speech_summary_graph = SpeechSummaryGraph(
25+
"Make a summary of the news to be converted to audio for blind people.",
26+
"https://www.wired.com/category/science/",
27+
llm_config,
28+
output_file_path
29+
)
2430

2531
def test_summary_generation(self):
26-
"""
27-
Execution of the test
28-
"""
29-
speech_summary_graph = SpeechSummaryGraph("""Make a summary of the news to be
30-
converted to audio for
31-
blind people.""",
32-
"https://www.wired.com/category/science/",
33-
self.llm_config,
34-
self.output_file_path)
35-
final_state = speech_summary_graph.run()
36-
result = final_state.get("answer", "No answer found.")
37-
self.assertIsNotNone(result)
38-
self.assertNotEqual(result, "No answer found.")
32+
"""Test summary generation and audio conversion"""
33+
# Run the summary graph
34+
final_state = self.speech_summary_graph.run()
35+
print(final_state)
36+
37+
# Check if the final state contains non-empty 'answer' key
38+
self.assertTrue(final_state.get("answer")
39+
is not None and final_state["answer"] != "")
3940

4041

4142
if __name__ == '__main__':

0 commit comments

Comments
 (0)