mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-23 08:54:24 +01:00
Pass Configs to Commands and remove CFG = Config() in the commands/ folder (#4328)
* feat: pass config to call_ai_functions in coimmands * feat: config for read_audio_from_file * feat: file operations cfg NOTE: we replaced the CFG in the command enable with TRUE b/c not sure how to handle this yet * feat: git command conversion * feat: google search * feat: image generation * feat: extract cfg from browser commands * feat: remove cfg from execute code commands * fix: file operation related tests * fix: linting * fix: tests for read_audio * fix: test error * feat: update cassettes * fix: linting * fix: test typechecking * fix: google_search errors if unexpected kw arg is passed * fix: pass config param to google search test * fix: agent commands were broken + cassettes * fix: agent test * feat: cassettes * feat: enable/disable logic for commands * fix: some commands threw errors * feat: fix tests * Add new cassettes * Add new cassettes * ci: trigger ci * Update autogpt/commands/execute_code.py Co-authored-by: Reinier van der Leer <github@pwuts.nl> * fix prompt * fix prompt + rebase * add config remove useless imports * put back CFG just for download file * lint * The signature should be mandatory in the decorator * black isort * fix: remove the CFG * fix: non typed arg * lint: type some args * lint: add types for libraries * Add new cassettes * fix: windows compatibility * fix: add config access to decorator * fix: remove twitter mention * DDGS search works at 3.0.2 version * ci: linting --------- Co-authored-by: Auto-GPT-Bot <github-bot@agpt.co> Co-authored-by: merwanehamadi <merwanehamadi@gmail.com> Co-authored-by: Reinier van der Leer <github@pwuts.nl> Co-authored-by: kinance <kinance@gmail.com>
This commit is contained in:
@@ -42,7 +42,7 @@ Additional aspects:
|
||||
|
||||
|
||||
class TestScrapeText:
|
||||
def test_scrape_text_with_valid_url(self, mocker):
|
||||
def test_scrape_text_with_valid_url(self, mocker, config):
|
||||
"""Tests that scrape_text() returns the expected text when given a valid URL."""
|
||||
# Mock the requests.get() method to return a response with expected text
|
||||
expected_text = "This is some sample text"
|
||||
@@ -57,14 +57,14 @@ class TestScrapeText:
|
||||
# Call the function with a valid URL and assert that it returns the
|
||||
# expected text
|
||||
url = "http://www.example.com"
|
||||
assert scrape_text(url) == expected_text
|
||||
assert scrape_text(url, config) == expected_text
|
||||
|
||||
def test_invalid_url(self):
|
||||
def test_invalid_url(self, config):
|
||||
"""Tests that an error is raised when an invalid url is provided."""
|
||||
url = "invalidurl.com"
|
||||
pytest.raises(ValueError, scrape_text, url)
|
||||
pytest.raises(ValueError, scrape_text, url, config)
|
||||
|
||||
def test_unreachable_url(self, mocker):
|
||||
def test_unreachable_url(self, mocker, config):
|
||||
"""Test that scrape_text returns an error message when an invalid or unreachable url is provided."""
|
||||
# Mock the requests.get() method to raise an exception
|
||||
mocker.patch(
|
||||
@@ -74,10 +74,10 @@ class TestScrapeText:
|
||||
# Call the function with an invalid URL and assert that it returns an error
|
||||
# message
|
||||
url = "http://thiswebsitedoesnotexist.net/"
|
||||
error_message = scrape_text(url)
|
||||
error_message = scrape_text(url, config)
|
||||
assert "Error:" in error_message
|
||||
|
||||
def test_no_text(self, mocker):
|
||||
def test_no_text(self, mocker, config):
|
||||
"""Test that scrape_text returns an empty string when the html page contains no text to be scraped."""
|
||||
# Mock the requests.get() method to return a response with no text
|
||||
mock_response = mocker.Mock()
|
||||
@@ -87,20 +87,20 @@ class TestScrapeText:
|
||||
|
||||
# Call the function with a valid URL and assert that it returns an empty string
|
||||
url = "http://www.example.com"
|
||||
assert scrape_text(url) == ""
|
||||
assert scrape_text(url, config) == ""
|
||||
|
||||
def test_http_error(self, mocker):
|
||||
def test_http_error(self, mocker, config):
|
||||
"""Test that scrape_text returns an error message when the response status code is an http error (>=400)."""
|
||||
# Mock the requests.get() method to return a response with a 404 status code
|
||||
mocker.patch("requests.Session.get", return_value=mocker.Mock(status_code=404))
|
||||
|
||||
# Call the function with a URL
|
||||
result = scrape_text("https://www.example.com")
|
||||
result = scrape_text("https://www.example.com", config)
|
||||
|
||||
# Check that the function returns an error message
|
||||
assert result == "Error: HTTP 404 error"
|
||||
|
||||
def test_scrape_text_with_html_tags(self, mocker):
|
||||
def test_scrape_text_with_html_tags(self, mocker, config):
|
||||
"""Test that scrape_text() properly handles HTML tags."""
|
||||
# Create a mock response object with HTML containing tags
|
||||
html = "<html><body><p>This is <b>bold</b> text.</p></body></html>"
|
||||
@@ -110,7 +110,7 @@ class TestScrapeText:
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function with a URL
|
||||
result = scrape_text("https://www.example.com")
|
||||
result = scrape_text("https://www.example.com", config)
|
||||
|
||||
# Check that the function properly handles HTML tags
|
||||
assert result == "This is bold text."
|
||||
|
||||
Reference in New Issue
Block a user