1- import llm
21import json
3- import pytest
42import os
3+
4+ import llm
5+ import pytest
6+
57from llm_tools_searxng import SearXNG , searxng_search
68
79
@@ -10,7 +12,7 @@ def test_searxng_search_function_get(httpx_mock, monkeypatch):
1012 # Set required environment variable and explicitly set GET method
1113 monkeypatch .setenv ("SEARXNG_URL" , "https://searx.be" )
1214 monkeypatch .setenv ("SEARXNG_METHOD" , "GET" )
13-
15+
1416 # Mock the HTTP response
1517 mock_response = {
1618 "query" : "test query" ,
@@ -19,16 +21,16 @@ def test_searxng_search_function_get(httpx_mock, monkeypatch):
1921 "title" : "Test Result" ,
2022 "url" : "https://example.com" ,
2123 "content" : "This is a test result" ,
22- "engine" : "duckduckgo"
24+ "engine" : "duckduckgo" ,
2325 }
24- ]
26+ ],
2527 }
2628 httpx_mock .add_response (
2729 url = "https://searx.be/search?q=test+query&format=json&language=en&pageno=1&safesearch=1" ,
2830 json = mock_response ,
29- method = "GET"
31+ method = "GET" ,
3032 )
31-
33+
3234 model = llm .get_model ("echo" )
3335 chain_response = model .chain (
3436 json .dumps (
@@ -42,7 +44,7 @@ def test_searxng_search_function_get(httpx_mock, monkeypatch):
4244 )
4345 responses = list (chain_response .responses ())
4446 tool_results = json .loads (responses [- 1 ].text ())["tool_results" ]
45-
47+
4648 # The output should be a JSON string containing the formatted results
4749 output = json .loads (tool_results [0 ]["output" ])
4850 assert output ["query" ] == "test query"
@@ -55,24 +57,22 @@ def test_searxng_search_function_post(httpx_mock, monkeypatch):
5557 # Set required environment variable and POST method
5658 monkeypatch .setenv ("SEARXNG_URL" , "https://searx.be" )
5759 monkeypatch .setenv ("SEARXNG_METHOD" , "POST" )
58-
60+
5961 mock_response = {
6062 "query" : "test query" ,
6163 "results" : [
6264 {
6365 "title" : "Test Result POST" ,
6466 "url" : "https://example.com" ,
6567 "content" : "This is a test result via POST" ,
66- "engine" : "duckduckgo"
68+ "engine" : "duckduckgo" ,
6769 }
68- ]
70+ ],
6971 }
7072 httpx_mock .add_response (
71- url = "https://searx.be/search" ,
72- json = mock_response ,
73- method = "POST"
73+ url = "https://searx.be/search" , json = mock_response , method = "POST"
7474 )
75-
75+
7676 model = llm .get_model ("echo" )
7777 chain_response = model .chain (
7878 json .dumps (
@@ -86,7 +86,7 @@ def test_searxng_search_function_post(httpx_mock, monkeypatch):
8686 )
8787 responses = list (chain_response .responses ())
8888 tool_results = json .loads (responses [- 1 ].text ())["tool_results" ]
89-
89+
9090 # The output should be a JSON string containing the formatted results
9191 output = json .loads (tool_results [0 ]["output" ])
9292 assert output ["query" ] == "test query"
@@ -98,28 +98,28 @@ def test_searxng_class_direct_get(httpx_mock, monkeypatch):
9898 """Test the SearXNG class directly with GET method"""
9999 # Explicitly set GET method
100100 monkeypatch .setenv ("SEARXNG_METHOD" , "GET" )
101-
101+
102102 mock_response = {
103103 "query" : "python" ,
104104 "results" : [
105105 {
106106 "title" : "Python.org" ,
107107 "url" : "https://python.org" ,
108108 "content" : "The official Python website" ,
109- "engine" : "google"
109+ "engine" : "google" ,
110110 }
111- ]
111+ ],
112112 }
113113 httpx_mock .add_response (
114114 url = "https://custom.searxng.com/search?q=python&format=json&language=en&pageno=1&safesearch=1" ,
115115 json = mock_response ,
116- method = "GET"
116+ method = "GET" ,
117117 )
118-
118+
119119 # Test the SearXNG class directly
120120 searxng = SearXNG ("https://custom.searxng.com" )
121121 result = searxng .search ("python" )
122-
122+
123123 output = json .loads (result )
124124 assert output ["query" ] == "python"
125125 assert len (output ["results" ]) == 1
@@ -135,20 +135,18 @@ def test_searxng_class_direct_post_default(httpx_mock):
135135 "title" : "Python.org" ,
136136 "url" : "https://python.org" ,
137137 "content" : "The official Python website" ,
138- "engine" : "google"
138+ "engine" : "google" ,
139139 }
140- ]
140+ ],
141141 }
142142 httpx_mock .add_response (
143- url = "https://custom.searxng.com/search" ,
144- json = mock_response ,
145- method = "POST"
143+ url = "https://custom.searxng.com/search" , json = mock_response , method = "POST"
146144 )
147-
145+
148146 # Test the SearXNG class directly without setting method (should default to POST)
149147 searxng = SearXNG ("https://custom.searxng.com" )
150148 result = searxng .search ("python" )
151-
149+
152150 output = json .loads (result )
153151 assert output ["query" ] == "python"
154152 assert len (output ["results" ]) == 1
0 commit comments