|
@@ -1,40 +1,19 @@
|
|
-# -*- coding: utf-8 -*-
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
# lint: pylint
|
|
# lint: pylint
|
|
"""Shared testing code."""
|
|
"""Shared testing code."""
|
|
|
|
|
|
# pylint: disable=missing-function-docstring
|
|
# pylint: disable=missing-function-docstring
|
|
|
|
|
|
|
|
+import sys
|
|
import os
|
|
import os
|
|
import subprocess
|
|
import subprocess
|
|
import traceback
|
|
import traceback
|
|
-
|
|
|
|
-from os.path import dirname, join, abspath, realpath
|
|
|
|
|
|
+import pathlib
|
|
|
|
|
|
from splinter import Browser
|
|
from splinter import Browser
|
|
-import aiounittest
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-class SearxTestLayer:
|
|
|
|
- """Base layer for non-robot tests."""
|
|
|
|
-
|
|
|
|
- __name__ = 'SearxTestLayer'
|
|
|
|
-
|
|
|
|
- @classmethod
|
|
|
|
- def setUp(cls):
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
- @classmethod
|
|
|
|
- def tearDown(cls):
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
- @classmethod
|
|
|
|
- def testSetUp(cls):
|
|
|
|
- pass
|
|
|
|
|
|
|
|
- @classmethod
|
|
|
|
- def testTearDown(cls):
|
|
|
|
- pass
|
|
|
|
|
|
+import tests as searx_tests
|
|
|
|
+from tests.robot import test_webapp
|
|
|
|
|
|
|
|
|
|
class SearxRobotLayer():
|
|
class SearxRobotLayer():
|
|
@@ -43,8 +22,10 @@ class SearxRobotLayer():
|
|
def setUp(self):
|
|
def setUp(self):
|
|
os.setpgrp() # create new process group, become its leader
|
|
os.setpgrp() # create new process group, become its leader
|
|
|
|
|
|
|
|
+ tests_path = pathlib.Path(searx_tests.__file__).resolve().parent
|
|
|
|
+
|
|
# get program paths
|
|
# get program paths
|
|
- webapp = join(abspath(dirname(realpath(__file__))), 'webapp.py')
|
|
|
|
|
|
+ webapp = str(tests_path.parent / 'searx' / 'webapp.py')
|
|
exe = 'python'
|
|
exe = 'python'
|
|
|
|
|
|
# The Flask app is started by Flask.run(...), don't enable Flask's debug
|
|
# The Flask app is started by Flask.run(...), don't enable Flask's debug
|
|
@@ -57,8 +38,7 @@ class SearxRobotLayer():
|
|
os.environ['SEARX_DEBUG'] = '0'
|
|
os.environ['SEARX_DEBUG'] = '0'
|
|
|
|
|
|
# set robot settings path
|
|
# set robot settings path
|
|
- os.environ['SEARX_SETTINGS_PATH'] = abspath(
|
|
|
|
- dirname(__file__) + '/settings_robot.yml')
|
|
|
|
|
|
+ os.environ['SEARX_SETTINGS_PATH'] = str(tests_path / 'robot' / 'settings_robot.yml')
|
|
|
|
|
|
# run the server
|
|
# run the server
|
|
self.server = subprocess.Popen( # pylint: disable=consider-using-with
|
|
self.server = subprocess.Popen( # pylint: disable=consider-using-with
|
|
@@ -75,7 +55,6 @@ class SearxRobotLayer():
|
|
del os.environ['SEARX_SETTINGS_PATH']
|
|
del os.environ['SEARX_SETTINGS_PATH']
|
|
|
|
|
|
|
|
|
|
-# SEARXROBOTLAYER = SearxRobotLayer()
|
|
|
|
def run_robot_tests(tests):
|
|
def run_robot_tests(tests):
|
|
print('Running {0} tests'.format(len(tests)))
|
|
print('Running {0} tests'.format(len(tests)))
|
|
for test in tests:
|
|
for test in tests:
|
|
@@ -83,38 +62,17 @@ def run_robot_tests(tests):
|
|
test(browser)
|
|
test(browser)
|
|
|
|
|
|
|
|
|
|
-class SearxTestCase(aiounittest.AsyncTestCase):
|
|
|
|
- """Base test case for non-robot tests."""
|
|
|
|
-
|
|
|
|
- layer = SearxTestLayer
|
|
|
|
-
|
|
|
|
- def setattr4test(self, obj, attr, value):
|
|
|
|
- """
|
|
|
|
- setattr(obj, attr, value)
|
|
|
|
- but reset to the previous value in the cleanup.
|
|
|
|
- """
|
|
|
|
- previous_value = getattr(obj, attr)
|
|
|
|
-
|
|
|
|
- def cleanup_patch():
|
|
|
|
- setattr(obj, attr, previous_value)
|
|
|
|
- self.addCleanup(cleanup_patch)
|
|
|
|
- setattr(obj, attr, value)
|
|
|
|
|
|
+def main():
|
|
|
|
+ test_layer = SearxRobotLayer()
|
|
|
|
+ try:
|
|
|
|
+ test_layer.setUp()
|
|
|
|
+ run_robot_tests([getattr(test_webapp, x) for x in dir(test_webapp) if x.startswith('test_')])
|
|
|
|
+ except Exception: # pylint: disable=broad-except
|
|
|
|
+ print('Error occured: {0}'.format(traceback.format_exc()))
|
|
|
|
+ sys.exit(1)
|
|
|
|
+ finally:
|
|
|
|
+ test_layer.tearDown()
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
- import sys
|
|
|
|
- # test cases
|
|
|
|
- from tests import robot
|
|
|
|
-
|
|
|
|
- base_dir = abspath(join(dirname(__file__), '../tests'))
|
|
|
|
- if sys.argv[1] == 'robot':
|
|
|
|
- test_layer = SearxRobotLayer()
|
|
|
|
- errors = False
|
|
|
|
- try:
|
|
|
|
- test_layer.setUp()
|
|
|
|
- run_robot_tests([getattr(robot, x) for x in dir(robot) if x.startswith('test_')])
|
|
|
|
- except Exception: # pylint: disable=broad-except
|
|
|
|
- errors = True
|
|
|
|
- print('Error occured: {0}'.format(traceback.format_exc()))
|
|
|
|
- test_layer.tearDown()
|
|
|
|
- sys.exit(1 if errors else 0)
|
|
|
|
|
|
+ main()
|