summaryrefslogtreecommitdiffstats
path: root/etc/unittest/asyncio.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-29 20:37:59 +0100
committerGitHub <noreply@github.com>2024-01-29 20:37:59 +0100
commit280ddf57b0f54d1805f1ee26aa699469019e731f (patch)
treecabcbf5fa9a5dbf75a223377dbf032cfeb3e1027 /etc/unittest/asyncio.py
parentMerge pull request #1523 from u66u/which-webdriver (diff)
parentImprove readme / unittests (diff)
downloadgpt4free-280ddf57b0f54d1805f1ee26aa699469019e731f.tar
gpt4free-280ddf57b0f54d1805f1ee26aa699469019e731f.tar.gz
gpt4free-280ddf57b0f54d1805f1ee26aa699469019e731f.tar.bz2
gpt4free-280ddf57b0f54d1805f1ee26aa699469019e731f.tar.lz
gpt4free-280ddf57b0f54d1805f1ee26aa699469019e731f.tar.xz
gpt4free-280ddf57b0f54d1805f1ee26aa699469019e731f.tar.zst
gpt4free-280ddf57b0f54d1805f1ee26aa699469019e731f.zip
Diffstat (limited to 'etc/unittest/asyncio.py')
-rw-r--r--etc/unittest/asyncio.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/etc/unittest/asyncio.py b/etc/unittest/asyncio.py
index a31ce211..e886c43a 100644
--- a/etc/unittest/asyncio.py
+++ b/etc/unittest/asyncio.py
@@ -1,4 +1,3 @@
-from .include import DEFAULT_MESSAGES
import asyncio
try:
import nest_asyncio
@@ -6,55 +5,60 @@ try:
except:
has_nest_asyncio = False
import unittest
+
import g4f
from g4f import ChatCompletion
from .mocks import ProviderMock, AsyncProviderMock, AsyncGeneratorProviderMock
-
+
+DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}]
+
class TestChatCompletion(unittest.TestCase):
-
+
async def run_exception(self):
return ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES, AsyncProviderMock)
-
+
def test_exception(self):
+ if hasattr(asyncio, '_nest_patched'):
+ self.skipTest('asyncio is already patched')
self.assertRaises(g4f.errors.NestAsyncioError, asyncio.run, self.run_exception())
def test_create(self):
result = ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES, AsyncProviderMock)
self.assertEqual("Mock",result)
-
+
def test_create_generator(self):
result = ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES, AsyncGeneratorProviderMock)
self.assertEqual("Mock",result)
class TestChatCompletionAsync(unittest.IsolatedAsyncioTestCase):
-
+
async def test_base(self):
result = await ChatCompletion.create_async(g4f.models.default, DEFAULT_MESSAGES, ProviderMock)
self.assertEqual("Mock",result)
-
+
async def test_async(self):
result = await ChatCompletion.create_async(g4f.models.default, DEFAULT_MESSAGES, AsyncProviderMock)
self.assertEqual("Mock",result)
-
+
async def test_create_generator(self):
result = await ChatCompletion.create_async(g4f.models.default, DEFAULT_MESSAGES, AsyncGeneratorProviderMock)
self.assertEqual("Mock",result)
-
+
class TestChatCompletionNestAsync(unittest.IsolatedAsyncioTestCase):
-
+
def setUp(self) -> None:
if not has_nest_asyncio:
self.skipTest('"nest_asyncio" not installed')
nest_asyncio.apply()
-
+
async def test_create(self):
result = await ChatCompletion.create_async(g4f.models.default, DEFAULT_MESSAGES, ProviderMock)
self.assertEqual("Mock",result)
-
+
async def test_nested(self):
result = ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES, AsyncProviderMock)
self.assertEqual("Mock",result)
-
+
async def test_nested_generator(self):
result = ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES, AsyncGeneratorProviderMock)
self.assertEqual("Mock",result)