Fix unittests (#1472)

* Fix unittests

* Fix missing distutils, install setuptools

* Fix version not found

* Remove deprecation in get_event_loop
This commit is contained in:
H Lohaus 2024-01-14 16:37:21 +01:00 committed by GitHub
parent faa5f0f9bc
commit 42709f55b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 14 deletions

View File

@ -14,6 +14,6 @@ jobs:
python-version: "3.x"
cache: 'pip'
- name: Install requirements
- run: pip install -r requirements.txt
run: pip install -r requirements.txt
- name: Run tests
- run: python -m etc.unittest.main
run: python -m etc.unittest.main

View File

@ -11,6 +11,7 @@ from g4f.gui.server.backend import Backend_Api, get_error_message
from g4f.base_provider import BaseProvider
g4f.debug.logging = False
g4f.debug.version_check = False
class MockProvider(BaseProvider):
working = True

View File

@ -5,7 +5,7 @@ import os
import random
import secrets
import string
from asyncio import AbstractEventLoop, BaseEventLoop
from asyncio import AbstractEventLoop
from platformdirs import user_config_dir
from browser_cookie3 import (
chrome, chromium, opera, opera_gx,
@ -27,19 +27,13 @@ def get_event_loop() -> AbstractEventLoop:
AbstractEventLoop: The current or new event loop.
"""
try:
loop = asyncio.get_event_loop()
if isinstance(loop, BaseEventLoop):
loop._check_closed()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
asyncio.get_running_loop()
loop = asyncio.get_running_loop()
if not hasattr(loop.__class__, "_nest_patched"):
import nest_asyncio
nest_asyncio.apply(loop)
except RuntimeError:
pass
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
except ImportError:
raise RuntimeError(
'Use "create_async" instead of "create" function in a running event loop. Or install "nest_asyncio" package.'

View File

@ -5,6 +5,7 @@ from typing import Generator
from g4f import debug, version, models
from g4f import _all_models, get_last_provider, ChatCompletion
from g4f.image import is_allowed_extension, to_image
from g4f.errors import VersionNotFoundError
from g4f.Provider import __providers__
from g4f.Provider.bing.create_images import patch_provider
from .internet import get_search_message
@ -91,8 +92,12 @@ class Backend_Api:
Returns:
dict: A dictionary containing the current and latest version.
"""
try:
current_version = version.utils.current_version
except VersionNotFoundError:
current_version = None
return {
"version": version.utils.current_version,
"version": current_version,
"latest_version": version.get_latest_version(),
}

View File

@ -20,4 +20,5 @@ asyncstdlib
async-property
undetected-chromedriver
brotli
beautifulsoup4
beautifulsoup4
setuptools

View File

@ -32,6 +32,7 @@ install_requires = [
"undetected-chromedriver",
"brotli",
"beautifulsoup4",
"setuptools",
]
DESCRIPTION = (