fix: Update test for scrape method with correct mocking

This commit is contained in:
Paul Gauthier (aider) 2024-08-10 06:06:19 -07:00
parent 2cc4ae6e88
commit 6c38766c92

View file

@ -100,7 +100,7 @@ class TestScrape(unittest.TestCase):
# Mock the necessary objects and methods # Mock the necessary objects and methods
scraper.scrape_with_playwright = MagicMock() scraper.scrape_with_playwright = MagicMock()
scraper.scrape_with_playwright.return_value = None scraper.scrape_with_playwright.return_value = (None, None)
# Call the scrape method # Call the scrape method
result = scraper.scrape("https://example.com") result = scraper.scrape("https://example.com")
@ -113,6 +113,19 @@ class TestScrape(unittest.TestCase):
"Failed to retrieve content from https://example.com" "Failed to retrieve content from https://example.com"
) )
# Reset the mock
mock_print_error.reset_mock()
# Test with a different return value
scraper.scrape_with_playwright.return_value = ("Some content", "text/html")
result = scraper.scrape("https://example.com")
# Assert that the result is not None
self.assertIsNotNone(result)
# Assert that print_error was not called
mock_print_error.assert_not_called()
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()