@@ -3935,36 +3935,37 @@ def test_shared_memory_pickle_unpickle(self):
3935
3935
3936
3936
# Test pickling
3937
3937
pickled_sms = pickle .dumps (sms , protocol = proto )
3938
- self .assertNotIn (b'pickle' , pickled_sms )
3939
3938
3940
3939
# Test unpickling
3941
3940
sms2 = pickle .loads (pickled_sms )
3942
- self .assertIsInstance (sms2 , sms . __class__ )
3941
+ self .assertIsInstance (sms2 , shared_memory . SharedMemory )
3943
3942
self .assertEqual (sms .name , sms2 .name )
3944
- self .assertEqual (
3945
- bytes ( sms . buf [ 0 : 6 ]), bytes (sms2 .buf [0 :6 ]), b'pickle' )
3943
+ self .assertEqual (bytes ( sms . buf [ 0 : 6 ]), b'pickle' )
3944
+ self . assertEqual ( bytes (sms2 .buf [0 :6 ]), b'pickle' )
3946
3945
3947
3946
# Test that unpickled version is still the same SharedMemory
3948
3947
sms .buf [0 :6 ] = b'newval'
3949
- self .assertEqual (
3950
- bytes ( sms . buf [ 0 : 6 ]), bytes (sms2 .buf [0 :6 ]), b'newval' )
3948
+ self .assertEqual (bytes ( sms . buf [ 0 : 6 ]), b'newval' )
3949
+ self . assertEqual ( bytes (sms2 .buf [0 :6 ]), b'newval' )
3951
3950
3952
3951
sms2 .buf [0 :6 ] = b'oldval'
3953
- self .assertEqual (
3954
- bytes ( sms . buf [ 0 : 6 ]), bytes (sms2 .buf [0 :6 ]), b'oldval' )
3952
+ self .assertEqual (bytes ( sms . buf [ 0 : 6 ]), b'oldval' )
3953
+ self . assertEqual ( bytes (sms2 .buf [0 :6 ]), b'oldval' )
3955
3954
3956
3955
def test_shared_memory_pickle_unpickle_dead_object (self ):
3957
- sms = shared_memory .SharedMemory (create = True , size = 512 )
3958
- sms .buf [0 :6 ] = b'pickle'
3959
- pickled_sms = pickle .dumps (sms )
3956
+ for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
3957
+ with self .subTest (proto = proto ):
3958
+ sms = shared_memory .SharedMemory (create = True , size = 512 )
3959
+ sms .buf [0 :6 ] = b'pickle'
3960
+ pickled_sms = pickle .dumps (sms )
3960
3961
3961
- # Now, we are going to kill the original object.
3962
- # So, unpickled one won't be able to attach to it.
3963
- sms .close ()
3964
- sms .unlink ()
3962
+ # Now, we are going to kill the original object.
3963
+ # So, unpickled one won't be able to attach to it.
3964
+ sms .close ()
3965
+ sms .unlink ()
3965
3966
3966
- with self .assertRaises (FileNotFoundError ):
3967
- pickle .loads (pickled_sms )
3967
+ with self .assertRaises (FileNotFoundError ):
3968
+ pickle .loads (pickled_sms )
3968
3969
3969
3970
def test_shared_memory_across_processes (self ):
3970
3971
# bpo-40135: don't define shared memory block's name in case of
@@ -4194,11 +4195,12 @@ def test_shared_memory_ShareableList_pickling(self):
4194
4195
deserialized_sl , shared_memory .ShareableList )
4195
4196
self .assertEqual (deserialized_sl [- 1 ], 9 )
4196
4197
self .assertIsNot (sl , deserialized_sl )
4198
+
4197
4199
deserialized_sl [4 ] = "changed"
4198
4200
self .assertEqual (sl [4 ], "changed" )
4201
+ sl [3 ] = "newvalue"
4202
+ self .assertEqual (deserialized_sl [3 ], "newvalue" )
4199
4203
4200
- # Verify data is not being put into the pickled representation.
4201
- name = 'a' * len (sl .shm .name )
4202
4204
larger_sl = shared_memory .ShareableList (range (400 ))
4203
4205
self .addCleanup (larger_sl .shm .unlink )
4204
4206
serialized_larger_sl = pickle .dumps (larger_sl , protocol = proto )
@@ -4209,16 +4211,18 @@ def test_shared_memory_ShareableList_pickling(self):
4209
4211
sl .shm .close ()
4210
4212
4211
4213
def test_shared_memory_ShareableList_pickling_dead_object (self ):
4212
- sl = shared_memory .ShareableList (range (10 ))
4213
- serialized_sl = pickle .dumps (sl )
4214
+ for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
4215
+ with self .subTest (proto = proto ):
4216
+ sl = shared_memory .ShareableList (range (10 ))
4217
+ serialized_sl = pickle .dumps (sl )
4214
4218
4215
- # Now, we are going to kill the original object.
4216
- # So, unpickled one won't be able to attach to it.
4217
- sl .shm .close ()
4218
- sl .shm .unlink ()
4219
+ # Now, we are going to kill the original object.
4220
+ # So, unpickled one won't be able to attach to it.
4221
+ sl .shm .close ()
4222
+ sl .shm .unlink ()
4219
4223
4220
- with self .assertRaises (FileNotFoundError ):
4221
- pickle .loads (serialized_sl )
4224
+ with self .assertRaises (FileNotFoundError ):
4225
+ pickle .loads (serialized_sl )
4222
4226
4223
4227
def test_shared_memory_cleaned_after_process_termination (self ):
4224
4228
cmd = '''if 1:
0 commit comments