|
| 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,40 @@ 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_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 | + |
1983 | 2019 | # Tests for protocol 2 |
1984 | 2020 |
|
1985 | 2021 | def test_proto(self): |
|
0 commit comments