| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,5 +56,6 @@ Contributors are: | |||
| 56 | 56 | -Ethan Lin <et.repositories _at_ gmail.com> | |
| 57 | 57 | -Jonas Scharpf <jonas.scharpf _at_ checkmk.com> | |
| 58 | 58 | -Gordon Marx | |
| 59 | + -Enji Cooper | ||
| 59 | 60 | ||
| 60 | 61 | Portions derived from other open source works and are clearly marked. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1364,25 +1364,29 @@ def communicate() -> Tuple[AnyStr, AnyStr]: | |||
| 1364 | 1364 | if output_stream is None: | |
| 1365 | 1365 | stdout_value, stderr_value = communicate() | |
| 1366 | 1366 | # Strip trailing "\n". | |
| 1367 | - if stdout_value.endswith(newline) and strip_newline_in_stdout: # type: ignore[arg-type] | ||
| 1367 | + if stdout_value is not None and stdout_value.endswith(newline) and strip_newline_in_stdout: # type: ignore[arg-type] | ||
| 1368 | 1368 | stdout_value = stdout_value[:-1] | |
| 1369 | - if stderr_value.endswith(newline): # type: ignore[arg-type] | ||
| 1369 | + if stderr_value is not None and stderr_value.endswith(newline): # type: ignore[arg-type] | ||
| 1370 | 1370 | stderr_value = stderr_value[:-1] | |
| 1371 | 1371 | ||
| 1372 | 1372 | status = proc.returncode | |
| 1373 | 1373 | else: | |
| 1374 | 1374 | max_chunk_size = max_chunk_size if max_chunk_size and max_chunk_size > 0 else io.DEFAULT_BUFFER_SIZE | |
| 1375 | - stream_copy(proc.stdout, output_stream, max_chunk_size) | ||
| 1376 | - stdout_value = proc.stdout.read() | ||
| 1377 | - stderr_value = proc.stderr.read() | ||
| 1375 | + if proc.stdout is not None: | ||
| 1376 | + stream_copy(proc.stdout, output_stream, max_chunk_size) | ||
| 1377 | + stdout_value = proc.stdout.read() | ||
| 1378 | + if proc.stderr is not None: | ||
| 1379 | + stderr_value = proc.stderr.read() | ||
| 1378 | 1380 | # Strip trailing "\n". | |
| 1379 | - if stderr_value.endswith(newline): # type: ignore[arg-type] | ||
| 1381 | + if stderr_value is not None and stderr_value.endswith(newline): # type: ignore[arg-type] | ||
| 1380 | 1382 | stderr_value = stderr_value[:-1] | |
| 1381 | 1383 | status = proc.wait() | |
| 1382 | 1384 | # END stdout handling | |
| 1383 | 1385 | finally: | |
| 1384 | - proc.stdout.close() | ||
| 1385 | - proc.stderr.close() | ||
| 1386 | + if proc.stdout is not None: | ||
| 1387 | + proc.stdout.close() | ||
| 1388 | + if proc.stderr is not None: | ||
| 1389 | + proc.stderr.close() | ||
| 1386 | 1390 | ||
| 1387 | 1391 | if self.GIT_PYTHON_TRACE == "full": | |
| 1388 | 1392 | cmdstr = " ".join(redacted_command) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | import contextlib | |
| 7 | 7 | import gc | |
| 8 | 8 | import inspect | |
| 9 | + import io | ||
| 9 | 10 | import logging | |
| 10 | 11 | import os | |
| 11 | 12 | import os.path as osp | |
@@ -201,6 +202,25 @@ def test_it_logs_istream_summary_for_stdin(self, case): | |||
| 201 | 202 | def test_it_executes_git_and_returns_result(self): | |
| 202 | 203 | self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$") | |
| 203 | 204 | ||
| 205 | + def test_it_output_stream_with_stdout_is_false(self): | ||
| 206 | + temp_stream = io.BytesIO() | ||
| 207 | + self.git.execute( | ||
| 208 | + ["git", "version"], | ||
| 209 | + output_stream=temp_stream, | ||
| 210 | + with_stdout=False, | ||
| 211 | + ) | ||
| 212 | + self.assertEqual(temp_stream.tell(), 0) | ||
| 213 | + | ||
| 214 | + def test_it_executes_git_without_stdout_redirect(self): | ||
| 215 | + returncode, stdout, stderr = self.git.execute( | ||
| 216 | + ["git", "version"], | ||
| 217 | + with_extended_output=True, | ||
| 218 | + with_stdout=False, | ||
| 219 | + ) | ||
| 220 | + self.assertEqual(returncode, 0) | ||
| 221 | + self.assertIsNone(stdout) | ||
| 222 | + self.assertIsNotNone(stderr) | ||
| 223 | + | ||
| 204 | 224 | @ddt.data( | |
| 205 | 225 | # chdir_to_repo, shell, command, use_shell_impostor | |
| 206 | 226 | (False, False, ["git", "version"], False), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,7 +113,7 @@ def test_deletes_dir_with_readonly_files(self, tmp_path): | |||
| 113 | 113 | sys.platform == "cygwin", | |
| 114 | 114 | reason="Cygwin can't set the permissions that make the test meaningful.", | |
| 115 | 115 | ) | |
| 116 | - def test_avoids_changing_permissions_outside_tree(self, tmp_path): | ||
| 116 | + def test_avoids_changing_permissions_outside_tree(self, tmp_path, request): | ||
| 117 | 117 | # Automatically works on Windows, but on Unix requires either special handling | |
| 118 | 118 | # or refraining from attempting to fix PermissionError by making chmod calls. | |
| 119 | 119 | ||
@@ -125,9 +125,32 @@ def test_avoids_changing_permissions_outside_tree(self, tmp_path): | |||
| 125 | 125 | ||
| 126 | 126 | dir2 = tmp_path / "dir2" | |
| 127 | 127 | dir2.mkdir() | |
| 128 | - (dir2 / "symlink").symlink_to(dir1 / "file") | ||
| 128 | + symlink = dir2 / "symlink" | ||
| 129 | + symlink.symlink_to(dir1 / "file") | ||
| 129 | 130 | dir2.chmod(stat.S_IRUSR | stat.S_IXUSR) | |
| 130 | 131 | ||
| 132 | + def preen_dir2(): | ||
| 133 | + """Don't leave unwritable directories behind. | ||
| 134 | + | ||
| 135 | + pytest has difficulties cleaning up after the fact on some platforms, | ||
| 136 | + e.g., macOS, and whines incessantly until the issue is resolved--regardless | ||
| 137 | + of the pytest session. | ||
| 138 | + """ | ||
| 139 | + rwx = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | ||
| 140 | + if not dir2.exists(): | ||
| 141 | + return | ||
| 142 | + if symlink.exists(): | ||
| 143 | + try: | ||
| 144 | + # Try lchmod first, if the platform supports it. | ||
| 145 | + symlink.lchmod(rwx) | ||
| 146 | + except NotImplementedError: | ||
| 147 | + # The platform (probably win32) doesn't support lchmod; fall back to chmod. | ||
| 148 | + symlink.chmod(rwx) | ||
| 149 | + dir2.chmod(rwx) | ||
| 150 | + rmtree(dir2) | ||
| 151 | + | ||
| 152 | + request.addfinalizer(preen_dir2) | ||
| 153 | + | ||
| 131 | 154 | try: | |
| 132 | 155 | rmtree(dir2) | |
| 133 | 156 | except PermissionError: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments