|
4 | 4 | #
|
5 | 5 | # This module is part of GitPython and is released under
|
6 | 6 | # the BSD License: https://opensource.org/license/bsd-3-clause/
|
| 7 | +import contextlib |
7 | 8 | import os
|
| 9 | +import os.path as osp |
8 | 10 | import shutil
|
9 | 11 | import subprocess
|
10 | 12 | import sys
|
11 | 13 | from tempfile import TemporaryDirectory, TemporaryFile
|
12 | 14 | from unittest import mock, skipUnless
|
13 | 15 |
|
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 |
20 | 17 |
|
| 18 | +from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd |
21 | 19 | 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 |
22 | 22 |
|
23 | 23 |
|
| 24 | +@ddt.ddt |
24 | 25 | class TestGit(TestBase):
|
25 | 26 | @classmethod
|
26 | 27 | def setUpClass(cls):
|
@@ -73,6 +74,28 @@ def test_it_transforms_kwargs_into_git_command_arguments(self):
|
73 | 74 | res = self.git.transform_kwargs(**{"s": True, "t": True})
|
74 | 75 | self.assertEqual({"-s", "-t"}, set(res))
|
75 | 76 |
|
| 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 | + |
76 | 99 | def test_it_executes_git_and_returns_result(self):
|
77 | 100 | self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$")
|
78 | 101 |
|
|
0 commit comments