__init__.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # pylint: disable=missing-module-docstring
  3. import os
  4. import aiounittest
  5. os.environ.pop('SEARX_DEBUG', None)
  6. os.environ.pop('SEARX_DEBUG_LOG_LEVEL', None)
  7. os.environ.pop('SEARX_DISABLE_ETC_SETTINGS', None)
  8. os.environ.pop('SEARX_SETTINGS_PATH', None)
  9. os.environ.pop('SEARXNG_SETTINGS_PATH', None)
  10. os.environ['SEARXNG_DEBUG'] = '1'
  11. os.environ['SEARXNG_DEBUG_LOG_LEVEL'] = 'WARNING'
  12. os.environ['SEARXNG_DISABLE_ETC_SETTINGS'] = '1'
  13. class SearxTestLayer:
  14. """Base layer for non-robot tests."""
  15. __name__ = 'SearxTestLayer'
  16. @classmethod
  17. def setUp(cls):
  18. pass
  19. @classmethod
  20. def tearDown(cls):
  21. pass
  22. @classmethod
  23. def testSetUp(cls):
  24. pass
  25. @classmethod
  26. def testTearDown(cls):
  27. pass
  28. class SearxTestCase(aiounittest.AsyncTestCase):
  29. """Base test case for non-robot tests."""
  30. layer = SearxTestLayer
  31. def setattr4test(self, obj, attr, value):
  32. """
  33. setattr(obj, attr, value)
  34. but reset to the previous value in the cleanup.
  35. """
  36. previous_value = getattr(obj, attr)
  37. def cleanup_patch():
  38. setattr(obj, attr, previous_value)
  39. self.addCleanup(cleanup_patch)
  40. setattr(obj, attr, value)