Skip to content

Commit 5944060

Browse files
committed
Test whether a shell is used
In the Popen calls in Git.execute, for all combinations of allowed values for Git.USE_SHELL and the shell= keyword argument.
1 parent 5e71c27 commit 5944060

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

test/test_git.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44
#
55
# This module is part of GitPython and is released under
66
# the BSD License: https://opensource.org/license/bsd-3-clause/
7+
import contextlib
78
import os
9+
import os.path as osp
810
import shutil
911
import subprocess
1012
import sys
1113
from tempfile import TemporaryDirectory, TemporaryFile
1214
from unittest import mock, skipUnless
1315

14-
from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd
15-
from test.lib import TestBase, fixture_path
16-
from test.lib import with_rw_directory
17-
from git.util import cwd, finalize_process
18-
19-
import os.path as osp
16+
import ddt
2017

18+
from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd
2119
from git.compat import is_win
20+
from git.util import cwd, finalize_process
21+
from test.lib import TestBase, fixture_path, with_rw_directory
2222

2323

24+
@ddt.ddt
2425
class TestGit(TestBase):
2526
@classmethod
2627
def setUpClass(cls):
@@ -73,6 +74,28 @@ def test_it_transforms_kwargs_into_git_command_arguments(self):
7374
res = self.git.transform_kwargs(**{"s": True, "t": True})
7475
self.assertEqual({"-s", "-t"}, set(res))
7576

77+
@ddt.data(
78+
(None, False, False),
79+
(None, True, True),
80+
(False, True, False),
81+
(False, False, False),
82+
(True, False, True),
83+
(True, True, True),
84+
)
85+
@mock.patch.object(cmd, "Popen", wraps=cmd.Popen) # Since it is gotten via a "from" import.
86+
def test_it_uses_shell_or_not_as_specified(self, case, mock_popen):
87+
"""A bool passed as ``shell=`` takes precedence over `Git.USE_SHELL`."""
88+
value_in_call, value_from_class, expected_popen_arg = case
89+
# FIXME: Check what gets logged too!
90+
with mock.patch.object(Git, "USE_SHELL", value_from_class):
91+
with contextlib.suppress(GitCommandError):
92+
self.git.execute(
93+
"git", # No args, so it runs with or without a shell, on all OSes.
94+
shell=value_in_call,
95+
)
96+
mock_popen.assert_called_once()
97+
self.assertIs(mock_popen.call_args.kwargs["shell"], expected_popen_arg)
98+
7699
def test_it_executes_git_and_returns_result(self):
77100
self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$")
78101

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy