mirror of https://github.com/scrapy/scrapy.git
Move TestProjectBase to utils.
This commit is contained in:
parent
49a0d1dca1
commit
ac751a57a3
|
|
@ -7,7 +7,7 @@ from unittest import TestCase
|
|||
from unittest.mock import MagicMock, Mock, PropertyMock, call, patch
|
||||
|
||||
from scrapy.commands.check import Command, TextTestResult
|
||||
from tests.test_commands import TestProjectBase
|
||||
from tests.utils.base_commands import TestProjectBase
|
||||
from tests.utils.cmdline import proc
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from tests.test_commands import TestProjectBase
|
||||
from tests.utils.base_commands import TestProjectBase
|
||||
from tests.utils.cmdline import proc
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from tests.test_commands import TestProjectBase
|
||||
from tests.utils.base_commands import TestProjectBase
|
||||
from tests.utils.cmdline import call, proc, write_recording_editor
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import pytest
|
|||
|
||||
from scrapy.commands import parse
|
||||
from scrapy.settings import Settings
|
||||
from tests.test_commands import TestProjectBase
|
||||
from tests.utils.base_commands import TestProjectBase
|
||||
from tests.utils.cmdline import call, proc
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import argparse
|
|||
import json
|
||||
import sys
|
||||
from io import StringIO
|
||||
from shutil import copytree
|
||||
from typing import TYPE_CHECKING
|
||||
from unittest import mock
|
||||
|
||||
|
|
@ -16,6 +15,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.base_commands import TestProjectBase
|
||||
from tests.utils.cmdline import call, proc, write_recording_editor
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -109,29 +109,6 @@ class TestCommandSettings:
|
|||
)
|
||||
|
||||
|
||||
class TestProjectBase:
|
||||
"""A base class for tests that may need a Scrapy project."""
|
||||
|
||||
project_name = "testproject"
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def _proj_path_cached(self, tmp_path_factory: pytest.TempPathFactory) -> Path:
|
||||
"""Create a Scrapy project in a temporary directory and return its path.
|
||||
|
||||
Used as a cache for ``proj_path``.
|
||||
"""
|
||||
tmp_path = tmp_path_factory.mktemp("proj")
|
||||
call("startproject", self.project_name, cwd=tmp_path)
|
||||
return tmp_path / self.project_name
|
||||
|
||||
@pytest.fixture
|
||||
def proj_path(self, tmp_path: Path, _proj_path_cached: Path) -> Path:
|
||||
"""Copy a pre-generated Scrapy project into a temporary directory and return its path."""
|
||||
proj_path = tmp_path / self.project_name
|
||||
copytree(_proj_path_cached, proj_path)
|
||||
return proj_path
|
||||
|
||||
|
||||
class TestCommandCrawlerProcess(TestProjectBase):
|
||||
"""Test that the command uses the expected kind of *CrawlerProcess
|
||||
and produces expected errors when needed."""
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from shutil import copytree
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.utils.cmdline import call
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class TestProjectBase:
|
||||
"""A base class for tests that may need a Scrapy project."""
|
||||
|
||||
project_name = "testproject"
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def _proj_path_cached(self, tmp_path_factory: pytest.TempPathFactory) -> Path:
|
||||
"""Create a Scrapy project in a temporary directory and return its path.
|
||||
|
||||
Used as a cache for ``proj_path``.
|
||||
"""
|
||||
tmp_path = tmp_path_factory.mktemp("proj")
|
||||
call("startproject", self.project_name, cwd=tmp_path)
|
||||
return tmp_path / self.project_name
|
||||
|
||||
@pytest.fixture
|
||||
def proj_path(self, tmp_path: Path, _proj_path_cached: Path) -> Path:
|
||||
"""Copy a pre-generated Scrapy project into a temporary directory and return its path."""
|
||||
proj_path = tmp_path / self.project_name
|
||||
copytree(_proj_path_cached, proj_path)
|
||||
return proj_path
|
||||
Loading…
Reference in New Issue