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

Method test_realpath_basic

Lib/test/test_ntpath.py:550–574  ·  view source on GitHub ↗
(self, kwargs)

Source from the content-addressed store, hash-verified

548 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
549 @_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
550 def test_realpath_basic(self, kwargs):
551 ABSTFN = ntpath.abspath(os_helper.TESTFN)
552 open(ABSTFN, "wb").close()
553 self.addCleanup(os_helper.unlink, ABSTFN)
554 self.addCleanup(os_helper.unlink, ABSTFN + "1")
555
556 os.symlink(ABSTFN, ABSTFN + "1")
557 self.assertPathEqual(ntpath.realpath(ABSTFN + "1", **kwargs), ABSTFN)
558 self.assertPathEqual(ntpath.realpath(os.fsencode(ABSTFN + "1"), **kwargs),
559 os.fsencode(ABSTFN))
560
561 # gh-88013: call ntpath.realpath with binary drive name may raise a
562 # TypeError. The drive should not exist to reproduce the bug.
563 drives = {f"{c}:\\" for c in string.ascii_uppercase} - set(os.listdrives())
564 d = drives.pop().encode()
565 self.assertEqual(ntpath.realpath(d, strict=False), d)
566
567 # gh-106242: Embedded nulls and non-strict fallback to abspath
568 if kwargs:
569 with self.assertRaises(OSError):
570 ntpath.realpath(os_helper.TESTFN + "\0spam",
571 **kwargs)
572 else:
573 self.assertEqual(ABSTFN + "\0spam",
574 ntpath.realpath(os_helper.TESTFN + "\0spam", **kwargs))
575
576 @os_helper.skip_unless_symlink
577 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')

Callers

nothing calls this directly

Calls 11

setFunction · 0.85
addCleanupMethod · 0.80
openFunction · 0.50
abspathMethod · 0.45
closeMethod · 0.45
assertPathEqualMethod · 0.45
realpathMethod · 0.45
encodeMethod · 0.45
popMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected