Skip to content

Commit 6cd302c

Browse files
Add tests.
1 parent 4f908e8 commit 6cd302c

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lib/test/pickletester.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import builtins
12
import collections
23
import copyreg
34
import dbm
@@ -11,6 +12,7 @@
1112
import struct
1213
import sys
1314
import threading
15+
import types
1416
import unittest
1517
import weakref
1618
from textwrap import dedent
@@ -1980,6 +1982,40 @@ def test_singleton_types(self):
19801982
u = self.loads(s)
19811983
self.assertIs(type(singleton), u)
19821984

1985+
def test_builtin_types(self):
1986+
for t in builtins.__dict__.values():
1987+
if isinstance(t, type) and not issubclass(t, BaseException):
1988+
for proto in protocols:
1989+
s = self.dumps(t, proto)
1990+
self.assertIs(self.loads(s), t)
1991+
1992+
def test_types_types(self):
1993+
for t in types.__dict__.values():
1994+
if isinstance(t, type):
1995+
for proto in protocols:
1996+
s = self.dumps(t, proto)
1997+
self.assertIs(self.loads(s), t)
1998+
1999+
def test_builtin_exceptions(self):
2000+
for t in builtins.__dict__.values():
2001+
if isinstance(t, type) and issubclass(t, BaseException):
2002+
for proto in protocols:
2003+
s = self.dumps(t, proto)
2004+
u = self.loads(s)
2005+
if proto <= 2 and issubclass(t, OSError) and t is not BlockingIOError:
2006+
self.assertIs(u, OSError)
2007+
elif proto <= 2 and issubclass(t, ImportError):
2008+
self.assertIs(u, ImportError)
2009+
else:
2010+
self.assertIs(u, t)
2011+
2012+
def test_builtin_functions(self):
2013+
for t in builtins.__dict__.values():
2014+
if isinstance(t, types.BuiltinFunctionType):
2015+
for proto in protocols:
2016+
s = self.dumps(t, proto)
2017+
self.assertIs(self.loads(s), t)
2018+
19832019
# Tests for protocol 2
19842020

19852021
def test_proto(self):

0 commit comments

Comments
 (0)