Skip to content

Commit f6c3262

Browse files
authored
Redesign new decorator to better separate concerns
_allow_file_protocol was effectively a _patch_git_config fixture, being no no shorter, simpler, or clearer by hard-coding the specific name and value to patch. So this changes it to be that. As a secondary issue, it previously was called with no arguments, then that would be used as a decorator. That was unintutive and it was easy to omit the parentheses accidentally. This resolves that.
1 parent 4f594cd commit f6c3262

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: test/test_submodule.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333

3434

3535
@contextlib.contextmanager
36-
def _allow_file_protocol():
37-
"""Temporarily set protocol.file.allow to always, using environment variables."""
36+
def _patch_git_config(name, value):
37+
"""Temporarily add a git config name-value pair, using environment variables."""
3838
pair_index = int(os.getenv("GIT_CONFIG_COUNT", "0"))
3939

4040
# This is recomputed each time the context is entered, for compatibility with
4141
# existing GIT_CONFIG_* environment variables, even if changed in this process.
4242
patcher = mock.patch.dict(os.environ, {
4343
"GIT_CONFIG_COUNT": str(pair_index + 1),
44-
f"GIT_CONFIG_KEY_{pair_index}": "protocol.file.allow",
45-
f"GIT_CONFIG_VALUE_{pair_index}": "always",
44+
f"GIT_CONFIG_KEY_{pair_index}": name,
45+
f"GIT_CONFIG_VALUE_{pair_index}": value,
4646
})
4747

4848
with patcher:
@@ -727,7 +727,7 @@ def test_add_empty_repo(self, rwdir):
727727
# end for each checkout mode
728728

729729
@with_rw_directory
730-
@_allow_file_protocol()
730+
@_patch_git_config("protocol.file.allow", "always")
731731
def test_list_only_valid_submodules(self, rwdir):
732732
repo_path = osp.join(rwdir, "parent")
733733
repo = git.Repo.init(repo_path)
@@ -756,7 +756,7 @@ def test_list_only_valid_submodules(self, rwdir):
756756
""",
757757
)
758758
@with_rw_directory
759-
@_allow_file_protocol()
759+
@_patch_git_config("protocol.file.allow", "always")
760760
def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
761761
parent = git.Repo.init(osp.join(rwdir, "parent"))
762762
parent.git.submodule("add", self._small_repo_url(), "module")

0 commit comments

Comments
 (0)