@@ -439,16 +439,15 @@ def testAttributes(self):
439
439
value , expected [checkArgName ]))
440
440
441
441
# test for pickling support
442
- for p in [pickle ]:
443
- for protocol in range (p .HIGHEST_PROTOCOL + 1 ):
444
- s = p .dumps (e , protocol )
445
- new = p .loads (s )
446
- for checkArgName in expected :
447
- got = repr (getattr (new , checkArgName ))
448
- want = repr (expected [checkArgName ])
449
- self .assertEqual (got , want ,
450
- 'pickled "%r", attribute "%s' %
451
- (e , checkArgName ))
442
+ for protocol in range (pickle .HIGHEST_PROTOCOL + 1 ):
443
+ s = pickle .dumps (e , protocol )
444
+ new = pickle .loads (s )
445
+ for checkArgName in expected :
446
+ got = repr (getattr (new , checkArgName ))
447
+ want = repr (expected [checkArgName ])
448
+ self .assertEqual (got , want ,
449
+ 'pickled "%r", attribute "%s"' %
450
+ (e , checkArgName ))
452
451
453
452
def testWithTraceback (self ):
454
453
try :
@@ -1417,8 +1416,14 @@ def test_pickle_overriden_init(self):
1417
1416
# Issue #27015
1418
1417
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
1419
1418
orig = NaiveException (x = 'foo' )
1420
- exc = pickle .loads (pickle .dumps (orig , proto ))
1421
- self .assertEqual (orig .x , exc .x )
1419
+ if proto in (0 , 1 ):
1420
+ # Pickling excpetions keyword arguments is not supported for
1421
+ # protocol 0 and 1
1422
+ with self .assertRaises (TypeError ):
1423
+ pickle .loads (pickle .dumps (orig , proto ))
1424
+ else :
1425
+ exc = pickle .loads (pickle .dumps (orig , proto ))
1426
+ self .assertEqual (orig .x , exc .x )
1422
1427
1423
1428
1424
1429
if __name__ == '__main__' :
0 commit comments