Skip to content

Commit

Permalink
Fix unittests (#1472)
Browse files Browse the repository at this point in the history
* Fix unittests

* Fix missing distutils, install setuptools

* Fix version not found

* Remove deprecation in get_event_loop
  • Loading branch information
hlohaus authored Jan 14, 2024
1 parent faa5f0f commit 42709f5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions etc/unittest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from g4f.base_provider import BaseProvider

g4f.debug.logging = False
g4f.debug.version_check = False

class MockProvider(BaseProvider):
working = True
Expand Down
14 changes: 4 additions & 10 deletions g4f/Provider/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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,
Expand All @@ -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.'
Expand Down
7 changes: 6 additions & 1 deletion g4f/gui/server/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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
Expand Down Expand Up @@ -91,8 +92,12 @@ def get_version(self):
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(),
}

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ asyncstdlib
async-property
undetected-chromedriver
brotli
beautifulsoup4
beautifulsoup4
setuptools
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"undetected-chromedriver",
"brotli",
"beautifulsoup4",
"setuptools",
]

DESCRIPTION = (
Expand Down

0 comments on commit 42709f5

Please sign in to comment.