Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move CalledProcessError pickling test to test_subprocess
  • Loading branch information
Rémi Lapeyre committed Jan 16, 2019
commit 1d12d28ffa2dfb7c41ba5cd3d8e98838e9bdbb44
8 changes: 2 additions & 6 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,14 +1415,10 @@ def test_copy_pickle(self):

def test_pickle_overriden_init(self):
# Issue #27015
from subprocess import CalledProcessError

for proto in range(pickle.HIGHEST_PROTOCOL + 1):
orig = CalledProcessError(returncode=2, cmd='foo')
orig = NaiveException(x='foo')
exc = pickle.loads(pickle.dumps(orig, proto))
self.assertEqual(orig.cmd, exc.cmd)
self.assertEqual(orig.returncode, exc.returncode)

self.assertEqual(orig.x, exc.x)


if __name__ == '__main__':
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import threading
import gc
import textwrap
import pickle
from test.support import FakePath

try:
Expand Down Expand Up @@ -1690,6 +1691,14 @@ def test_CalledProcessError_str_non_zero(self):
error_string = str(err)
self.assertIn("non-zero exit status 2.", error_string)

def test_CalledProcessError_picklable(self):
# Issue #27015
err = subprocess.CalledProcessError(returncode=2, cmd='foo')
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
new = pickle.loads(pickle.dumps(err, proto))
self.assertEqual(err.returncode, new.returncode)
self.assertEqual(err.cmd, new.cmd)

def test_preexec(self):
# DISCLAIMER: Setting environment variables is *not* a good use
# of a preexec_fn. This is merely a test.
Expand Down