@@ -2272,39 +2272,47 @@ def test_nonencodable_module_name_error(self):
2272
2272
2273
2273
def test_nested_lookup_error (self ):
2274
2274
# Nested name does not exist
2275
- obj = REX ('AbstractPickleTests.spam' )
2275
+ global TestGlobal
2276
+ class TestGlobal :
2277
+ class A :
2278
+ pass
2279
+ obj = REX ('TestGlobal.A.B.C' )
2276
2280
obj .__module__ = __name__
2277
2281
for proto in protocols :
2278
2282
with self .subTest (proto = proto ):
2279
2283
with self .assertRaises (pickle .PicklingError ) as cm :
2280
2284
self .dumps (obj , proto )
2281
2285
self .assertEqual (str (cm .exception ),
2282
2286
f"Can't pickle { obj !r} : "
2283
- f"it's not found as { __name__ } .AbstractPickleTests.spam " )
2287
+ f"it's not found as { __name__ } .TestGlobal.A.B.C " )
2284
2288
self .assertEqual (str (cm .exception .__context__ ),
2285
- "type object 'AbstractPickleTests ' has no attribute 'spam '" )
2289
+ "type object 'A ' has no attribute 'B '" )
2286
2290
2287
2291
obj .__module__ = None
2288
2292
for proto in protocols :
2289
2293
with self .subTest (proto = proto ):
2290
2294
with self .assertRaises (pickle .PicklingError ) as cm :
2291
2295
self .dumps (obj , proto )
2292
2296
self .assertEqual (str (cm .exception ),
2293
- f"Can't pickle { obj !r} : it's not found as __main__.AbstractPickleTests.spam" )
2297
+ f"Can't pickle { obj !r} : "
2298
+ f"it's not found as __main__.TestGlobal.A.B.C" )
2294
2299
self .assertEqual (str (cm .exception .__context__ ),
2295
- "module '__main__' has no attribute 'AbstractPickleTests '" )
2300
+ "module '__main__' has no attribute 'TestGlobal '" )
2296
2301
2297
2302
def test_wrong_object_lookup_error (self ):
2298
2303
# Name is bound to different object
2299
- obj = REX ('AbstractPickleTests' )
2304
+ global TestGlobal
2305
+ class TestGlobal :
2306
+ pass
2307
+ obj = REX ('TestGlobal' )
2300
2308
obj .__module__ = __name__
2301
- AbstractPickleTests .ham = []
2302
2309
for proto in protocols :
2303
2310
with self .subTest (proto = proto ):
2304
2311
with self .assertRaises (pickle .PicklingError ) as cm :
2305
2312
self .dumps (obj , proto )
2306
2313
self .assertEqual (str (cm .exception ),
2307
- f"Can't pickle { obj !r} : it's not the same object as { __name__ } .AbstractPickleTests" )
2314
+ f"Can't pickle { obj !r} : "
2315
+ f"it's not the same object as { __name__ } .TestGlobal" )
2308
2316
self .assertIsNone (cm .exception .__context__ )
2309
2317
2310
2318
obj .__module__ = None
@@ -2313,9 +2321,10 @@ def test_wrong_object_lookup_error(self):
2313
2321
with self .assertRaises (pickle .PicklingError ) as cm :
2314
2322
self .dumps (obj , proto )
2315
2323
self .assertEqual (str (cm .exception ),
2316
- f"Can't pickle { obj !r} : it's not found as __main__.AbstractPickleTests" )
2324
+ f"Can't pickle { obj !r} : "
2325
+ f"it's not found as __main__.TestGlobal" )
2317
2326
self .assertEqual (str (cm .exception .__context__ ),
2318
- "module '__main__' has no attribute 'AbstractPickleTests '" )
2327
+ "module '__main__' has no attribute 'TestGlobal '" )
2319
2328
2320
2329
def test_local_lookup_error (self ):
2321
2330
# Test that whichmodule() errors out cleanly when looking up
0 commit comments