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

Commitac50d8e

Browse files
committed
Change warning refresh-mode tests to expect logging
This is instead of the current behavior writing the message tostdout.This commit does not change the behavior of the code under test,but it changes tests to assert the following:- "Bad git executable" messages are logged, at level CRITICAL.- "log" (and "l") is recognized as another synonym of "warn".- "silent" is recognized as a synonym of "quiet" (as "silence" is).Although it is ambiguous whether this should be logged at levelERROR or CRITICAL, because git.refresh is still expected to beusable and can be called manually, not having a working git is acondition in which GitPython, and any program that really relies onits functionality, should be expected not work. That is the generalrationale for using CRIICAL here. There are also two specificreasons:- Existing messages GitPython logs as ERROR typically represent errors in individual operations on repositories, which could fail without indicating that GitPython's overall functionality is in an unusable state. Using the higher CRITICAL level for this situation makes sense for contrast.- Prior to#1813, logging messsges emitted from GitPython modules, no matter the level, were suppressed when logging was not configured, but because this message was printed instead of being logged, it was still shown. Now that it is to be logged, there may be a benefit to have an easy way for someone to bring back a close approximation of the old behavior. Having this message be at a higher logging level makes that easier to do. (This is a less important reason, as that should rarely be done.)test_initial_refresh_from_bad_git_path_env_warn is the main changedtest. All tests should pass again once code is changed for#1808.
1 parent147e80b commitac50d8e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎test/test_git.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
importcontextlib
77
importgc
88
importinspect
9-
importio
109
importlogging
1110
importos
1211
importos.pathasosp
@@ -333,7 +332,7 @@ def test_cmd_override(self):
333332
deftest_git_exc_name_is_git(self):
334333
self.assertEqual(self.git.git_exec_name,"git")
335334

336-
@ddt.data(("0",), ("q",), ("quiet",), ("s",), ("silence",), ("n",), ("none",))
335+
@ddt.data(("0",), ("q",), ("quiet",), ("s",), ("silence",), ("silent",), ("n",), ("none",))
337336
deftest_initial_refresh_from_bad_git_path_env_quiet(self,case):
338337
"""In "q" mode, bad initial path sets "git" and is quiet."""
339338
(mode,)=case
@@ -348,9 +347,9 @@ def test_initial_refresh_from_bad_git_path_env_quiet(self, case):
348347
refresh()
349348
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,"git")
350349

351-
@ddt.data(("1",), ("w",), ("warn",), ("warning",))
350+
@ddt.data(("1",), ("w",), ("warn",), ("warning",), ("l",), ("log",))
352351
deftest_initial_refresh_from_bad_git_path_env_warn(self,case):
353-
"""In "w" mode, bad initial path sets "git" and warns."""
352+
"""In "w" mode, bad initial path sets "git" and warns, by logging."""
354353
(mode,)=case
355354
env_vars= {
356355
"GIT_PYTHON_GIT_EXECUTABLE":str(Path("yada").absolute()),# Any bad path.
@@ -360,9 +359,11 @@ def test_initial_refresh_from_bad_git_path_env_warn(self, case):
360359
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=None# Simulate startup.
361360

362361
withmock.patch.dict(os.environ,env_vars):
363-
withcontextlib.redirect_stdout(io.StringIO())asout:
362+
withself.assertLogs(cmd.__name__,logging.CRITICAL)asctx:
364363
refresh()
365-
self.assertRegex(out.getvalue(),r"\AWARNING: Bad git executable.\n")
364+
self.assertEqual(len(ctx.records),1)
365+
message=ctx.records[0].getMessage()
366+
self.assertRegex(message,r"\AWARNING: Bad git executable.\n")
366367
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,"git")
367368

368369
@ddt.data(("2",), ("r",), ("raise",), ("e",), ("error",))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp