mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00
Added a test case for error handling in the scrape_with_playwright
method.
This commit is contained in:
parent
5dc3bbb6fb
commit
b9d6fd16fc
1 changed files with 25 additions and 0 deletions
|
@ -68,6 +68,31 @@ class TestScrape(unittest.TestCase):
|
||||||
# Assert that print_error was never called
|
# Assert that print_error was never called
|
||||||
mock_print_error.assert_not_called()
|
mock_print_error.assert_not_called()
|
||||||
|
|
||||||
|
def test_scrape_with_playwright_error_handling(self):
|
||||||
|
# Create a Scraper instance with a mock print_error function
|
||||||
|
mock_print_error = MagicMock()
|
||||||
|
scraper = Scraper(print_error=mock_print_error, playwright_available=True)
|
||||||
|
|
||||||
|
# Mock the playwright module to raise an error
|
||||||
|
import playwright
|
||||||
|
playwright._impl._errors.Error = Exception # Mock the Error class
|
||||||
|
|
||||||
|
def mock_content():
|
||||||
|
raise playwright._impl._errors.Error("Test error")
|
||||||
|
|
||||||
|
# Mock the necessary objects and methods
|
||||||
|
scraper.scrape_with_playwright = MagicMock()
|
||||||
|
scraper.scrape_with_playwright.return_value = None
|
||||||
|
|
||||||
|
# Call the scrape method
|
||||||
|
result = scraper.scrape("https://example.com")
|
||||||
|
|
||||||
|
# Assert that the result is None
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
# Assert that print_error was called with the expected error message
|
||||||
|
mock_print_error.assert_called_once_with("Failed to retrieve content from https://example.com")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue