@@ -1,7 +1,6 @@
1# -*- coding: utf-8 -*-
1# -*- coding: utf-8 -*-
2"""Test utils/standalone_searx.py"""
2"""Test utils/standalone_searx.py"""
3import datetime
3import datetime
@@ -10,16 +9,7 @@ from nose2.tools import params
11from searx.search import SearchQuery, EngineRef, initialize
10from searx.search import SearchQuery, EngineRef, initialize
12from searx.testing import SearxTestCase
11from searx.testing import SearxTestCase
15−def get_standalone_searx_module():
16− """Get standalone_searx module."""
17− module_name = 'utils.standalone_searx'
12+from searx_extra import standalone_searx as sas
18− filename = 'utils/standalone_searx.py'
19− spec = importlib.util.spec_from_file_location(module_name, filename)
20− sas = importlib.util.module_from_spec(spec)
21− spec.loader.exec_module(sas)
25class StandaloneSearx(SearxTestCase):
15class StandaloneSearx(SearxTestCase):
@@ -33,7 +23,6 @@ class StandaloneSearx(SearxTestCase):
34 def test_parse_argument_no_args(self):
24 def test_parse_argument_no_args(self):
35 """Test parse argument without args."""
25 """Test parse argument without args."""
36− sas = get_standalone_searx_module()
37 with patch.object(sys, 'argv', ['standalone_searx']), \
26 with patch.object(sys, 'argv', ['standalone_searx']), \
38 self.assertRaises(SystemExit):
27 self.assertRaises(SystemExit):
39 sys.stderr = io.StringIO()
28 sys.stderr = io.StringIO()
@@ -42,7 +31,6 @@ class StandaloneSearx(SearxTestCase):
43 def test_parse_argument_basic_args(self):
32 def test_parse_argument_basic_args(self):
44 """Test parse argument with basic args."""
33 """Test parse argument with basic args."""
45− sas = get_standalone_searx_module()
46 query = 'red box'
34 query = 'red box'
47 exp_dict = {
35 exp_dict = {
48 'query': query, 'category': 'general', 'lang': 'all', 'pageno': 1,
36 'query': query, 'category': 'general', 'lang': 'all', 'pageno': 1,
@@ -56,7 +44,6 @@ class StandaloneSearx(SearxTestCase):
57 def test_to_dict(self):
45 def test_to_dict(self):
58 """test to_dict."""
46 """test to_dict."""
59− sas = get_standalone_searx_module()
60 self.assertEqual(
47 self.assertEqual(
61 sas.to_dict(
48 sas.to_dict(
62 sas.get_search_query(sas.parse_argument(['red box']))),
49 sas.get_search_query(sas.parse_argument(['red box']))),
@@ -72,7 +59,6 @@ class StandaloneSearx(SearxTestCase):
73 def test_to_dict_with_mock(self):
60 def test_to_dict_with_mock(self):
74 """test to dict."""
61 """test to dict."""
75− sas = get_standalone_searx_module()
76 with patch.object(sas.searx.search, 'Search') as mock_s:
62 with patch.object(sas.searx.search, 'Search') as mock_s:
77 m_search = mock_s().search()
63 m_search = mock_s().search()
78 m_sq = Mock()
64 m_sq = Mock()
@@ -97,7 +83,6 @@ class StandaloneSearx(SearxTestCase):
98 def test_get_search_query(self):
84 def test_get_search_query(self):
99 """test get_search_query."""
85 """test get_search_query."""
100− sas = get_standalone_searx_module()
101 args = sas.parse_argument(['rain', ])
86 args = sas.parse_argument(['rain', ])
102 search_q = sas.get_search_query(args)
87 search_q = sas.get_search_query(args)
103 self.assertTrue(search_q)
88 self.assertTrue(search_q)
@@ -106,7 +91,6 @@ class StandaloneSearx(SearxTestCase):
107 def test_no_parsed_url(self):
92 def test_no_parsed_url(self):
108 """test no_parsed_url func"""
93 """test no_parsed_url func"""
109− sas = get_standalone_searx_module()
110 self.assertEqual(
94 self.assertEqual(
111 sas.no_parsed_url([{'parsed_url': 'http://example.com'}]),
95 sas.no_parsed_url([{'parsed_url': 'http://example.com'}]),
@@ -119,11 +103,9 @@ class StandaloneSearx(SearxTestCase):
120 def test_json_serial(self, arg, exp_res):
104 def test_json_serial(self, arg, exp_res):
121 """test json_serial func"""
105 """test json_serial func"""
122− sas = get_standalone_searx_module()
123 self.assertEqual(sas.json_serial(arg), exp_res)
106 self.assertEqual(sas.json_serial(arg), exp_res)
125 def test_json_serial_error(self):
108 def test_json_serial_error(self):
126 """test error on json_serial."""
109 """test error on json_serial."""
127− sas = get_standalone_searx_module()
128 with self.assertRaises(TypeError):
110 with self.assertRaises(TypeError):
129 sas.json_serial('a')
111 sas.json_serial('a')