Mocked the aider.scraper.Scraper.scrape method in the test_cmd_web_imports_playwright test.

This commit is contained in:
Paul Gauthier (aider) 2024-07-16 11:14:29 +01:00
parent d41f07b024
commit d5a258356b

View file

@ -1,7 +1,5 @@
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch, MagicMock
import sys
import io
from aider.commands import Commands from aider.commands import Commands
from aider.io import InputOutput from aider.io import InputOutput
@ -12,9 +10,19 @@ class TestScrape(unittest.TestCase):
self.io = InputOutput() self.io = InputOutput()
self.commands = Commands(self.io, None) self.commands = Commands(self.io, None)
def test_cmd_web_imports_playwright(self): @patch('aider.scraper.Scraper.scrape')
def test_cmd_web_imports_playwright(self, mock_scrape):
# Mock the scrape method
mock_scrape.return_value = "Mocked webpage content"
# Run the cmd_web command # Run the cmd_web command
self.commands.cmd_web("https://example.com") result = self.commands.cmd_web("https://example.com")
# Assert that the scrape method was called with the correct URL
mock_scrape.assert_called_once_with("https://example.com")
# Assert that the result contains the mocked content
self.assertIn("Mocked webpage content", result)
# Try to import playwright # Try to import playwright
try: try: