Skip to content

Commit 790a790

Browse files
committed
Log stdin arg as such, and test that this is done
This changes how the Popen call debug logging line shows the informal summary of what kind of thing is being passed as the stdin argument to Popen, showing it with stdin= rather than istream=. The new test, with "istream" in place of "stdin", passed before the code change in the git.cmd module, failed once "istream" was changed to "stdin" in the test, and then, as expected, passed again once "istream=" was changed to "stdin=" in the log.debug call in git.cmd.Git.execute.
1 parent 9fa1cee commit 790a790

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: git/cmd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def execute(
979979
if shell is None:
980980
shell = self.USE_SHELL
981981
log.debug(
982-
"Popen(%s, cwd=%s, universal_newlines=%s, shell=%s, istream=%s)",
982+
"Popen(%s, cwd=%s, universal_newlines=%s, shell=%s, stdin=%s)",
983983
redacted_command,
984984
cwd,
985985
universal_newlines,

Diff for: test/test_git.py

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ def test_it_logs_if_it_uses_a_shell(self, case):
124124
mock_popen = self._do_shell_combo(value_in_call, value_from_class)
125125
self._assert_logged_for_popen(log_watcher, "shell", mock_popen.call_args.kwargs["shell"])
126126

127+
@ddt.data(
128+
("None", None),
129+
("<valid stream>", subprocess.PIPE),
130+
)
131+
def test_it_logs_istream_summary_for_stdin(self, case):
132+
expected_summary, istream_argument = case
133+
with self.assertLogs(cmd.log, level=logging.DEBUG) as log_watcher:
134+
self.git.execute(["git", "version"], istream=istream_argument)
135+
self._assert_logged_for_popen(log_watcher, "stdin", expected_summary)
136+
127137
def test_it_executes_git_and_returns_result(self):
128138
self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$")
129139

0 commit comments

Comments
 (0)