Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5944060

Browse files
committed
Test whether a shell is used
In the Popen calls in Git.execute, for all combinations of allowedvalues for Git.USE_SHELL and the shell= keyword argument.
1 parent5e71c27 commit5944060

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+
importcontextlib
78
importos
9+
importos.pathasosp
810
importshutil
911
importsubprocess
1012
importsys
1113
fromtempfileimportTemporaryDirectory,TemporaryFile
1214
fromunittestimportmock,skipUnless
1315

14-
fromgitimportGit,refresh,GitCommandError,GitCommandNotFound,Repo,cmd
15-
fromtest.libimportTestBase,fixture_path
16-
fromtest.libimportwith_rw_directory
17-
fromgit.utilimportcwd,finalize_process
18-
19-
importos.pathasosp
16+
importddt
2017

18+
fromgitimportGit,refresh,GitCommandError,GitCommandNotFound,Repo,cmd
2119
fromgit.compatimportis_win
20+
fromgit.utilimportcwd,finalize_process
21+
fromtest.libimportTestBase,fixture_path,with_rw_directory
2222

2323

24+
@ddt.ddt
2425
classTestGit(TestBase):
2526
@classmethod
2627
defsetUpClass(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+
deftest_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+
withmock.patch.object(Git,"USE_SHELL",value_from_class):
91+
withcontextlib.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
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp