summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-08 08:25:47 (GMT)
committerGitHub <noreply@github.com>2017-04-08 08:25:47 (GMT)
commitaf685f9050416da8050e0ec11a8dff9afd4130e7 (patch)
tree6cc7ad8a88bd7458913a0b1501601b230c62f513 /Lib/test
parentc26b19d5c7aba51b50a4d7fb5f8291036cb9da24 (diff)
downloadcpython-af685f9050416da8050e0ec11a8dff9afd4130e7.zip
cpython-af685f9050416da8050e0ec11a8dff9afd4130e7.tar.gz
cpython-af685f9050416da8050e0ec11a8dff9afd4130e7.tar.bz2
bpo-29998: Pickling and copying ImportError now preserves name and path (#1010) (#1042)
attributes. (cherry picked from commit b785396ab451b0c9d6ae9ee5a9e56c810209a6cb)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_exceptions.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 4837922..960fc0f 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1,5 +1,6 @@
# Python test set -- part 5, built-in exceptions
+import copy
import os
import sys
import unittest
@@ -1119,6 +1120,25 @@ class ImportErrorTests(unittest.TestCase):
exc = ImportError(arg)
self.assertEqual(str(arg), str(exc))
+ def test_copy_pickle(self):
+ for kwargs in (dict(),
+ dict(name='somename'),
+ dict(path='somepath'),
+ dict(name='somename', path='somepath')):
+ orig = ImportError('test', **kwargs)
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ exc = pickle.loads(pickle.dumps(orig, proto))
+ self.assertEqual(exc.args, ('test',))
+ self.assertEqual(exc.msg, 'test')
+ self.assertEqual(exc.name, orig.name)
+ self.assertEqual(exc.path, orig.path)
+ for c in copy.copy, copy.deepcopy:
+ exc = c(orig)
+ self.assertEqual(exc.args, ('test',))
+ self.assertEqual(exc.msg, 'test')
+ self.assertEqual(exc.name, orig.name)
+ self.assertEqual(exc.path, orig.path)
+
if __name__ == '__main__':
unittest.main()