[Python-checkins] gh-100129: Add tests for pickling all builtin types and functions (GH-100142)
miss-islington
webhook-mailer at python.org
Wed Dec 21 09:58:39 EST 2022
https://github.com/python/cpython/commit/0397f040e239c82848f51dedef9af7b9bd99ef55
commit: 0397f040e239c82848f51dedef9af7b9bd99ef55
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-12-21T06:58:20-08:00
summary:
gh-100129: Add tests for pickling all builtin types and functions (GH-100142)
(cherry picked from commit b98d2d31bffcaeb0c4c8848a8d1b35419c70b2da)
Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>
files:
M Lib/test/pickletester.py
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 499f80a15f34..6e87370c2065 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 struct
import sys
import threading
+import types
import unittest
import weakref
from textwrap import dedent
@@ -1980,6 +1982,33 @@ def test_singleton_types(self):
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):
More information about the Python-checkins
mailing list