@@ -3768,6 +3768,18 @@ def test_shared_memory_basics(self):
3768
3768
self .assertGreaterEqual (sms .size , 512 )
3769
3769
self .assertGreaterEqual (len (sms .buf ), sms .size )
3770
3770
3771
+ # Verify __repr__
3772
+ self .assertIn (sms .name , str (sms ))
3773
+ self .assertIn (str (sms .size ), str (sms ))
3774
+
3775
+ # Test pickling
3776
+ sms .buf [0 :6 ] = b'pickle'
3777
+ pickled_sms = pickle .dumps (sms )
3778
+ sms2 = pickle .loads (pickled_sms )
3779
+ self .assertEqual (sms .name , sms2 .name )
3780
+ self .assertEqual (sms .size , sms2 .size )
3781
+ self .assertEqual (bytes (sms .buf [0 :6 ]), bytes (sms2 .buf [0 :6 ]), b'pickle' )
3782
+
3771
3783
# Modify contents of shared memory segment through memoryview.
3772
3784
sms .buf [0 ] = 42
3773
3785
self .assertEqual (sms .buf [0 ], 42 )
@@ -3975,6 +3987,23 @@ def test_shared_memory_ShareableList_basics(self):
3975
3987
)
3976
3988
self .addCleanup (sl .shm .unlink )
3977
3989
3990
+ # Verify __repr__
3991
+ self .assertIn (sl .shm .name , str (sl ))
3992
+ self .assertIn (str (list (sl )), str (sl ))
3993
+
3994
+ # Index Out of Range (get)
3995
+ with self .assertRaises (IndexError ):
3996
+ sl [7 ]
3997
+
3998
+ # Index Out of Range (set)
3999
+ with self .assertRaises (IndexError ):
4000
+ sl [7 ] = 2
4001
+
4002
+ # Assign value without format change (str -> str)
4003
+ current_format = sl ._get_packing_format (0 )
4004
+ sl [0 ] = 'howdy'
4005
+ self .assertEqual (current_format , sl ._get_packing_format (0 ))
4006
+
3978
4007
# Verify attributes are readable.
3979
4008
self .assertEqual (sl .format , '8s8sdqxxxxxx?xxxxxxxx?q' )
3980
4009
0 commit comments