File tree Expand file tree Collapse file tree 1 file changed +27
-6
lines changed
Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -2106,22 +2106,43 @@ def test__all__(self):
21062106 def test_set_name (self ):
21072107 try :
21082108 get_name = _thread ._get_name
2109- set_name = _thread .set_name
2109+ _thread .set_name
21102110 except AttributeError :
21112111 self .skipTest ("need thread._get_name() and thread.set_name()" )
21122112
2113- work_name = None
21142113 def work ():
21152114 nonlocal work_name
21162115 work_name = get_name ()
21172116
21182117 # name not too long to fit into Linux 15 bytes limit
21192118 name = "CustomName"
2119+ tests = [(name , name )]
21202120
2121- thread = threading .Thread (target = work , name = name )
2122- thread .start ()
2123- thread .join ()
2124- self .assertEqual (work_name , name )
2121+ if sys .platform == "linux" :
2122+ # On Linux, set_name() truncates the name to 15 bytes.
2123+
2124+ # Test ASCII name
2125+ name = "x" * 100
2126+ tests .append ((name , name [:15 ]))
2127+
2128+ # Test non-ASCII name
2129+ name = "x" * 14 + "é€"
2130+ try :
2131+ encoded = os .fsencode (name )
2132+ except UnicodeEncodeError :
2133+ # name cannot be encoded to the filesystem encoding
2134+ pass
2135+ else :
2136+ expected = os .fsdecode (encoded [:15 ])
2137+ tests .append ((name , expected ))
2138+
2139+ for name , expected in tests :
2140+ with self .subTest (name = name , expected = expected ):
2141+ work_name = None
2142+ thread = threading .Thread (target = work , name = name )
2143+ thread .start ()
2144+ thread .join ()
2145+ self .assertEqual (work_name , expected )
21252146
21262147
21272148class InterruptMainTests (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments