mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[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>
This commit is contained in:
@@ -18,9 +18,12 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||||||
import scm
|
import scm
|
||||||
|
|
||||||
|
|
||||||
def GIT(test: unittest.TestCase,
|
def GIT(
|
||||||
*,
|
test: unittest.TestCase,
|
||||||
branchref: str | None = None) -> Iterable[tuple[str, list[str]]]:
|
*,
|
||||||
|
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:
|
"""Installs fakes/mocks for scm.GIT so that:
|
||||||
|
|
||||||
* GetBranch will just return a fake branchname starting with the value of
|
* 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
|
* git_new_branch.create_new_branch will be mocked to update the value
|
||||||
returned by GetBranch.
|
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
|
NOTE: The dependency on git_new_branch.create_new_branch seems pretty
|
||||||
circular - this functionality should probably move to scm.GIT?
|
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']
|
_branchref = [branchref or 'refs/heads/main']
|
||||||
|
|
||||||
global_lock = threading.Lock()
|
global_lock = threading.Lock()
|
||||||
@@ -45,7 +49,7 @@ def GIT(test: unittest.TestCase,
|
|||||||
patches: list[mock._patch] = [
|
patches: list[mock._patch] = [
|
||||||
mock.patch('scm.GIT._new_config_state',
|
mock.patch('scm.GIT._new_config_state',
|
||||||
side_effect=lambda _: scm.GitConfigStateTest(
|
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('scm.GIT.GetBranchRef', side_effect=lambda _: _branchref[0]),
|
||||||
mock.patch('git_new_branch.create_new_branch', side_effect=_newBranch)
|
mock.patch('git_new_branch.create_new_branch', side_effect=_newBranch)
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user