@@ -3705,6 +3705,18 @@ def test_shared_memory_basics(self):
3705
3705
self .assertGreaterEqual (sms .size , 512 )
3706
3706
self .assertGreaterEqual (len (sms .buf ), sms .size )
3707
3707
3708
+ # Verify __repr__
3709
+ self .assertIn (sms .name , str (sms ))
3710
+ self .assertIn (str (sms .size ), str (sms ))
3711
+
3712
+ # Test pickling
3713
+ sms .buf [0 :6 ] = b'pickle'
3714
+ pickled_sms = pickle .dumps (sms )
3715
+ sms2 = pickle .loads (pickled_sms )
3716
+ self .assertEqual (sms .name , sms2 .name )
3717
+ self .assertEqual (sms .size , sms2 .size )
3718
+ self .assertEqual (bytes (sms .buf [0 :6 ]), bytes (sms2 .buf [0 :6 ]), b'pickle' )
3719
+
3708
3720
# Modify contents of shared memory segment through memoryview.
3709
3721
sms .buf [0 ] = 42
3710
3722
self .assertEqual (sms .buf [0 ], 42 )
@@ -3910,6 +3922,23 @@ def test_shared_memory_ShareableList_basics(self):
3910
3922
)
3911
3923
self .addCleanup (sl .shm .unlink )
3912
3924
3925
+ # Verify __repr__
3926
+ self .assertIn (sl .shm .name , str (sl ))
3927
+ self .assertIn (str (list (sl )), str (sl ))
3928
+
3929
+ # Index Out of Range (get)
3930
+ with self .assertRaises (IndexError ):
3931
+ sl [7 ]
3932
+
3933
+ # Index Out of Range (set)
3934
+ with self .assertRaises (IndexError ):
3935
+ sl [7 ] = 2
3936
+
3937
+ # Assign value without format change (str -> str)
3938
+ current_format = sl ._get_packing_format (0 )
3939
+ sl [0 ] = 'howdy'
3940
+ self .assertEqual (current_format , sl ._get_packing_format (0 ))
3941
+
3913
3942
# Verify attributes are readable.
3914
3943
self .assertEqual (sl .format , '8s8sdqxxxxxx?xxxxxxxx?q' )
3915
3944
0 commit comments