mirror of https://github.com/scrapy/scrapy.git
Extract write_recording_editor().
This commit is contained in:
parent
b3670369b8
commit
49a0d1dca1
|
|
@ -7,14 +7,7 @@ from pathlib import Path
|
|||
import pytest
|
||||
|
||||
from tests.test_commands import TestProjectBase
|
||||
from tests.utils.cmdline import call, proc
|
||||
|
||||
|
||||
def write_recording_editor(editor: Path) -> None:
|
||||
"""Create an executable editor script that writes the path it is asked to
|
||||
open (its last argument) into the file given as its first argument."""
|
||||
editor.write_text('#!/bin/sh\nprintf "%s" "$2" > "$1"\n', encoding="utf-8")
|
||||
editor.chmod(0o755)
|
||||
from tests.utils.cmdline import call, proc, write_recording_editor
|
||||
|
||||
|
||||
def find_in_file(filename: Path, regex: str) -> re.Match[str] | None:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from scrapy.commands import ScrapyCommand, ScrapyHelpFormatter, view
|
|||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.settings import Settings
|
||||
from scrapy.utils.reactor import _asyncio_reactor_path
|
||||
from tests.utils.cmdline import call, proc
|
||||
from tests.utils.cmdline import call, proc, write_recording_editor
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
|
@ -430,9 +430,7 @@ class TestEditCommand(TestProjectBase):
|
|||
spider = proj_path / self.project_name / "spiders" / "example.py"
|
||||
edited = proj_path / "edited.txt"
|
||||
editor = proj_path / "fake-editor.sh"
|
||||
# Records the file it is asked to open ($2) into the file given as $1.
|
||||
editor.write_text('#!/bin/sh\nprintf "%s" "$2" > "$1"\n', encoding="utf-8")
|
||||
editor.chmod(0o755)
|
||||
write_recording_editor(editor)
|
||||
monkeypatch.setenv("EDITOR", f"{editor} {edited}")
|
||||
|
||||
assert call("genspider", "example", "example.com", cwd=proj_path) == 0
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@ from __future__ import annotations
|
|||
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import pytest
|
||||
|
||||
from scrapy.utils.test import get_testenv
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def call(*args: str, **popen_kwargs: Any) -> int:
|
||||
args = (sys.executable, "-m", "scrapy.cmdline", *args)
|
||||
|
|
@ -36,3 +39,10 @@ def proc(*args: str, **popen_kwargs: Any) -> tuple[int, str, str]:
|
|||
pytest.fail("Command took too much time to complete")
|
||||
|
||||
return p.returncode, p.stdout, p.stderr
|
||||
|
||||
|
||||
def write_recording_editor(editor: Path) -> None:
|
||||
"""Create an executable editor script that writes the path it is asked to
|
||||
open (its last argument) into the file given as its first argument."""
|
||||
editor.write_text('#!/bin/sh\nprintf "%s" "$2" > "$1"\n', encoding="utf-8")
|
||||
editor.chmod(0o755)
|
||||
|
|
|
|||
Loading…
Reference in New Issue