Repository-wide mechanical cleanup so `ruff check src tests` has a chance of passing; no behavioural changes. - Add `from __future__ import annotations` where PEP 604 unions are used. This has to come first: pyproject declares requires-python >= 3.9, where `X | None` is not evaluable at runtime unless annotations are stringified. - Replace typing.List/Dict/Tuple/Set with the builtin generics and Optional[X] with X | None, then drop the imports that became unused. The four actions/*/__init__.py files needed this by hand because ruff leaves unused imports in __init__.py alone (possible re-exports). - Strip shebangs from 72 importable modules. None of them are executable or invoked directly; the entry points are console_scripts and runpy. - Flatten nested `with` blocks, collapse needless-bool returns, and apply the remaining mechanical ruff fixes (PIE810, FLY002, PERF102, FURB192, RUF059, I001). - Pass check=False explicitly to the four subprocess.run() calls that inspect returncode themselves. That is the existing default. Two rewrites are visible to mocks, so their tests move with them: subprocess.run(stdout=PIPE, stderr=PIPE) became capture_output=True, and open(path, "r", ...) lost the redundant mode. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from pkgmgr.actions.mirror.context import build_context
|
|
|
|
|
|
class TestMirrorContext(unittest.TestCase):
|
|
"""
|
|
Unit tests for building RepoMirrorContext from repo + filesystem.
|
|
"""
|
|
|
|
@patch("pkgmgr.actions.mirror.context.read_mirrors_file")
|
|
@patch("pkgmgr.actions.mirror.context.load_config_mirrors")
|
|
@patch("pkgmgr.actions.mirror.context.get_repo_dir")
|
|
@patch("pkgmgr.actions.mirror.context.get_repo_identifier")
|
|
def test_build_context_bundles_config_and_file_mirrors(
|
|
self,
|
|
mock_identifier,
|
|
mock_repo_dir,
|
|
mock_load_config,
|
|
mock_read_file,
|
|
) -> None:
|
|
mock_identifier.return_value = "id"
|
|
mock_repo_dir.return_value = "/tmp/repo"
|
|
mock_load_config.return_value = {"origin": "git@github.com:alice/repo.git"}
|
|
mock_read_file.return_value = {"backup": "ssh://git@backup/alice/repo.git"}
|
|
|
|
repo = {"provider": "github.com", "account": "alice", "repository": "repo"}
|
|
|
|
ctx = build_context(repo, repositories_base_dir="/base", all_repos=[repo])
|
|
|
|
self.assertEqual(ctx.identifier, "id")
|
|
self.assertEqual(ctx.repo_dir, "/tmp/repo")
|
|
self.assertEqual(
|
|
ctx.config_mirrors, {"origin": "git@github.com:alice/repo.git"}
|
|
)
|
|
self.assertEqual(
|
|
ctx.file_mirrors, {"backup": "ssh://git@backup/alice/repo.git"}
|
|
)
|
|
self.assertEqual(
|
|
ctx.resolved_mirrors,
|
|
{
|
|
"origin": "git@github.com:alice/repo.git",
|
|
"backup": "ssh://git@backup/alice/repo.git",
|
|
},
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|