import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from dotenv import load_dotenv import unittest from unittest.mock import patch, MagicMock from tools.searchTools_lg import wiki_search, mini_web_search, arvix_search class TestSearchToolsLG(unittest.TestCase): @patch("tools.searchTools_lg.WikipediaLoader") def test_wiki_search(self, mock_loader): mock_doc = MagicMock() mock_doc.metadata = {"source": "Wikipedia", "page": "1"} mock_doc.page_content = "Test Wikipedia content" mock_loader.return_value.load.return_value = [mock_doc] result = wiki_search("test query") self.assertIn("wiki_results", result) self.assertIn("Test Wikipedia content", result["wiki_results"]) @patch("tools.searchTools_lg.TavilySearch") def test_mini_web_search(self, mock_tavily): mock_doc = MagicMock() mock_doc.result = [ {'url': 'https://www.python.org/', 'title': 'Welcome to Python.org', 'content': '**Notice:** While JavaScript is not essential for this website, your interaction with the content will be limited. # Python 3: Fibonacci series up to n More about defining functions in Python\xa03 # Python 3: List comprehensions Lists (known as arrays in other languages) are one of the compound data types that Python understands. More about lists in Python\xa03 # Python 3: Simple arithmetic More about simple math functions in Python\xa03. >>> print("Hello, I\'m Python!") Hello, I\'m Python! Python Hi, Python. Experienced programmers in any other language can pick up Python very quickly, and beginners find the clean syntax and indentation structure easy to learn. Latest: Python 3.13.7 docs.python.org jobs.python.org * Python 3.14.0rc2 and 3.13.7 are go!', 'score': 0.98583, 'raw_content': None}, {'url': 'https://www.w3schools.com/python/python_intro.asp', 'title': 'Introduction to Python - W3Schools', 'content': 'PYTHON # Python Introduction ## What is Python? Python is a popular programming language. ### What can Python do? ## Why Python? * Python has syntax that allows developers to write programs with fewer lines than some other programming languages. * In this tutorial Python will be written in a text editor. ### Python Syntax compared to other programming languages ##### Top Tutorials HTML Tutorial CSS Tutorial How To Tutorial Python Tutorial W3.CSS Tutorial ##### Top References HTML Reference CSS Reference Python Reference W3.CSS Reference ##### Top Examples HTML Examples CSS Examples How To Examples Python Examples W3.CSS Examples CSS Certificate Python Certificate Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness ', 'score': 0.98365, 'raw_content': None}, {'url': 'https://en.wikipedia.org/wiki/Python_(programming_language)', 'title': 'Python (programming language) - Wikipedia', 'content': 'Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.', 'score': 0.97793, 'raw_content': None}] mock_tavily.return_value.invoke.return_value = [mock_doc] result = mini_web_search("test query") self.assertTrue(len(result) > 0) @patch("tools.searchTools_lg.ArxivLoader") def test_arvix_search(self, mock_arxiv): mock_doc = MagicMock() mock_doc.metadata = {'Published': '2024-04-05', 'Title': 'Egglog Python: A Pythonic Library for E-graphs', 'Authors': 'Saul Shanabrook', 'Summary': 'E-graphs have emerged as a versatile data structure with applications in\nsynthesis, optimization, and verification through techniques such as equality\nsaturation. This paper introduces Python bindings for the experimental egglog\nlibrary (previously called egg-smol), which aims to bring the benefits of\ne-graphs to the Python ecosystem. The bindings offer a high-level, Pythonic API\nproviding an accessible and familiar interface for Python users. By integrating\ne-graph techniques with Python, we hope to enable collaboration and innovation\nacross various domains in the scientific computing and machine learning\ncommunities. We discuss the advantages of using Python bindings for both Python\nand existing egg-smol users, as well as possible future directions for\ndevelopment.'} mock_doc.page_content = "'Egg-smol Python: A Pythonic Library for E-graphs\nSaul Shanabrook\ns.shanabrook@gmail.com\nAbstract\nE-graphs have emerged as a versatile data structure with ap-\nplications in synthesis, optimization, and verification through\ntechniques such as equality saturation." mock_arxiv.return_value.load.return_value = [mock_doc] result = arvix_search("Python programming") self.assertTrue(len(result) > 0) def test_wiki_search_integration(self): result = wiki_search("Python programming") self.assertIn("wiki_results", result) self.assertTrue(len(result["wiki_results"]) > 0) #print("Wiki search result:", result["wiki_results"][:200]) def test_mini_web_search_integration(self): result = mini_web_search("Python programming") self.assertIn("results", result) self.assertTrue(len(result["results"]) > 0) def test_arvix_search_integration(self): result = arvix_search("Python programming") self.assertTrue(len(result) > 0) if __name__ == "__main__": # load environment variables from .env file load_dotenv() unittest.main()