summaryrefslogtreecommitdiffstats
path: root/etc/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'etc/unittest')
-rw-r--r--etc/unittest/__main__.py2
-rw-r--r--etc/unittest/backend.py18
-rw-r--r--etc/unittest/client.py10
-rw-r--r--etc/unittest/include.py18
-rw-r--r--etc/unittest/mocks.py2
5 files changed, 33 insertions, 17 deletions
diff --git a/etc/unittest/__main__.py b/etc/unittest/__main__.py
index a133343e..06b2dff5 100644
--- a/etc/unittest/__main__.py
+++ b/etc/unittest/__main__.py
@@ -3,5 +3,7 @@ from .asyncio import *
from .backend import *
from .main import *
from .model import *
+from .client import *
+from .include import *
unittest.main() \ No newline at end of file
diff --git a/etc/unittest/backend.py b/etc/unittest/backend.py
index e4a7b3ab..c4ab219e 100644
--- a/etc/unittest/backend.py
+++ b/etc/unittest/backend.py
@@ -1,13 +1,15 @@
import unittest
+import asyncio
from unittest.mock import MagicMock
from .mocks import ProviderMock
import g4f
+
try:
from g4f.gui.server.backend import Backend_Api, get_error_message
has_requirements = True
except:
has_requirements = False
-
+
class TestBackendApi(unittest.TestCase):
def setUp(self):
@@ -20,17 +22,23 @@ class TestBackendApi(unittest.TestCase):
response = self.api.get_version()
self.assertIn("version", response)
self.assertIn("latest_version", response)
-
+
def test_get_models(self):
response = self.api.get_models()
self.assertIsInstance(response, list)
self.assertTrue(len(response) > 0)
-
+
def test_get_providers(self):
response = self.api.get_providers()
self.assertIsInstance(response, list)
self.assertTrue(len(response) > 0)
-
+
+ def test_search(self):
+ # Task was destroyed but it is pending!
+ from g4f.gui.server.internet import search
+ result = asyncio.run(search("Hello"))
+ self.assertEqual(5, len(result))
+
class TestUtilityFunctions(unittest.TestCase):
def setUp(self):
@@ -42,6 +50,6 @@ class TestUtilityFunctions(unittest.TestCase):
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
diff --git a/etc/unittest/client.py b/etc/unittest/client.py
index c63edbd2..ec8aa4b7 100644
--- a/etc/unittest/client.py
+++ b/etc/unittest/client.py
@@ -35,15 +35,17 @@ class TestPassModel(unittest.TestCase):
response = client.chat.completions.create(messages, "Hello", stream=True)
for chunk in response:
self.assertIsInstance(chunk, ChatCompletionChunk)
- self.assertIsInstance(chunk.choices[0].delta.content, str)
+ if chunk.choices[0].delta.content is not None:
+ self.assertIsInstance(chunk.choices[0].delta.content, str)
messages = [{'role': 'user', 'content': chunk} for chunk in ["You ", "You ", "Other", "?"]]
response = client.chat.completions.create(messages, "Hello", stream=True, max_tokens=2)
response = list(response)
- self.assertEqual(len(response), 2)
+ self.assertEqual(len(response), 3)
for chunk in response:
- self.assertEqual(chunk.choices[0].delta.content, "You ")
+ if chunk.choices[0].delta.content is not None:
+ self.assertEqual(chunk.choices[0].delta.content, "You ")
- def no_test_stop(self):
+ def test_stop(self):
client = Client(provider=YieldProviderMock)
messages = [{'role': 'user', 'content': chunk} for chunk in ["How ", "are ", "you", "?"]]
response = client.chat.completions.create(messages, "Hello", stop=["and"])
diff --git a/etc/unittest/include.py b/etc/unittest/include.py
index e67fd5a7..9695bc5b 100644
--- a/etc/unittest/include.py
+++ b/etc/unittest/include.py
@@ -1,11 +1,15 @@
-import sys
-import pathlib
+import unittest
-sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
+class TestImport(unittest.TestCase):
-import g4f
+ def test_get_cookies(self):
+ from g4f import get_cookies as get_cookies_alias
+ from g4f.cookies import get_cookies
+ self.assertEqual(get_cookies_alias, get_cookies)
-g4f.debug.logging = False
-g4f.debug.version_check = False
+ def test_requests(self):
+ from g4f.requests import StreamSession
+ self.assertIsInstance(StreamSession, type)
-DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}] \ No newline at end of file
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file
diff --git a/etc/unittest/mocks.py b/etc/unittest/mocks.py
index 8a67aaf7..102730fa 100644
--- a/etc/unittest/mocks.py
+++ b/etc/unittest/mocks.py
@@ -1,4 +1,4 @@
-from g4f.Provider.base_provider import AbstractProvider, AsyncProvider, AsyncGeneratorProvider
+from g4f.providers.base_provider import AbstractProvider, AsyncProvider, AsyncGeneratorProvider
class ProviderMock(AbstractProvider):
working = True