Improve asserts in unittests

This commit is contained in:
Heiner Lohaus 2024-01-20 18:16:45 +01:00
parent 7f4d9ba82b
commit 782edbdb6a
1 changed files with 5 additions and 4 deletions

View File

@ -39,10 +39,11 @@ class TestBackendApi(unittest.TestCase):
class TestChatCompletion(unittest.TestCase):
def test_create(self):
def test_create_default(self):
messages = [{'role': 'user', 'content': 'Hello'}]
result = ChatCompletion.create(g4f.models.default, messages)
self.assertTrue("Hello" in result or "Good" in result)
if "Good" not in result and "Hi" not in result:
self.assertIn("Hello", result)
def test_get_last_provider(self):
messages = [{'role': 'user', 'content': 'Hello'}]
@ -53,14 +54,14 @@ class TestChatCompletion(unittest.TestCase):
messages = [{'role': 'user', 'content': 'Hello'}]
provider = g4f.Provider.Bing
result = ChatCompletion.create(g4f.models.default, messages, provider)
self.assertTrue("Bing" in result)
self.assertIn("Bing", result)
class TestChatCompletionAsync(unittest.IsolatedAsyncioTestCase):
async def test_async(self):
messages = [{'role': 'user', 'content': 'Hello'}]
result = await ChatCompletion.create_async(g4f.models.default, messages, MockProvider)
self.assertTrue("Mock" in result)
self.assertEqual("Mock", result)
class TestUtilityFunctions(unittest.TestCase):