[scm_mock] Expose mocking of system config layer.

R=ayatane, yiwzhang

Change-Id: I15a48c6af54d2b047b085abc729d2849759816d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5762792
Reviewed-by: Allen Li <ayatane@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
changes/92/5762792/6
Robert Iannucci 7 months ago committed by LUCI CQ
parent 5f4fb8c8fb
commit 7762989876

@ -18,9 +18,12 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import scm
def GIT(test: unittest.TestCase,
*,
branchref: str | None = None) -> Iterable[tuple[str, list[str]]]:
def GIT(
test: unittest.TestCase,
*,
branchref: str | None = None,
system_config: dict[str, list[str]] | None = None
) -> Iterable[tuple[str, list[str]]]:
"""Installs fakes/mocks for scm.GIT so that:
* GetBranch will just return a fake branchname starting with the value of
@ -28,12 +31,13 @@ def GIT(test: unittest.TestCase,
* git_new_branch.create_new_branch will be mocked to update the value
returned by GetBranch.
If provided, `system_config` allows you to set the 'system' scoped
git-config which will be visible as the immutable base configuration layer
for all git config scopes.
NOTE: The dependency on git_new_branch.create_new_branch seems pretty
circular - this functionality should probably move to scm.GIT?
"""
# TODO - add `system_config` - this will be configuration which exists at
# the 'system installation' level and is immutable.
_branchref = [branchref or 'refs/heads/main']
global_lock = threading.Lock()
@ -45,7 +49,7 @@ def GIT(test: unittest.TestCase,
patches: list[mock._patch] = [
mock.patch('scm.GIT._new_config_state',
side_effect=lambda _: scm.GitConfigStateTest(
global_lock, global_state)),
global_lock, global_state, system_state=system_config)),
mock.patch('scm.GIT.GetBranchRef', side_effect=lambda _: _branchref[0]),
mock.patch('git_new_branch.create_new_branch', side_effect=_newBranch)
]

Loading…
Cancel
Save