mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-10 07:38:04 -05:00
move decorator higher up
Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
This commit is contained in:
committed by
Reinier van der Leer
parent
eb5a8a87d8
commit
b7cd56f72b
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -71,8 +71,7 @@ jobs:
|
||||
|
||||
- name: Run unittest tests with coverage
|
||||
run: |
|
||||
pytest --cov=autogpt --without-integration --without-slow-integration --cov-report term-missing --cov-branch --cov-report xml --cov-report term
|
||||
pytest --cov=autogpt tests/integration/goal_oriented --cov-report term-missing --cov-branch --cov-report xml --cov-report term
|
||||
pytest --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term
|
||||
env:
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
- name: Generate coverage report
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Your other pytest configurations and fixtures
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
def requires_openai_api_key(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
if not os.environ.get('OPENAI_API_KEY'):
|
||||
pytest.skip(
|
||||
"Environment variable 'OPENAI_API_KEY' is not set, skipping the test."
|
||||
)
|
||||
else:
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
@@ -2,7 +2,6 @@ import concurrent
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
import vcr
|
||||
|
||||
from autogpt.agent import Agent
|
||||
@@ -13,8 +12,8 @@ from autogpt.memory import get_memory
|
||||
|
||||
# from autogpt.prompt import Prompt
|
||||
from autogpt.workspace import WORKSPACE_PATH
|
||||
from tests.integration.goal_oriented.decorators import requires_openai_api_key
|
||||
from tests.integration.goal_oriented.vcr_helper import before_record_request
|
||||
from tests.utils import requires_api_key
|
||||
|
||||
current_file_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
# tests_directory = os.path.join(current_file_dir, 'tests')
|
||||
@@ -28,11 +27,8 @@ my_vcr = vcr.VCR(
|
||||
CFG = Config()
|
||||
|
||||
|
||||
@requires_openai_api_key
|
||||
@pytest.mark.integration_test
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_write_file() -> None:
|
||||
# Your test code here
|
||||
|
||||
# if file exist
|
||||
file_name = "hello_world.txt"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import unittest
|
||||
import pytest
|
||||
|
||||
from autogpt.memory.local import LocalCache
|
||||
from tests.utils import requires_api_key
|
||||
|
||||
|
||||
def mock_config() -> dict:
|
||||
@@ -32,17 +33,20 @@ class TestLocalCache(unittest.TestCase):
|
||||
self.cfg = mock_config()
|
||||
self.cache = LocalCache(self.cfg)
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_add(self) -> None:
|
||||
"""Test adding a text to the cache"""
|
||||
text = "Sample text"
|
||||
self.cache.add(text)
|
||||
self.assertIn(text, self.cache.data.texts)
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_clear(self) -> None:
|
||||
"""Test clearing the cache"""
|
||||
self.cache.clear()
|
||||
self.assertEqual(self.cache.data.texts, [])
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_get(self) -> None:
|
||||
"""Test getting a text from the cache"""
|
||||
text = "Sample text"
|
||||
@@ -50,6 +54,7 @@ class TestLocalCache(unittest.TestCase):
|
||||
result = self.cache.get(text)
|
||||
self.assertEqual(result, [text])
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_get_relevant(self) -> None:
|
||||
"""Test getting relevant texts from the cache"""
|
||||
text1 = "Sample text 1"
|
||||
@@ -59,6 +64,7 @@ class TestLocalCache(unittest.TestCase):
|
||||
result = self.cache.get_relevant(text1, 1)
|
||||
self.assertEqual(result, [text1])
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_get_stats(self) -> None:
|
||||
"""Test getting the cache stats"""
|
||||
text = "Sample text"
|
||||
|
||||
@@ -7,6 +7,7 @@ from PIL import Image
|
||||
from autogpt.commands.image_gen import generate_image, generate_image_with_sd_webui
|
||||
from autogpt.config import Config
|
||||
from autogpt.workspace import path_in_workspace
|
||||
from tests.utils import requires_api_key
|
||||
|
||||
|
||||
def lst(txt):
|
||||
@@ -18,6 +19,7 @@ class TestImageGen(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.config = Config()
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_dalle(self):
|
||||
self.config.image_provider = "dalle"
|
||||
|
||||
@@ -36,6 +38,7 @@ class TestImageGen(unittest.TestCase):
|
||||
self.assertEqual(img.size, (512, 512))
|
||||
image_path.unlink()
|
||||
|
||||
@requires_api_key("HUGGINGFACE_API_TOKEN")
|
||||
def test_huggingface(self):
|
||||
self.config.image_provider = "huggingface"
|
||||
|
||||
|
||||
18
tests/utils.py
Normal file
18
tests/utils.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def requires_api_key(env_var):
|
||||
def decorator(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
if not os.environ.get(env_var):
|
||||
pytest.skip(
|
||||
f"Environment variable '{env_var}' is not set, skipping the test."
|
||||
)
|
||||
else:
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
Reference in New Issue
Block a user