Omit warning prefix in "Bad git executable" message by EliahKagan · Pull Request #1816 · gitpython-developers/GitPython
def test_cmd_override(self): with mock.patch.object( type(self.git), "GIT_PYTHON_GIT_EXECUTABLE", osp.join("some", "path", "which", "doesn't", "exist", "gitbinary"), ): self.assertRaises(GitCommandNotFound, self.git.version)
def test_git_exc_name_is_git(self): self.assertEqual(self.git.git_exec_name, "git")
def test_cmd_override(self): """Directly set bad GIT_PYTHON_GIT_EXECUTABLE causes git operations to raise.""" bad_path = osp.join("some", "path", "which", "doesn't", "exist", "gitbinary") with mock.patch.object(Git, "GIT_PYTHON_GIT_EXECUTABLE", bad_path): with self.assertRaises(GitCommandNotFound) as ctx: self.git.version() self.assertEqual(ctx.exception.command, [bad_path, "version"])
@ddt.data(("0",), ("q",), ("quiet",), ("s",), ("silence",), ("silent",), ("n",), ("none",)) def test_initial_refresh_from_bad_git_path_env_quiet(self, case): """In "q" mode, bad initial path sets "git" and is quiet."""
with mock.patch.dict(os.environ, set_vars): refresh()
with mock.patch.dict(os.environ, env_vars): with self.assertLogs(cmd.__name__, logging.CRITICAL) as ctx: refresh() self.assertEqual(len(ctx.records), 1) message = ctx.records[0].getMessage() self.assertRegex(message, r"\AWARNING: Bad git executable.\n") self.assertRegex(message, r"\ABad git executable.\n") self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, "git")
@ddt.data(("2",), ("r",), ("raise",), ("e",), ("error",))
with mock.patch.dict(os.environ, env_vars): with self.assertRaisesRegex(ImportError, r"\ABad git executable.\n"):
with _rollback_refresh(): type(self.git).GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup. Git.GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": absolute_path}): refresh()
# Now observe if setting the environment variable to "git" takes effect. with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": "git"}):
# Now observe if setting the environment variable to "git" takes effect. with mock.patch.dict(os.environ, {"GIT_PYTHON_GIT_EXECUTABLE": "git"}):