Skip to content

Commit bce77d8

Browse files
author
Benjy Wiener
committed
Combine test_CalledProcessError_str tests
1 parent 12aff1a commit bce77d8

1 file changed

Lines changed: 15 additions & 25 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,36 +2428,26 @@ def test_run_abort(self):
24282428
p.wait()
24292429
self.assertEqual(-p.returncode, signal.SIGABRT)
24302430

2431-
def test_CalledProcessError_str_signal(self):
2432-
err = subprocess.CalledProcessError(-int(signal.SIGABRT), "fake cmd")
2433-
error_string = str(err)
2434-
# We're relying on the repr() of the signal.Signals intenum to provide
2435-
# the word signal, the signal name and the numeric value.
2436-
self.assertIn("signal", error_string.lower())
2437-
# We're not being specific about the signal name as some signals have
2438-
# multiple names and which name is revealed can vary.
2439-
self.assertIn("SIG", error_string)
2440-
self.assertIn(str(signal.SIGABRT), error_string)
2441-
2442-
def test_CalledProcessError_str_unknown_signal(self):
2443-
err = subprocess.CalledProcessError(-9876543, "fake cmd")
2444-
error_string = str(err)
2445-
self.assertIn("unknown signal 9876543.", error_string)
2446-
2447-
def test_CalledProcessError_str_non_zero(self):
2431+
def test_CalledProcessError_str(self):
2432+
# command string
24482433
err = subprocess.CalledProcessError(2, "fake cmd")
2449-
error_string = str(err)
2450-
self.assertIn("non-zero exit status 2.", error_string)
2434+
self.assertEqual(str(err), "Command 'fake cmd' returned non-zero exit status 2.")
24512435

2452-
def test_CalledProcessError_str_quote_in_cmd(self):
2436+
# command string with a single-quote
24532437
err = subprocess.CalledProcessError(2, "fake ' cmd")
2454-
error_string = str(err)
2455-
self.assertStartsWith(error_string, 'Command "fake \' cmd" ')
2438+
self.assertEqual(str(err), 'Command "fake \' cmd" returned non-zero exit status 2.')
24562439

2457-
def test_CalledProcessError_str_list_cmd(self):
2440+
# command list
24582441
err = subprocess.CalledProcessError(2, ["fake", "cmd"])
2459-
error_string = str(err)
2460-
self.assertStartsWith(error_string, "Command ['fake', 'cmd'] ")
2442+
self.assertEqual(str(err), "Command ['fake', 'cmd'] returned non-zero exit status 2.")
2443+
2444+
# signal
2445+
err = subprocess.CalledProcessError(-int(signal.SIGABRT), "fake cmd")
2446+
self.assertEqual(str(err), f"Command 'fake cmd' died with {signal.SIGABRT!r}.")
2447+
2448+
# unknown signal
2449+
err = subprocess.CalledProcessError(-9876543, "fake cmd")
2450+
self.assertEqual(str(err), "Command 'fake cmd' died with unknown signal 9876543.")
24612451

24622452
def test_preexec(self):
24632453
# DISCLAIMER: Setting environment variables is *not* a good use

0 commit comments

Comments
 (0)