Skip to content

Commit

Permalink
Redesign new decorator to better separate concerns
Browse files Browse the repository at this point in the history
_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.
  • Loading branch information
EliahKagan authored Sep 6, 2023
1 parent 4f594cd commit f6c3262
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@


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

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

with patcher:
Expand Down Expand Up @@ -727,7 +727,7 @@ def test_add_empty_repo(self, rwdir):
# end for each checkout mode

@with_rw_directory
@_allow_file_protocol()
@_patch_git_config("protocol.file.allow", "always")
def test_list_only_valid_submodules(self, rwdir):
repo_path = osp.join(rwdir, "parent")
repo = git.Repo.init(repo_path)
Expand Down Expand Up @@ -756,7 +756,7 @@ def test_list_only_valid_submodules(self, rwdir):
""",
)
@with_rw_directory
@_allow_file_protocol()
@_patch_git_config("protocol.file.allow", "always")
def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
parent = git.Repo.init(osp.join(rwdir, "parent"))
parent.git.submodule("add", self._small_repo_url(), "module")
Expand Down

0 comments on commit f6c3262

Please sign in to comment.