MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_expanduser_pwd2

Method test_expanduser_pwd2

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

Source from the content-addressed store, hash-verified

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 ("", "."),

Callers

nothing calls this directly

Calls 11

getpwallFunction · 0.85
lenFunction · 0.85
shuffleMethod · 0.80
subTestMethod · 0.80
expanduserMethod · 0.80
fsencodeMethod · 0.80
import_moduleMethod · 0.45
sortMethod · 0.45
isasciiMethod · 0.45
rstripMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected