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