Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix: Fix CI failing tests

Reinier van der Leer6c69e16f31c9
diff --git a/autogpts/autogpt/tests/unit/test_config.py b/autogpts/autogpt/tests/unit/test_config.py
index 083946c327..df77132295 100644
--- a/autogpts/autogpt/tests/unit/test_config.py
+++ b/autogpts/autogpt/tests/unit/test_config.py
@@ -21,7 +21,7 @@ def test_initial_values(config: Config) -> None:
assert config.continuous_mode is False
assert config.tts_config.speak_mode is False
assert config.fast_llm == "gpt-3.5-turbo-16k"
- assert config.smart_llm == "gpt-4-0314"
+ assert config.smart_llm.startswith("gpt-4")
def test_set_continuous_mode(config: Config) -> None:
diff --git a/autogpts/autogpt/tests/unit/test_retry_provider_openai.py b/autogpts/autogpt/tests/unit/test_retry_provider_openai.py
deleted file mode 100644
index e076a39735..0000000000
--- a/autogpts/autogpt/tests/unit/test_retry_provider_openai.py
+++ /dev/null
@@ -1,143 +0,0 @@
-import logging
-
-import pytest
-from openai.error import APIError, RateLimitError, ServiceUnavailableError
-
-from autogpt.llm.providers import openai
-from autogpt.logs.config import USER_FRIENDLY_OUTPUT_LOGGER
-
-
[email protected](params=[RateLimitError, ServiceUnavailableError, APIError])
-def error(request):
- if request.param == APIError:
- return request.param("Error", http_status=502)
- else:
- return request.param("Error")
-
-
-def error_factory(error_instance, error_count, retry_count, warn_user=True):
- """Creates errors"""
-
- class RaisesError:
- def __init__(self):
- self.count = 0
-
- @openai.retry_api(
- max_retries=retry_count, backoff_base=0.001, warn_user=warn_user
- )
- def __call__(self):
- self.count += 1
- if self.count <= error_count:
- raise error_instance
- return self.count
-
- return RaisesError()
-
-
-def test_retry_open_api_no_error(caplog: pytest.LogCaptureFixture):
- """Tests the retry functionality with no errors expected"""
-
- @openai.retry_api()
- def f():
- return 1
-
- result = f()
- assert result == 1
-
- output = caplog.text
- assert output == ""
- assert output == ""
-
-
- "error_count, retry_count, failure",
- [(2, 10, False), (2, 2, False), (10, 2, True), (3, 2, True), (1, 0, True)],
- ids=["passing", "passing_edge", "failing", "failing_edge", "failing_no_retries"],
-)
-def test_retry_open_api_passing(
- caplog: pytest.LogCaptureFixture,
- error: Exception,
- error_count: int,
- retry_count: int,
- failure: bool,
-):
- """Tests the retry with simulated errors [RateLimitError, ServiceUnavailableError, APIError], but should ulimately pass"""
-
- # Add capture handler to non-propagating logger
- logging.getLogger(USER_FRIENDLY_OUTPUT_LOGGER).addHandler(caplog.handler)
-
- call_count = min(error_count, retry_count) + 1
-
- raises = error_factory(error, error_count, retry_count)
- if failure:
- with pytest.raises(type(error)):
- raises()
- else:
- result = raises()
- assert result == call_count
-
- assert raises.count == call_count
-
- output = caplog.text
-
- if error_count and retry_count:
- if type(error) == RateLimitError:
- assert "Reached rate limit" in output
- assert "Please double check" in output
- if type(error) == ServiceUnavailableError:
- assert "The OpenAI API engine is currently overloaded" in output
- assert "Please double check" in output
- else:
- assert output == ""
-
-
-def test_retry_open_api_rate_limit_no_warn(caplog: pytest.LogCaptureFixture):
- """Tests the retry logic with a rate limit error"""
- error_count = 2
- retry_count = 10
-
- raises = error_factory(RateLimitError, error_count, retry_count, warn_user=False)
- result = raises()
- call_count = min(error_count, retry_count) + 1
- assert result == call_count
- assert raises.count == call_count
-
- output = caplog.text
-
- assert "Reached rate limit" in output
- assert "Please double check" not in output
-
-
-def test_retry_open_api_service_unavairable_no_warn(caplog: pytest.LogCaptureFixture):
- """Tests the retry logic with a service unavairable error"""
- error_count = 2
- retry_count = 10
-
- raises = error_factory(
- ServiceUnavailableError, error_count, retry_count, warn_user=False
- )
- result = raises()
- call_count = min(error_count, retry_count) + 1
- assert result == call_count
- assert raises.count == call_count
-
- output = caplog.text
-
- assert "The OpenAI API engine is currently overloaded" in output
- assert "Please double check" not in output
-
-
-def test_retry_openapi_other_api_error(caplog: pytest.LogCaptureFixture):
- """Tests the Retry logic with a non rate limit error such as HTTP500"""
- error_count = 2
- retry_count = 10
-
- raises = error_factory(APIError("Error", http_status=500), error_count, retry_count)
-
- with pytest.raises(APIError):
- raises()
- call_count = 1
- assert raises.count == call_count
-
- output = caplog.text
- assert output == ""
diff --git a/autogpts/autogpt/tests/unit/test_url_validation.py b/autogpts/autogpt/tests/unit/test_url_validation.py
index 5d6e8124e9..743c0e35ab 100644
--- a/autogpts/autogpt/tests/unit/test_url_validation.py
+++ b/autogpts/autogpt/tests/unit/test_url_validation.py
@@ -64,11 +64,10 @@ def test_url_validation_fails_invalid_url(url, expected_error):
local_file = (
- ("http://localhost"),
- ("https://localhost/"),
- ("http://2130706433"),
- ("https://2130706433"),
- ("http://127.0.0.1/"),
+ ("file://localhost"),
+ ("file://localhost/home/reinier/secrets.txt"),
+ ("file:///home/reinier/secrets.txt"),
+ ("file:///C:/Users/Reinier/secrets.txt"),
)
diff --git a/autogpts/autogpt/tests/unit/test_web_search.py b/autogpts/autogpt/tests/unit/test_web_search.py
index a8ccb0ce67..c4aba67f11 100644
--- a/autogpts/autogpt/tests/unit/test_web_search.py
+++ b/autogpts/autogpt/tests/unit/test_web_search.py
@@ -24,28 +24,28 @@ def test_safe_google_results_invalid_input():
@pytest.mark.parametrize(
- "query, num_results, expected_output, return_value",
+ "query, num_results, expected_output_parts, return_value",
[
(
"test",
1,
- '[\n {\n "title": "Result 1",\n "url": "https://example.com/result1"\n }\n]',
+ ("Result 1", "https://example.com/result1"),
[{"title": "Result 1", "href": "https://example.com/result1"}],
),
- ("", 1, "[]", []),
- ("no results", 1, "[]", []),
+ ("", 1, (), []),
+ ("no results", 1, (), []),
],
)
def test_google_search(
- query, num_results, expected_output, return_value, mocker, agent: Agent
+ query, num_results, expected_output_parts, return_value, mocker, agent: Agent
):
mock_ddg = mocker.Mock()
mock_ddg.return_value = return_value
mocker.patch("autogpt.commands.web_search.DDGS.text", mock_ddg)
actual_output = web_search(query, agent=agent, num_results=num_results)
- expected_output = safe_google_results(expected_output)
- assert actual_output == expected_output
+ for o in expected_output_parts:
+ assert o in actual_output
@pytest.fixture