Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions tests/units/reflex_release/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import shutil
import subprocess
from collections.abc import Callable
from pathlib import Path
Expand Down Expand Up @@ -123,33 +124,49 @@ def write_custom_build(repo: Path, extra: str = "", workflow: bool = True) -> No
)


@pytest.fixture
def repo(tmp_path: Path) -> Path:
"""Create a git repository with a root package and one sub-package.
@pytest.fixture(scope="session")
def repo_template(tmp_path_factory: pytest.TempPathFactory) -> Path:
"""Create, once per session, the git repository that ``repo`` copies.

Args:
tmp_path: The pytest temporary directory.
tmp_path_factory: The pytest temporary directory factory.

Returns:
The repository root.
The template repository root.
"""
(tmp_path / "src" / "mypkg").mkdir(parents=True)
(tmp_path / "packages" / "widget-core" / "src").mkdir(parents=True)
(tmp_path / "packages" / "widget-core" / "pyproject.toml").write_text(
root = tmp_path_factory.mktemp("repo-template")
(root / "src" / "mypkg").mkdir(parents=True)
(root / "packages" / "widget-core" / "src").mkdir(parents=True)
(root / "packages" / "widget-core" / "pyproject.toml").write_text(
SUB_PYPROJECT.format(name="widget-core"),
encoding="utf-8",
)
(tmp_path / "pyproject.toml").write_text(
(root / "pyproject.toml").write_text(
ROOT_PYPROJECT + "\n[tool.reflex-release]\n"
'root-package = "mypkg"\n'
'packages-dir = "packages"\n\n' + towncrier_config_toml(tmp_path),
'packages-dir = "packages"\n\n' + towncrier_config_toml(root),
encoding="utf-8",
)
for news in (tmp_path / "news", tmp_path / "packages" / "widget-core" / "news"):
for news in (root / "news", root / "packages" / "widget-core" / "news"):
news.mkdir()
(news / ".gitkeep").touch()
git(tmp_path, "init", "-q", "-b", "main")
commit_all(tmp_path, "init")
git(root, "init", "-q", "-b", "main")
commit_all(root, "init")
return root


@pytest.fixture
def repo(tmp_path: Path, repo_template: Path) -> Path:
"""Create a git repository with a root package and one sub-package.

Args:
tmp_path: The pytest temporary directory.
repo_template: The session's pristine repository to copy.

Returns:
The repository root.
"""
shutil.copytree(repo_template, tmp_path, dirs_exist_ok=True)
return tmp_path


Expand Down