(self)
| 360 | @unittest.skipIf(sys.platform == "vxworks", |
| 361 | "no home directory on VxWorks") |
| 362 | def test_expanduser_pwd2(self): |
| 363 | pwd = import_helper.import_module('pwd') |
| 364 | getpwall = support.get_attribute(pwd, 'getpwall') |
| 365 | names = [entry.pw_name for entry in getpwall()] |
| 366 | maxusers = 1000 if support.is_resource_enabled('cpu') else 100 |
| 367 | if len(names) > maxusers: |
| 368 | # Select random names, half of them with non-ASCII name, |
| 369 | # if available. |
| 370 | random.shuffle(names) |
| 371 | names.sort(key=lambda name: name.isascii()) |
| 372 | del names[maxusers//2:-maxusers//2] |
| 373 | for name in names: |
| 374 | # gh-121200: pw_dir can be different between getpwall() and |
| 375 | # getpwnam(), so use getpwnam() pw_dir as expanduser() does. |
| 376 | entry = pwd.getpwnam(name) |
| 377 | home = entry.pw_dir |
| 378 | home = home.rstrip('/') or '/' |
| 379 | |
| 380 | with self.subTest(name=name, pw_dir=entry.pw_dir): |
| 381 | self.assertEqual(posixpath.expanduser('~' + name), home) |
| 382 | self.assertEqual(posixpath.expanduser(os.fsencode('~' + name)), |
| 383 | os.fsencode(home)) |
| 384 | |
| 385 | NORMPATH_CASES = [ |
| 386 | ("", "."), |
nothing calls this directly
no test coverage detected