mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-29998: Pickling and copying ImportError now preserves name and path (#1010)
attributes.
This commit is contained in:
parent
b879fe82e7
commit
b785396ab4
3 changed files with 71 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
# Python test set -- part 5, built-in exceptions
|
||||
|
||||
import copy
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
@ -1126,6 +1127,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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue