MCPcopy Index your code
hub / github.com/python/cpython / test_expanduser_pwd2

Method test_expanduser_pwd2

Lib/test/test_posixpath.py:363–384  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

shuffleMethod · 0.80
isasciiMethod · 0.80
expanduserMethod · 0.80
import_moduleMethod · 0.45
sortMethod · 0.45
rstripMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected