@@ -1165,6 +1165,35 @@ def test_flush_parameters(self):
11651165 m .flush (PAGESIZE )
11661166 m .flush (PAGESIZE , PAGESIZE )
11671167
1168+ @unittest .skipUnless (hasattr (mmap , 'MAP_ANONYMOUS' ), 'requires MAP_ANONYMOUS' )
1169+ def test_set_name (self ):
1170+ # Test setting name on anonymous mmap
1171+ m = mmap .mmap (- 1 , PAGESIZE )
1172+ self .addCleanup (m .close )
1173+ result = m .set_name ('test_mapping' )
1174+ self .assertIsNone (result )
1175+
1176+ # Test name length limit (80 chars including prefix "cpython:mmap:")
1177+ # Prefix is 13 chars, so max name is 67 chars
1178+ long_name = 'x' * 30
1179+ result = m .set_name (long_name )
1180+ self .assertIsNone (result )
1181+
1182+ # Test name too long
1183+ too_long_name = 'x' * 80
1184+ with self .assertRaises (ValueError ):
1185+ m .set_name (too_long_name )
1186+
1187+ # Test that file-backed mmap raises error
1188+ with open (TESTFN , 'wb+' ) as f :
1189+ f .write (b'x' * PAGESIZE )
1190+ f .flush ()
1191+ m2 = mmap .mmap (f .fileno (), PAGESIZE )
1192+ self .addCleanup (m2 .close )
1193+
1194+ with self .assertRaises (ValueError ):
1195+ m2 .set_name ('should_fail' )
1196+
11681197
11691198class LargeMmapTests (unittest .TestCase ):
11701199
0 commit comments