Skip to content

Commit f8cb3c3

Browse files
committed
Add even more tests
1 parent f6dd74a commit f8cb3c3

File tree

2 files changed

+300
-42
lines changed

2 files changed

+300
-42
lines changed

tests/integration_python/conftest.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import os
33
import shutil
4+
import subprocess
5+
from dataclasses import dataclass
46
from pathlib import Path
57
from typing import Any, cast
68

@@ -334,3 +336,81 @@ def multiple_versions_channel_1(channels: Path) -> str:
334336
@pytest.fixture
335337
def target_specific_channel_1(channels: Path) -> str:
336338
return channels.joinpath("target_specific_channel_1").as_uri()
339+
340+
341+
@dataclass
342+
class LocalGitRepo:
343+
path: Path
344+
main_rev: str
345+
other_feature_rev: str
346+
tag: str
347+
348+
349+
@pytest.fixture
350+
def local_cpp_git_repo(
351+
pixi: Path,
352+
build_data: Path,
353+
tmp_path_factory: pytest.TempPathFactory,
354+
) -> LocalGitRepo:
355+
"""
356+
Create a local git repository mirroring cpp-with-path-to-source so tests can
357+
exercise git sources without touching the network.
358+
"""
359+
360+
source_root = build_data.joinpath("cpp-with-path-to-source")
361+
repo_root = tmp_path_factory.mktemp("git-repo")
362+
repo_path = repo_root.joinpath("repo")
363+
shutil.copytree(source_root, repo_path)
364+
365+
marker = repo_path.joinpath("project", "LOCAL_MARKER.txt")
366+
marker.write_text("local git fixture marker\n", encoding="utf-8")
367+
368+
readme_path = repo_path.joinpath("README.md")
369+
370+
def run_git(*args: str) -> str:
371+
result = subprocess.run(
372+
[str(pixi), "run", "git", *args],
373+
cwd=repo_path,
374+
capture_output=True,
375+
text=True,
376+
)
377+
if result.returncode != 0:
378+
raise RuntimeError(
379+
"git command failed ({}):\nstdout: {}\nstderr: {}".format(
380+
" ".join(args), result.stdout, result.stderr
381+
)
382+
)
383+
return result.stdout.strip()
384+
385+
run_git("init", "-b", "main")
386+
run_git("config", "user.email", "[email protected]")
387+
run_git("config", "user.name", "Pixi Build Tests")
388+
run_git("add", ".")
389+
run_git("commit", "-m", "Initial commit")
390+
391+
run_git("checkout", "-b", "other-feature")
392+
readme_path.write_text(
393+
readme_path.read_text(encoding="utf-8") + "\nLocal change on other-feature branch\n",
394+
encoding="utf-8",
395+
)
396+
run_git("add", readme_path.relative_to(repo_path).as_posix())
397+
run_git("commit", "-m", "Add branch change")
398+
other_feature_rev = run_git("rev-parse", "HEAD")
399+
400+
run_git("checkout", "main")
401+
readme_path.write_text(
402+
readme_path.read_text(encoding="utf-8") + "\nLocal change on main\n",
403+
encoding="utf-8",
404+
)
405+
run_git("add", readme_path.relative_to(repo_path).as_posix())
406+
run_git("commit", "-m", "Update main")
407+
main_rev = run_git("rev-parse", "HEAD")
408+
409+
run_git("tag", "fixture-v1")
410+
411+
return LocalGitRepo(
412+
path=repo_path,
413+
main_rev=main_rev,
414+
other_feature_rev=other_feature_rev,
415+
tag="fixture-v1",
416+
)

0 commit comments

Comments
 (0)