68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
|
|
META_ROOT = Path(__file__).resolve().parents[1]
|
|
RELEASE_TOOLS_ROOT = META_ROOT / "tools" / "release"
|
|
|
|
if str(RELEASE_TOOLS_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(RELEASE_TOOLS_ROOT))
|
|
|
|
from govoplan_release import git_state # noqa: E402
|
|
|
|
|
|
class ReleaseGitStateTests(unittest.TestCase):
|
|
def test_manifest_version_does_not_confuse_interface_versions(self) -> None:
|
|
from tempfile import TemporaryDirectory
|
|
|
|
with TemporaryDirectory() as directory:
|
|
root = Path(directory) / "govoplan-example"
|
|
manifest = root / "src" / "govoplan_example" / "backend" / "manifest.py"
|
|
manifest.parent.mkdir(parents=True)
|
|
manifest.write_text(
|
|
"\n".join(
|
|
(
|
|
'MODULE_VERSION = "1.2.3"',
|
|
"manifest = ModuleManifest(",
|
|
' id="example",',
|
|
" version=MODULE_VERSION,",
|
|
" provides_interfaces=(",
|
|
' ModuleInterfaceProvider(name="example.items", version="9.8.7"),',
|
|
" ),",
|
|
")",
|
|
"",
|
|
)
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
versions = git_state.read_manifest_versions(root)
|
|
|
|
self.assertEqual(("1.2.3",), versions)
|
|
|
|
def test_git_trusts_only_the_resolved_repository_for_each_command(self) -> None:
|
|
repository = Path("/workspace/../workspace/govoplan-core")
|
|
completed = subprocess.CompletedProcess([], 0, "", "")
|
|
|
|
with patch.object(git_state.subprocess, "run", return_value=completed) as run:
|
|
result = git_state.git(repository, "status", "--porcelain")
|
|
|
|
self.assertEqual(result.returncode, 0)
|
|
command = run.call_args.args[0]
|
|
self.assertIn(f"safe.directory={repository.resolve()}", command)
|
|
self.assertNotIn("safe.directory=*", command)
|
|
self.assertEqual(run.call_args.kwargs["cwd"], repository)
|
|
self.assertEqual(
|
|
run.call_args.kwargs["env"]["GIT_CONFIG_GLOBAL"],
|
|
"/dev/null",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|