diff options
Diffstat (limited to 'etc/unittest/backend.py')
-rw-r--r-- | etc/unittest/backend.py | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/etc/unittest/backend.py b/etc/unittest/backend.py index ee6174d5..a2999c5c 100644 --- a/etc/unittest/backend.py +++ b/etc/unittest/backend.py @@ -1,15 +1,19 @@ +from __future__ import annotations + import unittest import asyncio from unittest.mock import MagicMock -from .mocks import ProviderMock -import g4f from g4f.errors import MissingRequirementsError - try: - from g4f.gui.server.backend import Backend_Api, get_error_message + from g4f.gui.server.backend import Backend_Api has_requirements = True except: has_requirements = False +try: + from duckduckgo_search.exceptions import DuckDuckGoSearchException +except ImportError: + class DuckDuckGoSearchException: + pass class TestBackendApi(unittest.TestCase): @@ -31,28 +35,15 @@ class TestBackendApi(unittest.TestCase): def test_get_providers(self): response = self.api.get_providers() - self.assertIsInstance(response, list) + self.assertIsInstance(response, dict) self.assertTrue(len(response) > 0) def test_search(self): from g4f.gui.server.internet import search try: result = asyncio.run(search("Hello")) + except DuckDuckGoSearchException as e: + self.skipTest(e) except MissingRequirementsError: self.skipTest("search is not installed") - self.assertEqual(5, len(result)) - -class TestUtilityFunctions(unittest.TestCase): - - def setUp(self): - if not has_requirements: - self.skipTest("gui is not installed") - - def test_get_error_message(self): - g4f.debug.last_provider = ProviderMock - exception = Exception("Message") - result = get_error_message(exception) - self.assertEqual("ProviderMock: Exception: Message", result) - -if __name__ == '__main__': - unittest.main()
\ No newline at end of file + self.assertEqual(5, len(result))
\ No newline at end of file |