mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[scm_mock] Remove unused config parameter.
R=ayatane, yiwzhang Change-Id: I843a967249d9f1f967c94af91f98c3885b319d01 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5763524 Reviewed-by: Yiwei Zhang <yiwzhang@google.com> Reviewed-by: Allen Li <ayatane@chromium.org> Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
This commit is contained in:
19
scm.py
19
scm.py
@@ -444,21 +444,16 @@ class GitConfigStateTest(GitConfigStateBase):
|
||||
global_state_lock: threading.Lock,
|
||||
global_state: dict[str, list[str]],
|
||||
*,
|
||||
system_state: Optional[GitFlatConfigData] = None,
|
||||
local_state: Optional[GitFlatConfigData] = None,
|
||||
worktree_state: Optional[GitFlatConfigData] = None):
|
||||
system_state: Optional[GitFlatConfigData] = None):
|
||||
"""Initializes a new (local, worktree) config state, with a reference to
|
||||
a single global `global` state and an optional immutable `system` state.
|
||||
|
||||
All keys in global_state, system_state, local_state and worktree_state
|
||||
MUST already be canonicalized with canonicalize_key().
|
||||
All keys in global_state and system_state MUST already be canonicalized
|
||||
with canonicalize_key().
|
||||
|
||||
The caller must supply a single shared Lock, plus a mutable reference to
|
||||
the global-state dictionary.
|
||||
|
||||
Optionally, the caller may supply an initial local/worktree
|
||||
configuration state.
|
||||
|
||||
This implementation will hold global_state_lock during all read/write
|
||||
operations on the 'global' scope.
|
||||
"""
|
||||
@@ -468,15 +463,7 @@ class GitConfigStateTest(GitConfigStateBase):
|
||||
self.global_state = global_state
|
||||
|
||||
self.worktree_state: dict[str, list[str]] = {}
|
||||
if worktree_state is not None:
|
||||
self.worktree_state = {
|
||||
k: list(v)
|
||||
for k, v in worktree_state.items()
|
||||
}
|
||||
|
||||
self.local_state: dict[str, list[str]] = {}
|
||||
if local_state is not None:
|
||||
self.local_state = {k: list(v) for k, v in local_state.items()}
|
||||
|
||||
super().__init__()
|
||||
|
||||
|
||||
@@ -18,11 +18,9 @@ import scm
|
||||
|
||||
|
||||
def GIT(test: unittest.TestCase,
|
||||
config: dict[str, list[str]] | None = None,
|
||||
branchref: str | None = None):
|
||||
"""Installs fakes/mocks for scm.GIT so that:
|
||||
|
||||
* Initial git config (local scope) is set to `config`.
|
||||
* GetBranch will just return a fake branchname starting with the value of
|
||||
branchref.
|
||||
* git_new_branch.create_new_branch will be mocked to update the value
|
||||
@@ -31,17 +29,9 @@ def GIT(test: unittest.TestCase,
|
||||
NOTE: The dependency on git_new_branch.create_new_branch seems pretty
|
||||
circular - this functionality should probably move to scm.GIT?
|
||||
"""
|
||||
# TODO - remove `config` - have callers just directly call SetConfig with
|
||||
# whatever config state they need.
|
||||
# TODO - add `system_config` - this will be configuration which exists at
|
||||
# the 'system installation' level and is immutable.
|
||||
|
||||
if config:
|
||||
config = {
|
||||
scm.canonicalize_git_config_key(k): v
|
||||
for k, v in config.items()
|
||||
}
|
||||
|
||||
_branchref = [branchref or 'refs/heads/main']
|
||||
|
||||
global_lock = threading.Lock()
|
||||
@@ -53,7 +43,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, local_state=config)),
|
||||
global_lock, global_state)),
|
||||
mock.patch('scm.GIT.GetBranchRef', side_effect=lambda _: _branchref[0]),
|
||||
mock.patch('git_new_branch.create_new_branch', side_effect=_newBranch)
|
||||
]
|
||||
|
||||
@@ -426,9 +426,7 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
@staticmethod
|
||||
def _make(*,
|
||||
global_state: dict[str, list[str]] | None = None,
|
||||
system_state: dict[str, list[str]] | None = None,
|
||||
local_state: dict[str, list[str]] | None = None,
|
||||
worktree_state: dict[str, list[str]] | None = None):
|
||||
system_state: dict[str, list[str]] | None = None):
|
||||
"""_make constructs a GitConfigStateTest with an internal Lock.
|
||||
|
||||
If global_state is None, an empty dictionary will be constructed and
|
||||
@@ -442,9 +440,7 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
global_state = global_state or {}
|
||||
m = scm.GitConfigStateTest(threading.Lock(),
|
||||
global_state,
|
||||
system_state=system_state,
|
||||
local_state=local_state,
|
||||
worktree_state=worktree_state)
|
||||
system_state=system_state)
|
||||
return m, global_state
|
||||
|
||||
def test_construction_empty(self):
|
||||
@@ -476,39 +472,6 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
self.assertDictEqual(m.load_config(),
|
||||
{'section.key': ['system', 'override']})
|
||||
|
||||
def test_construction_local(self):
|
||||
m, gs = self._make(
|
||||
global_state={'section.key': ['global']},
|
||||
system_state={'section.key': ['system']},
|
||||
local_state={'section.key': ['local']},
|
||||
)
|
||||
self.assertDictEqual(gs, {'section.key': ['global']})
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['system', 'global', 'local'],
|
||||
})
|
||||
|
||||
gs['section.key'] = ['override']
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['system', 'override', 'local'],
|
||||
})
|
||||
|
||||
def test_construction_worktree(self):
|
||||
m, gs = self._make(
|
||||
global_state={'section.key': ['global']},
|
||||
system_state={'section.key': ['system']},
|
||||
local_state={'section.key': ['local']},
|
||||
worktree_state={'section.key': ['worktree']},
|
||||
)
|
||||
self.assertDictEqual(gs, {'section.key': ['global']})
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['system', 'global', 'local', 'worktree'],
|
||||
})
|
||||
|
||||
gs['section.key'] = ['override']
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['system', 'override', 'local', 'worktree'],
|
||||
})
|
||||
|
||||
def test_set_config_system(self):
|
||||
m, _ = self._make()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user