summaryrefslogtreecommitdiffstats
path: root/etc/unittest
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-22 00:16:58 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-22 00:16:58 +0100
commite5b7f72b719814ffa2748e8e8ed1c6713a24e1a6 (patch)
tree70e9f87cb18f165428492d53a1c6e28c0828490a /etc/unittest
parentUpdate docs / readme, Improve Gemini auth (diff)
downloadgpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.gz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.bz2
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.lz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.xz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.zst
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.zip
Diffstat (limited to 'etc/unittest')
-rw-r--r--etc/unittest/__main__.py2
-rw-r--r--etc/unittest/backend.py14
-rw-r--r--etc/unittest/client.py2
-rw-r--r--etc/unittest/include.py18
-rw-r--r--etc/unittest/mocks.py2
5 files changed, 25 insertions, 13 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..846c3554 100644
--- a/etc/unittest/backend.py
+++ b/etc/unittest/backend.py
@@ -1,9 +1,11 @@
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
+ # from g4f.gui.server.internet import search
has_requirements = True
except:
has_requirements = False
@@ -16,10 +18,10 @@ class TestBackendApi(unittest.TestCase):
self.app = MagicMock()
self.api = Backend_Api(self.app)
- def test_version(self):
- response = self.api.get_version()
- self.assertIn("version", response)
- self.assertIn("latest_version", response)
+ # def test_version(self):
+ # response = self.api.get_version()
+ # self.assertIn("version", response)
+ # self.assertIn("latest_version", response)
def test_get_models(self):
response = self.api.get_models()
@@ -31,6 +33,10 @@ class TestBackendApi(unittest.TestCase):
self.assertIsInstance(response, list)
self.assertTrue(len(response) > 0)
+ # def test_search(self):
+ # result = asyncio.run(search("Hello"))
+ # self.assertEqual(5, len(result))
+
class TestUtilityFunctions(unittest.TestCase):
def setUp(self):
diff --git a/etc/unittest/client.py b/etc/unittest/client.py
index c63edbd2..2bc00c2e 100644
--- a/etc/unittest/client.py
+++ b/etc/unittest/client.py
@@ -43,7 +43,7 @@ class TestPassModel(unittest.TestCase):
for chunk in response:
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