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

Skip to content

Commit 5379d05

Browse files
committed
Convert copy_reg test to PyUnit.
1 parent 970a53c commit 5379d05

1 file changed

Lines changed: 19 additions & 29 deletions

File tree

Lib/test/test_copy_reg.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
import copy_reg
2+
import test_support
3+
import unittest
4+
25

36
class C:
47
pass
58

69

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."
10+
class CopyRegTestCase(unittest.TestCase):
11+
12+
def test_class(self):
13+
self.assertRaises(TypeError, copy_reg.pickle,
14+
C, None, None)
15+
16+
def test_noncallable_reduce(self):
17+
self.assertRaises(TypeError, copy_reg.pickle,
18+
type(1), "not a callable")
19+
20+
def test_noncallable_constructor(self):
21+
self.assertRaises(TypeError, copy_reg.pickle,
22+
type(1), int, "not a callable")
23+
24+
25+
test_support.run_unittest(CopyRegTestCase)

0 commit comments

Comments
 (0)