|
| 1 | +import builtins |
1 | 2 | import collections
|
2 | 3 | import copyreg
|
3 | 4 | import dbm
|
|
11 | 12 | import struct
|
12 | 13 | import sys
|
13 | 14 | import threading
|
| 15 | +import types |
14 | 16 | import unittest
|
15 | 17 | import weakref
|
16 | 18 | from textwrap import dedent
|
@@ -1980,6 +1982,33 @@ def test_singleton_types(self):
|
1980 | 1982 | u = self.loads(s)
|
1981 | 1983 | self.assertIs(type(singleton), u)
|
1982 | 1984 |
|
| 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_builtin_exceptions(self): |
| 1993 | + for t in builtins.__dict__.values(): |
| 1994 | + if isinstance(t, type) and issubclass(t, BaseException): |
| 1995 | + for proto in protocols: |
| 1996 | + s = self.dumps(t, proto) |
| 1997 | + u = self.loads(s) |
| 1998 | + if proto <= 2 and issubclass(t, OSError) and t is not BlockingIOError: |
| 1999 | + self.assertIs(u, OSError) |
| 2000 | + elif proto <= 2 and issubclass(t, ImportError): |
| 2001 | + self.assertIs(u, ImportError) |
| 2002 | + else: |
| 2003 | + self.assertIs(u, t) |
| 2004 | + |
| 2005 | + def test_builtin_functions(self): |
| 2006 | + for t in builtins.__dict__.values(): |
| 2007 | + if isinstance(t, types.BuiltinFunctionType): |
| 2008 | + for proto in protocols: |
| 2009 | + s = self.dumps(t, proto) |
| 2010 | + self.assertIs(self.loads(s), t) |
| 2011 | + |
1983 | 2012 | # Tests for protocol 2
|
1984 | 2013 |
|
1985 | 2014 | def test_proto(self):
|
|
0 commit comments