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

Method test_realpath_broken_symlinks

Lib/test/test_ntpath.py:664–717  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

662 @os_helper.skip_unless_symlink
663 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
664 def test_realpath_broken_symlinks(self):
665 ABSTFN = ntpath.abspath(os_helper.TESTFN)
666 os.mkdir(ABSTFN)
667 self.addCleanup(os_helper.rmtree, ABSTFN)
668
669 with os_helper.change_cwd(ABSTFN):
670 os.mkdir("subdir")
671 os.chdir("subdir")
672 os.symlink(".", "recursive")
673 os.symlink("..", "parent")
674 os.chdir("..")
675 os.symlink(".", "self")
676 os.symlink("missing", "broken")
677 os.symlink(r"broken\bar", "broken1")
678 os.symlink(r"self\self\broken", "broken2")
679 os.symlink(r"subdir\parent\subdir\parent\broken", "broken3")
680 os.symlink(ABSTFN + r"\broken", "broken4")
681 os.symlink(r"recursive\..\broken", "broken5")
682
683 self.assertPathEqual(ntpath.realpath("broken"),
684 ABSTFN + r"\missing")
685 self.assertPathEqual(ntpath.realpath(r"broken\foo"),
686 ABSTFN + r"\missing\foo")
687 # bpo-38453: We no longer recursively resolve segments of relative
688 # symlinks that the OS cannot resolve.
689 self.assertPathEqual(ntpath.realpath(r"broken1"),
690 ABSTFN + r"\broken\bar")
691 self.assertPathEqual(ntpath.realpath(r"broken1\baz"),
692 ABSTFN + r"\broken\bar\baz")
693 self.assertPathEqual(ntpath.realpath("broken2"),
694 ABSTFN + r"\self\self\missing")
695 self.assertPathEqual(ntpath.realpath("broken3"),
696 ABSTFN + r"\subdir\parent\subdir\parent\missing")
697 self.assertPathEqual(ntpath.realpath("broken4"),
698 ABSTFN + r"\missing")
699 self.assertPathEqual(ntpath.realpath("broken5"),
700 ABSTFN + r"\missing")
701
702 self.assertPathEqual(ntpath.realpath(b"broken"),
703 os.fsencode(ABSTFN + r"\missing"))
704 self.assertPathEqual(ntpath.realpath(rb"broken\foo"),
705 os.fsencode(ABSTFN + r"\missing\foo"))
706 self.assertPathEqual(ntpath.realpath(rb"broken1"),
707 os.fsencode(ABSTFN + r"\broken\bar"))
708 self.assertPathEqual(ntpath.realpath(rb"broken1\baz"),
709 os.fsencode(ABSTFN + r"\broken\bar\baz"))
710 self.assertPathEqual(ntpath.realpath(b"broken2"),
711 os.fsencode(ABSTFN + r"\self\self\missing"))
712 self.assertPathEqual(ntpath.realpath(rb"broken3"),
713 os.fsencode(ABSTFN + r"\subdir\parent\subdir\parent\missing"))
714 self.assertPathEqual(ntpath.realpath(b"broken4"),
715 os.fsencode(ABSTFN + r"\missing"))
716 self.assertPathEqual(ntpath.realpath(b"broken5"),
717 os.fsencode(ABSTFN + r"\missing"))
718
719 @os_helper.skip_unless_symlink
720 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')

Callers

nothing calls this directly

Calls 5

addCleanupMethod · 0.80
abspathMethod · 0.45
mkdirMethod · 0.45
assertPathEqualMethod · 0.45
realpathMethod · 0.45

Tested by

no test coverage detected