From 5bf9dbb226cc8d80c10e5461a27d1142c9cf4f50 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 28 Jul 2024 16:49:32 -0300 Subject: [PATCH] Fix test for self-signed url scrape --- tests/scrape/test_scrape.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/scrape/test_scrape.py b/tests/scrape/test_scrape.py index d3bde4805..c5c1fda83 100644 --- a/tests/scrape/test_scrape.py +++ b/tests/scrape/test_scrape.py @@ -1,6 +1,5 @@ import unittest from unittest.mock import MagicMock -import re from aider.commands import Commands from aider.io import InputOutput @@ -10,17 +9,22 @@ from aider.scrape import Scraper class TestScrape(unittest.TestCase): def test_scrape_self_signed_ssl(self): # Test with SSL verification - scraper_verify = Scraper(print_error=MagicMock(), playwright_available=True, verify_ssl=True) + scraper_verify = Scraper( + print_error=MagicMock(), playwright_available=True, verify_ssl=True + ) result_verify = scraper_verify.scrape("https://self-signed.badssl.com") self.assertIsNone(result_verify) scraper_verify.print_error.assert_called() # Test without SSL verification - scraper_no_verify = Scraper(print_error=MagicMock(), playwright_available=True, verify_ssl=False) + scraper_no_verify = Scraper( + print_error=MagicMock(), playwright_available=True, verify_ssl=False + ) result_no_verify = scraper_no_verify.scrape("https://self-signed.badssl.com") self.assertIsNotNone(result_no_verify) - self.assertIn("self-signed.badssl.com", result_no_verify) + self.assertIn("self-signed", result_no_verify) scraper_no_verify.print_error.assert_not_called() + def setUp(self): self.io = InputOutput(yes=True) self.commands = Commands(self.io, None) @@ -88,15 +92,16 @@ class TestScrape(unittest.TestCase): # 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") @@ -104,7 +109,9 @@ class TestScrape(unittest.TestCase): 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") + mock_print_error.assert_called_once_with( + "Failed to retrieve content from https://example.com" + ) if __name__ == "__main__":