summaryrefslogtreecommitdiffstats
path: root/etc/unittest/backend.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-11-16 13:19:51 +0100
committerGitHub <noreply@github.com>2024-11-16 13:19:51 +0100
commit6ce493d4dfc2884832ff5b5be4479a55818b2fe7 (patch)
tree92e9efce62f7832ebe56969c120d8e92e75881a3 /etc/unittest/backend.py
parentUpdate internet.py (diff)
downloadgpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.gz
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.bz2
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.lz
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.xz
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.zst
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.zip
Diffstat (limited to 'etc/unittest/backend.py')
-rw-r--r--etc/unittest/backend.py33
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