Skip to content

Test/refactor repo builders #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
2c11c47
test(fixtures): refactor repo build helpers for construction steps
codejedi365 Nov 24, 2024
75eba2c
test(fixtures): refactor github flow default release repo for constru…
codejedi365 Nov 24, 2024
dd72856
test(fixtures): refactor github flow feature release repo for constru…
codejedi365 Nov 24, 2024
40082ac
test(fixtures): refactor initial commit repo for construction steps
codejedi365 Nov 24, 2024
06b60a5
test(fixtures): refactor trunk-only unreleased repo for construction …
codejedi365 Nov 24, 2024
3718546
test(fixtures): refactor trunk-only repo w/ tags for construction steps
codejedi365 Nov 24, 2024
23ad268
test(fixtures): refactor trunk-only repo w/ prereleases for construct…
codejedi365 Nov 24, 2024
d49fe8a
test(fixtures): add git fast forward merge action to repo builder
codejedi365 Nov 24, 2024
d41f082
test(fixtures): refactor gitflow repo w/ 2 release channels for const…
codejedi365 Nov 24, 2024
ca994d4
test(fixtures): refactor gitflow repo w/ 3 release channels for const…
codejedi365 Nov 24, 2024
2740257
test(fixtures): add a gitflow repo w/ 4 release channels
codejedi365 Nov 24, 2024
d31b1af
test(fixtures): add a gitflow repo w/ a single release channel
codejedi365 Nov 24, 2024
23882d1
test(e2e): refactor test cases to match repo construction step implem…
codejedi365 Nov 29, 2024
56e3bc8
test(release-history): refactor unit tests to handle repo constructio…
codejedi365 Nov 29, 2024
e236238
build(deps-test): add `flatdict@4` to easily read `pyproject.toml` se…
codejedi365 Nov 29, 2024
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ docs = [
test = [
"coverage[toml] ~= 7.0",
"filelock ~= 3.15",
"flatdict ~= 4.0",
"freezegun ~= 1.5",
"pyyaml ~= 6.0",
"pytest ~= 8.3",
Expand Down
23 changes: 17 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import json
import os
import sys
from datetime import datetime, timedelta, timezone
Expand All @@ -21,10 +22,12 @@

if TYPE_CHECKING:
from tempfile import _TemporaryFileWrapper
from typing import Callable, Generator, Protocol, Sequence, TypedDict
from typing import Any, Callable, Generator, Protocol, Sequence, TypedDict

from filelock import AcquireReturnProxy

from tests.fixtures.git_repo import RepoActions

class MakeCommitObjFn(Protocol):
def __call__(self, message: str) -> Commit: ...

Expand Down Expand Up @@ -62,13 +65,14 @@ def __call__(
self,
repo_name: str,
build_spec_hash: str,
build_repo_func: Callable[[Path], None],
build_repo_func: Callable[[Path], Sequence[RepoActions]],
dest_dir: Path | None = None,
) -> Path: ...

class RepoData(TypedDict):
build_date: str
build_spec_hash: str
build_definition: Sequence[RepoActions]

class GetCachedRepoDataFn(Protocol):
def __call__(self, proj_dirname: str) -> RepoData | None: ...
Expand Down Expand Up @@ -281,9 +285,17 @@ def _get_cached_repo_data(proj_dirname: str) -> RepoData | None:

@pytest.fixture(scope="session")
def set_cached_repo_data(request: pytest.FixtureRequest) -> SetCachedRepoDataFn:
def magic_serializer(obj: Any) -> Any:
if isinstance(obj, Path):
return obj.__fspath__()
return obj

def _set_cached_repo_data(proj_dirname: str, data: RepoData) -> None:
cache_key = f"psr/repos/{proj_dirname}"
request.config.cache.set(cache_key, data)
request.config.cache.set(
cache_key,
json.loads(json.dumps(data, default=magic_serializer)),
)

return _set_cached_repo_data

Expand All @@ -303,7 +315,7 @@ def build_repo_or_copy_cache(
def _build_repo_w_cache_checking(
repo_name: str,
build_spec_hash: str,
build_repo_func: Callable[[Path], None],
build_repo_func: Callable[[Path], Sequence[RepoActions]],
dest_dir: Path | None = None,
) -> Path:
# Blocking mechanism to synchronize xdist workers
Expand All @@ -327,14 +339,13 @@ def _build_repo_w_cache_checking(
with log_file_lock, log_file.open(mode="a") as afd:
afd.write(f"{stable_now_date().isoformat()}: {build_msg}...\n")

build_repo_func(cached_repo_path)

# Marks the date when the cached repo was created
set_cached_repo_data(
repo_name,
{
"build_date": today_date_str,
"build_spec_hash": build_spec_hash,
"build_definition": build_repo_func(cached_repo_path),
},
)

Expand Down
14 changes: 14 additions & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from pathlib import Path

import git
Expand All @@ -7,6 +8,19 @@

PROJ_DIR = Path(__file__).parent.parent.absolute().resolve()


class RepoActionStep(str, Enum):
CONFIGURE = "CONFIGURE"
WRITE_CHANGELOGS = "WRITE_CHANGELOGS"
GIT_CHECKOUT = "GIT_CHECKOUT"
GIT_COMMIT = "GIT_COMMIT"
GIT_MERGE = "GIT_MERGE"
GIT_SQUASH = "GIT_SQUASH"
GIT_TAG = "GIT_TAG"
RELEASE = "RELEASE"
MAKE_COMMITS = "MAKE_COMMITS"


A_FULL_VERSION_STRING = "1.11.567"
A_PRERELEASE_VERSION_STRING = "2.3.4-dev.23"
A_FULL_VERSION_STRING_WITH_BUILD_METADATA = "4.2.3+build.12345"
Expand Down
Loading
Loading