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

Commit9fa1cee

Browse files
committed
Extract a _assert_logged_for_popen method
This extracts the logic of searching log messages, and assertingthat (at least) one matches a pattern for the report of a Popencall with a given argument, from test_it_logs_if_it_uses_a_shellinto a new nonpublic test helper method _assert_logged_for_popen.The extracted version is modified to make it slightly more general,and slightly more robust. This is still not extremely robust: thenotation used to log Popen calls is informal, so it wouldn't makesense to really parse it as code. But this no longer assumes thatthe representation of a value ends at a word boundary, nor that thevalue is free of regular expression metacharacters.
1 parenta8a43fe commit9fa1cee

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

‎test/test_git.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ def tearDown(self):
4040

4141
gc.collect()
4242

43+
def_assert_logged_for_popen(self,log_watcher,name,value):
44+
re_name=re.escape(name)
45+
re_value=re.escape(str(value))
46+
re_line=re.compile(fr"DEBUG:git.cmd:Popen\(.*\b{re_name}={re_value}[,)]")
47+
match_attempts= [re_line.match(message)formessageinlog_watcher.output]
48+
self.assertTrue(any(match_attempts),repr(log_watcher.output))
49+
4350
@mock.patch.object(Git,"execute")
4451
deftest_call_process_calls_execute(self,git):
4552
git.return_value=""
@@ -113,14 +120,9 @@ def test_it_uses_shell_or_not_as_specified(self, case):
113120
deftest_it_logs_if_it_uses_a_shell(self,case):
114121
"""``shell=`` in the log message agrees with what is passed to `Popen`."""
115122
value_in_call,value_from_class=case
116-
117123
withself.assertLogs(cmd.log,level=logging.DEBUG)aslog_watcher:
118124
mock_popen=self._do_shell_combo(value_in_call,value_from_class)
119-
120-
popen_shell_arg=mock_popen.call_args.kwargs["shell"]
121-
expected_message=re.compile(rf"DEBUG:git.cmd:Popen\(.*\bshell={popen_shell_arg}\b.*\)")
122-
match_attempts= [expected_message.fullmatch(message)formessageinlog_watcher.output]
123-
self.assertTrue(any(match_attempts),repr(log_watcher.output))
125+
self._assert_logged_for_popen(log_watcher,"shell",mock_popen.call_args.kwargs["shell"])
124126

125127
deftest_it_executes_git_and_returns_result(self):
126128
self.assertRegex(self.git.execute(["git","version"]),r"^git version [\d\.]{2}.*$")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp