Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb953d7

Browse files
committed
Test the exception-raising for error cases in copy_reg.
1 parent 78a6a36 commit cb953d7

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lib/test/output/test_copy_reg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test_copy_reg
2+
Caught expected TypeError:
3+
copy_reg is not intended for use with classes
4+
5+
Caught expected TypeError:
6+
reduction functions must be callable
7+
8+
Caught expected TypeError:
9+
constructors must be callable

Lib/test/test_copy_reg.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import copy_reg
2+
3+
class C:
4+
pass
5+
6+
7+
try:
8+
copy_reg.pickle(C, None, None)
9+
except TypeError, e:
10+
print "Caught expected TypeError:"
11+
print e
12+
else:
13+
print "Failed to catch expected TypeError when registering a class type."
14+
15+
16+
print
17+
try:
18+
copy_reg.pickle(type(1), "not a callable")
19+
except TypeError, e:
20+
print "Caught expected TypeError:"
21+
print e
22+
else:
23+
print "Failed to catch TypeError " \
24+
"when registering a non-callable reduction function."
25+
26+
27+
print
28+
try:
29+
copy_reg.pickle(type(1), int, "not a callable")
30+
except TypeError, e:
31+
print "Caught expected TypeError:"
32+
print e
33+
else:
34+
print "Failed to catch TypeError " \
35+
"when registering a non-callable constructor."

0 commit comments

Comments
 (0)