Skip to content

Commit 42102a1

Browse files
committed
Remove expected_returncode from CalledProcessError
1 parent 84b38f7 commit 42102a1

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

pre_commit/util.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,12 @@ def __init__(
8383
self,
8484
returncode: int,
8585
cmd: tuple[str, ...],
86-
expected_returncode: int,
8786
stdout: bytes,
8887
stderr: bytes | None,
8988
) -> None:
90-
super().__init__(returncode, cmd, expected_returncode, stdout, stderr)
89+
super().__init__(returncode, cmd, stdout, stderr)
9190
self.returncode = returncode
9291
self.cmd = cmd
93-
self.expected_returncode = expected_returncode
9492
self.stdout = stdout
9593
self.stderr = stderr
9694

@@ -104,7 +102,6 @@ def _indent_or_none(part: bytes | None) -> bytes:
104102
return b''.join((
105103
f'command: {self.cmd!r}\n'.encode(),
106104
f'return code: {self.returncode}\n'.encode(),
107-
f'expected return code: {self.expected_returncode}\n'.encode(),
108105
b'stdout:', _indent_or_none(self.stdout), b'\n',
109106
b'stderr:', _indent_or_none(self.stderr),
110107
))
@@ -142,9 +139,8 @@ def cmd_output_b(
142139
stdout_b, stderr_b = proc.communicate()
143140
returncode = proc.returncode
144141

145-
SUCCESS = 0
146-
if check and returncode != SUCCESS:
147-
raise CalledProcessError(returncode, cmd, SUCCESS, stdout_b, stderr_b)
142+
if check and returncode:
143+
raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
148144

149145
return returncode, stdout_b, stderr_b
150146

tests/error_handler_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_error_handler_non_ascii_exception(mock_store_dir):
162162
def test_error_handler_non_utf8_exception(mock_store_dir):
163163
with pytest.raises(SystemExit):
164164
with error_handler.error_handler():
165-
raise CalledProcessError(1, ('exe',), 0, b'error: \xa0\xe1', b'')
165+
raise CalledProcessError(1, ('exe',), b'error: \xa0\xe1', b'')
166166

167167

168168
def test_error_handler_non_stringable_exception(mock_store_dir):

tests/languages/docker_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ def test_get_docker_path_in_docker_windows(in_docker):
178178

179179
def test_get_docker_path_in_docker_docker_in_docker(in_docker):
180180
# won't be able to discover "self" container in true docker-in-docker
181-
err = CalledProcessError(1, (), 0, b'', b'')
181+
err = CalledProcessError(1, (), b'', b'')
182182
with mock.patch.object(docker, 'cmd_output_b', side_effect=err):
183183
assert docker._get_docker_path('/project') == '/project'

tests/store_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_clone_shallow_failure_fallback_to_complete(
127127

128128
# Force shallow clone failure
129129
def fake_shallow_clone(self, *args, **kwargs):
130-
raise CalledProcessError(1, (), 0, b'', None)
130+
raise CalledProcessError(1, (), b'', None)
131131
store._shallow_clone = fake_shallow_clone
132132

133133
ret = store.clone(path, rev)

tests/util_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919

2020
def test_CalledProcessError_str():
21-
error = CalledProcessError(1, ('exe',), 0, b'output', b'errors')
21+
error = CalledProcessError(1, ('exe',), b'output', b'errors')
2222
assert str(error) == (
2323
"command: ('exe',)\n"
2424
'return code: 1\n'
25-
'expected return code: 0\n'
2625
'stdout:\n'
2726
' output\n'
2827
'stderr:\n'
@@ -31,11 +30,10 @@ def test_CalledProcessError_str():
3130

3231

3332
def test_CalledProcessError_str_nooutput():
34-
error = CalledProcessError(1, ('exe',), 0, b'', b'')
33+
error = CalledProcessError(1, ('exe',), b'', b'')
3534
assert str(error) == (
3635
"command: ('exe',)\n"
3736
'return code: 1\n'
38-
'expected return code: 0\n'
3937
'stdout: (none)\n'
4038
'stderr: (none)'
4139
)

0 commit comments

Comments
 (0)