@@ -3935,36 +3935,37 @@ def test_shared_memory_pickle_unpickle(self):
39353935
39363936 # Test pickling
39373937 pickled_sms = pickle .dumps (sms , protocol = proto )
3938- self .assertNotIn (b'pickle' , pickled_sms )
39393938
39403939 # Test unpickling
39413940 sms2 = pickle .loads (pickled_sms )
3942- self .assertIsInstance (sms2 , sms . __class__ )
3941+ self .assertIsInstance (sms2 , shared_memory . SharedMemory )
39433942 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' )
39463945
39473946 # Test that unpickled version is still the same SharedMemory
39483947 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' )
39513950
39523951 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' )
39553954
39563955 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 )
39603961
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 ()
39653966
3966- with self .assertRaises (FileNotFoundError ):
3967- pickle .loads (pickled_sms )
3967+ with self .assertRaises (FileNotFoundError ):
3968+ pickle .loads (pickled_sms )
39683969
39693970 def test_shared_memory_across_processes (self ):
39703971 # bpo-40135: don't define shared memory block's name in case of
@@ -4194,11 +4195,12 @@ def test_shared_memory_ShareableList_pickling(self):
41944195 deserialized_sl , shared_memory .ShareableList )
41954196 self .assertEqual (deserialized_sl [- 1 ], 9 )
41964197 self .assertIsNot (sl , deserialized_sl )
4198+
41974199 deserialized_sl [4 ] = "changed"
41984200 self .assertEqual (sl [4 ], "changed" )
4201+ sl [3 ] = "newvalue"
4202+ self .assertEqual (deserialized_sl [3 ], "newvalue" )
41994203
4200- # Verify data is not being put into the pickled representation.
4201- name = 'a' * len (sl .shm .name )
42024204 larger_sl = shared_memory .ShareableList (range (400 ))
42034205 self .addCleanup (larger_sl .shm .unlink )
42044206 serialized_larger_sl = pickle .dumps (larger_sl , protocol = proto )
@@ -4209,16 +4211,18 @@ def test_shared_memory_ShareableList_pickling(self):
42094211 sl .shm .close ()
42104212
42114213 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 )
42144218
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 ()
42194223
4220- with self .assertRaises (FileNotFoundError ):
4221- pickle .loads (serialized_sl )
4224+ with self .assertRaises (FileNotFoundError ):
4225+ pickle .loads (serialized_sl )
42224226
42234227 def test_shared_memory_cleaned_after_process_termination (self ):
42244228 cmd = '''if 1:
0 commit comments