|
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 | +importcontextlib |
7 | 8 | importos
|
| 9 | +importos.pathasosp |
8 | 10 | importshutil
|
9 | 11 | importsubprocess
|
10 | 12 | importsys
|
11 | 13 | fromtempfileimportTemporaryDirectory,TemporaryFile
|
12 | 14 | fromunittestimportmock,skipUnless
|
13 | 15 |
|
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 |
20 | 17 |
|
| 18 | +fromgitimportGit,refresh,GitCommandError,GitCommandNotFound,Repo,cmd |
21 | 19 | fromgit.compatimportis_win
|
| 20 | +fromgit.utilimportcwd,finalize_process |
| 21 | +fromtest.libimportTestBase,fixture_path,with_rw_directory |
22 | 22 |
|
23 | 23 |
|
| 24 | +@ddt.ddt |
24 | 25 | classTestGit(TestBase):
|
25 | 26 | @classmethod
|
26 | 27 | defsetUpClass(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 | +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 | + |
76 | 99 | deftest_it_executes_git_and_returns_result(self):
|
77 | 100 | self.assertRegex(self.git.execute(["git","version"]),r"^git version [\d\.]{2}.*$")
|
78 | 101 |
|
|