(self)
| 800 | @os_helper.skip_unless_symlink |
| 801 | @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname') |
| 802 | def test_realpath_symlink_loops_raise(self): |
| 803 | # Symlink loops raise OSError in ALLOW_MISSING mode |
| 804 | ABSTFN = ntpath.abspath(os_helper.TESTFN) |
| 805 | self.addCleanup(os_helper.unlink, ABSTFN) |
| 806 | self.addCleanup(os_helper.unlink, ABSTFN + "1") |
| 807 | self.addCleanup(os_helper.unlink, ABSTFN + "2") |
| 808 | self.addCleanup(os_helper.unlink, ABSTFN + "y") |
| 809 | self.addCleanup(os_helper.unlink, ABSTFN + "c") |
| 810 | self.addCleanup(os_helper.unlink, ABSTFN + "a") |
| 811 | self.addCleanup(os_helper.unlink, ABSTFN + "x") |
| 812 | |
| 813 | os.symlink(ABSTFN, ABSTFN) |
| 814 | self.assertRaises(OSError, ntpath.realpath, ABSTFN, strict=ALLOW_MISSING) |
| 815 | |
| 816 | os.symlink(ABSTFN + "1", ABSTFN + "2") |
| 817 | os.symlink(ABSTFN + "2", ABSTFN + "1") |
| 818 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1", |
| 819 | strict=ALLOW_MISSING) |
| 820 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2", |
| 821 | strict=ALLOW_MISSING) |
| 822 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x", |
| 823 | strict=ALLOW_MISSING) |
| 824 | |
| 825 | # Windows eliminates '..' components before resolving links; |
| 826 | # realpath is not expected to raise if this removes the loop. |
| 827 | self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\.."), |
| 828 | ntpath.dirname(ABSTFN)) |
| 829 | self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\x"), |
| 830 | ntpath.dirname(ABSTFN) + "\\x") |
| 831 | |
| 832 | os.symlink(ABSTFN + "x", ABSTFN + "y") |
| 833 | self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\" |
| 834 | + ntpath.basename(ABSTFN) + "y"), |
| 835 | ABSTFN + "x") |
| 836 | self.assertRaises( |
| 837 | OSError, ntpath.realpath, |
| 838 | ABSTFN + "1\\..\\" + ntpath.basename(ABSTFN) + "1", |
| 839 | strict=ALLOW_MISSING) |
| 840 | |
| 841 | os.symlink(ntpath.basename(ABSTFN) + "a\\b", ABSTFN + "a") |
| 842 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "a", |
| 843 | strict=ALLOW_MISSING) |
| 844 | |
| 845 | os.symlink("..\\" + ntpath.basename(ntpath.dirname(ABSTFN)) |
| 846 | + "\\" + ntpath.basename(ABSTFN) + "c", ABSTFN + "c") |
| 847 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "c", |
| 848 | strict=ALLOW_MISSING) |
| 849 | |
| 850 | # Test using relative path as well. |
| 851 | self.assertRaises(OSError, ntpath.realpath, ntpath.basename(ABSTFN), |
| 852 | strict=ALLOW_MISSING) |
| 853 | |
| 854 | @os_helper.skip_unless_symlink |
| 855 | @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname') |
nothing calls this directly
no test coverage detected