| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2106,22 +2106,43 @@ def test__all__(self): | |||
| 2106 | 2106 | def test_set_name(self): | |
| 2107 | 2107 | try: | |
| 2108 | 2108 | get_name = _thread._get_name | |
| 2109 | - set_name = _thread.set_name | ||
| 2109 | + _thread.set_name | ||
| 2110 | 2110 | except AttributeError: | |
| 2111 | 2111 | self.skipTest("need thread._get_name() and thread.set_name()") | |
| 2112 | 2112 | ||
| 2113 | - work_name = None | ||
| 2114 | 2113 | def work(): | |
| 2115 | 2114 | nonlocal work_name | |
| 2116 | 2115 | work_name = get_name() | |
| 2117 | 2116 | ||
| 2118 | 2117 | # name not too long to fit into Linux 15 bytes limit | |
| 2119 | 2118 | name = "CustomName" | |
| 2119 | + tests = [(name, name)] | ||
| 2120 | 2120 | ||
| 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) | ||
| 2125 | 2146 | ||
| 2126 | 2147 | ||
| 2127 | 2148 | class InterruptMainTests(unittest.TestCase): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments