gperdrizet commited on
Commit
503c07a
·
verified ·
1 Parent(s): 1ade001

Added unittest for google_search() function.

Browse files
Files changed (1) hide show
  1. tests/test_tools.py +42 -0
tests/test_tools.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''Unittests for agent tools.'''
2
+
3
+ import unittest
4
+ import googlesearch
5
+ from functions.tools import google_search
6
+
7
+
8
+ class TestGoogleSearch(unittest.TestCase):
9
+ '''Tests for the google search tool.'''
10
+
11
+
12
+ def setUp(self):
13
+
14
+ google_search_query = 'Python programming language'
15
+ self.search_results = google_search(google_search_query)
16
+
17
+
18
+ def test_result_type(self):
19
+ '''Search results should be a dictionary.'''
20
+
21
+ self.assertIsInstance(self.search_results, dict)
22
+
23
+
24
+ def test_result_length(self):
25
+ '''Search results should contain 5 items.'''
26
+
27
+ self.assertEqual(len(self.search_results), 5)
28
+
29
+
30
+ def test_result_content(self):
31
+ '''Each search result should contain three elements: title, link, and snippet.'''
32
+
33
+ print(type(self.search_results[1]))
34
+
35
+ for _, result in self.search_results.items():
36
+ self.assertIsInstance(result, dict)
37
+ self.assertIn('title', result)
38
+ self.assertIn('url', result)
39
+ self.assertIn('description', result)
40
+ self.assertIsInstance(result['title'], str)
41
+ self.assertIsInstance(result['url'], str)
42
+ self.assertIsInstance(result['description'], str)