From 776298987617eb544c5ef03bc8e67c7f2d0fdcbc Mon Sep 17 00:00:00 2001 From: Robert Iannucci Date: Fri, 9 Aug 2024 20:23:54 +0000 Subject: [PATCH] [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 Commit-Queue: Robbie Iannucci Reviewed-by: Yiwei Zhang --- tests/scm_mock.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/scm_mock.py b/tests/scm_mock.py index 36ec9dd61..4ae712ffc 100644 --- a/tests/scm_mock.py +++ b/tests/scm_mock.py @@ -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) ]