mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 13:25:00 +00:00
Added a test for the cmd_web command to ensure that playwright can be imported after running the command.
This commit is contained in:
parent
b18dbf4772
commit
3e7663e914
1 changed files with 46 additions and 0 deletions
46
tests/scrape/test_scrape.py
Normal file
46
tests/scrape/test_scrape.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
|
from aider.commands import Commands
|
||||||
|
|
||||||
|
|
||||||
|
class TestScrape(unittest.TestCase):
|
||||||
|
@patch("aider.commands.install_playwright")
|
||||||
|
@patch("aider.commands.Scraper")
|
||||||
|
def test_cmd_web_imports_playwright(self, mock_scraper, mock_install_playwright):
|
||||||
|
# Mock the necessary objects and methods
|
||||||
|
mock_io = MagicMock()
|
||||||
|
mock_coder = MagicMock()
|
||||||
|
mock_install_playwright.return_value = True
|
||||||
|
mock_scraper_instance = MagicMock()
|
||||||
|
mock_scraper.return_value = mock_scraper_instance
|
||||||
|
mock_scraper_instance.scrape.return_value = "Mocked content"
|
||||||
|
|
||||||
|
# Create a Commands instance
|
||||||
|
commands = Commands(mock_io, mock_coder)
|
||||||
|
|
||||||
|
# Run the cmd_web command
|
||||||
|
commands.cmd_web("https://example.com")
|
||||||
|
|
||||||
|
# Check that install_playwright was called
|
||||||
|
mock_install_playwright.assert_called_once()
|
||||||
|
|
||||||
|
# Check that Scraper was instantiated
|
||||||
|
mock_scraper.assert_called_once()
|
||||||
|
|
||||||
|
# Try to import playwright
|
||||||
|
try:
|
||||||
|
import playwright # noqa: F401
|
||||||
|
playwright_imported = True
|
||||||
|
except ImportError:
|
||||||
|
playwright_imported = False
|
||||||
|
|
||||||
|
# Assert that playwright was successfully imported
|
||||||
|
self.assertTrue(
|
||||||
|
playwright_imported,
|
||||||
|
"Playwright should be importable after running cmd_web command"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue