mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fixing tests to fit latest merges into master
This commit is contained in:
@@ -25,3 +25,5 @@ black
|
||||
sourcery
|
||||
isort
|
||||
gitpython==3.1.31
|
||||
pytest
|
||||
pytest-mock
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from autogpt.memory.local import LocalCache
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from autogpt.file_operations import delete_file, read_file
|
||||
from autogpt.commands.file_operations import delete_file, read_file
|
||||
|
||||
env_vars = {"MEMORY_BACKEND": "no_memory", "TEMPERATURE": "0"}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# pip install pytest-mock
|
||||
import pytest
|
||||
|
||||
from scripts.browse import scrape_links
|
||||
from autogpt.commands.web_requests import scrape_links
|
||||
|
||||
"""
|
||||
Code Analysis
|
||||
@@ -55,7 +55,7 @@ class TestScrapeLinks:
|
||||
mock_response.text = (
|
||||
"<html><body><a href='https://www.google.com'>Google</a></body></html>"
|
||||
)
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function with a valid URL
|
||||
result = scrape_links("https://www.example.com")
|
||||
@@ -68,7 +68,7 @@ class TestScrapeLinks:
|
||||
# Mock the requests.get() function to return an HTTP error response
|
||||
mock_response = mocker.Mock()
|
||||
mock_response.status_code = 404
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function with an invalid URL
|
||||
result = scrape_links("https://www.invalidurl.com")
|
||||
@@ -82,7 +82,7 @@ class TestScrapeLinks:
|
||||
mock_response = mocker.Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.text = "<html><body><p>No hyperlinks here</p></body></html>"
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function with a URL containing no hyperlinks
|
||||
result = scrape_links("https://www.example.com")
|
||||
@@ -105,7 +105,7 @@ class TestScrapeLinks:
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function being tested
|
||||
result = scrape_links("https://www.example.com")
|
||||
|
||||
@@ -41,7 +41,7 @@ class TestScrapeText:
|
||||
mock_response = mocker.Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.text = f"<html><body><div><p style='color: blue;'>{expected_text}</p></div></body></html>"
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function with a valid URL and assert that it returns the expected text
|
||||
url = "http://www.example.com"
|
||||
@@ -50,7 +50,7 @@ class TestScrapeText:
|
||||
# Tests that the function returns an error message when an invalid or unreachable url is provided.
|
||||
def test_invalid_url(self, mocker):
|
||||
# Mock the requests.get() method to raise an exception
|
||||
mocker.patch("requests.get", side_effect=requests.exceptions.RequestException)
|
||||
mocker.patch("requests.Session.get", side_effect=requests.exceptions.RequestException)
|
||||
|
||||
# Call the function with an invalid URL and assert that it returns an error message
|
||||
url = "http://www.invalidurl.com"
|
||||
@@ -63,7 +63,7 @@ class TestScrapeText:
|
||||
mock_response = mocker.Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.text = "<html><body></body></html>"
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function with a valid URL and assert that it returns an empty string
|
||||
url = "http://www.example.com"
|
||||
@@ -72,7 +72,7 @@ class TestScrapeText:
|
||||
# Tests that the function returns an error message when the response status code is an http error (>=400).
|
||||
def test_http_error(self, mocker):
|
||||
# Mock the requests.get() method to return a response with a 404 status code
|
||||
mocker.patch("requests.get", return_value=mocker.Mock(status_code=404))
|
||||
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")
|
||||
@@ -87,7 +87,7 @@ class TestScrapeText:
|
||||
mock_response = mocker.Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.text = html
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
mocker.patch("requests.Session.get", return_value=mock_response)
|
||||
|
||||
# Call the function with a URL
|
||||
result = scrape_text("https://www.example.com")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import autogpt.agent.agent_manager as agent_manager
|
||||
from autogpt.app import start_agent, list_agents
|
||||
from autogpt.app import start_agent, list_agents, execute_command
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
|
||||
Reference in New Issue
Block a user