diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-12-21 14:58:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-21 14:58:31 (GMT) |
commit | 2dda6680ccb50bd1d8a8dcf0d524feb7daf5a3af (patch) | |
tree | 64e382bacb7605996a5e15643a31353ce84cad6a /Lib/test | |
parent | 7f24056dfbcaa080ab825924667e9359d86570d9 (diff) | |
download | cpython-2dda6680ccb50bd1d8a8dcf0d524feb7daf5a3af.zip cpython-2dda6680ccb50bd1d8a8dcf0d524feb7daf5a3af.tar.gz cpython-2dda6680ccb50bd1d8a8dcf0d524feb7daf5a3af.tar.bz2 |
gh-100129: Add tests for pickling all builtin types and functions (GH-100142)
(cherry picked from commit b98d2d31bffcaeb0c4c8848a8d1b35419c70b2da)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pickletester.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 18d7f52..72d6f52 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1,3 +1,4 @@ +import builtins import collections import copyreg import dbm @@ -11,6 +12,7 @@ import shutil import struct import sys import threading +import types import unittest import weakref from textwrap import dedent @@ -1979,6 +1981,33 @@ class AbstractPickleTests: u = self.loads(s) self.assertIs(type(singleton), u) + def test_builtin_types(self): + for t in builtins.__dict__.values(): + if isinstance(t, type) and not issubclass(t, BaseException): + for proto in protocols: + s = self.dumps(t, proto) + self.assertIs(self.loads(s), t) + + def test_builtin_exceptions(self): + for t in builtins.__dict__.values(): + if isinstance(t, type) and issubclass(t, BaseException): + for proto in protocols: + s = self.dumps(t, proto) + u = self.loads(s) + if proto <= 2 and issubclass(t, OSError) and t is not BlockingIOError: + self.assertIs(u, OSError) + elif proto <= 2 and issubclass(t, ImportError): + self.assertIs(u, ImportError) + else: + self.assertIs(u, t) + + def test_builtin_functions(self): + for t in builtins.__dict__.values(): + if isinstance(t, types.BuiltinFunctionType): + for proto in protocols: + s = self.dumps(t, proto) + self.assertIs(self.loads(s), t) + # Tests for protocol 2 def test_proto(self): |