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

Method test_expanduser_pwd

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

Source from the content-addressed store, hash-verified

319 @unittest.skipIf(sys.platform == "vxworks",
320 "no home directory on VxWorks")
321 def test_expanduser_pwd(self):
322 pwd = import_helper.import_module('pwd')
323
324 self.assertIsInstance(posixpath.expanduser("~/"), str)
325 self.assertIsInstance(posixpath.expanduser(b"~/"), bytes)
326
327 # if home directory == root directory, this test makes no sense
328 if posixpath.expanduser("~") != '/':
329 self.assertEqual(
330 posixpath.expanduser("~") + "/",
331 posixpath.expanduser("~/")
332 )
333 self.assertEqual(
334 posixpath.expanduser(b"~") + b"/",
335 posixpath.expanduser(b"~/")
336 )
337 self.assertIsInstance(posixpath.expanduser("~root/"), str)
338 self.assertIsInstance(posixpath.expanduser("~foo/"), str)
339 self.assertIsInstance(posixpath.expanduser(b"~root/"), bytes)
340 self.assertIsInstance(posixpath.expanduser(b"~foo/"), bytes)
341
342 with os_helper.EnvironmentVarGuard() as env:
343 # expanduser should fall back to using the password database
344 del env['HOME']
345
346 home = pwd.getpwuid(os.getuid()).pw_dir
347 # $HOME can end with a trailing /, so strip it (see #17809)
348 home = home.rstrip("/") or '/'
349 self.assertEqual(posixpath.expanduser("~"), home)
350
351 # bpo-10496: If the HOME environment variable is not set and the
352 # user (current identifier or name in the path) doesn't exist in
353 # the password database (pwd.getuid() or pwd.getpwnam() fail),
354 # expanduser() must return the path unchanged.
355 with mock.patch.object(pwd, 'getpwuid', side_effect=KeyError), \
356 mock.patch.object(pwd, 'getpwnam', side_effect=KeyError):
357 for path in ('~', '~/.local', '~vstinner/'):
358 self.assertEqual(posixpath.expanduser(path), path)
359
360 @unittest.skipIf(sys.platform == "vxworks",
361 "no home directory on VxWorks")

Callers

nothing calls this directly

Calls 5

assertIsInstanceMethod · 0.80
expanduserMethod · 0.80
import_moduleMethod · 0.45
assertEqualMethod · 0.45
rstripMethod · 0.45

Tested by

no test coverage detected