(self)
| 829 | @os_helper.skip_unless_symlink |
| 830 | @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname') |
| 831 | def test_realpath_symlink_loops_raise(self): |
| 832 | # Symlink loops raise OSError in ALLOW_MISSING mode |
| 833 | ABSTFN = ntpath.abspath(os_helper.TESTFN) |
| 834 | self.addCleanup(os_helper.unlink, ABSTFN) |
| 835 | self.addCleanup(os_helper.unlink, ABSTFN + "1") |
| 836 | self.addCleanup(os_helper.unlink, ABSTFN + "2") |
| 837 | self.addCleanup(os_helper.unlink, ABSTFN + "y") |
| 838 | self.addCleanup(os_helper.unlink, ABSTFN + "c") |
| 839 | self.addCleanup(os_helper.unlink, ABSTFN + "a") |
| 840 | self.addCleanup(os_helper.unlink, ABSTFN + "x") |
| 841 | |
| 842 | os.symlink(ABSTFN, ABSTFN) |
| 843 | self.assertRaises(OSError, ntpath.realpath, ABSTFN, strict=ALLOW_MISSING) |
| 844 | |
| 845 | os.symlink(ABSTFN + "1", ABSTFN + "2") |
| 846 | os.symlink(ABSTFN + "2", ABSTFN + "1") |
| 847 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1", |
| 848 | strict=ALLOW_MISSING) |
| 849 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2", |
| 850 | strict=ALLOW_MISSING) |
| 851 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x", |
| 852 | strict=ALLOW_MISSING) |
| 853 | |
| 854 | # Windows eliminates '..' components before resolving links; |
| 855 | # realpath is not expected to raise if this removes the loop. |
| 856 | self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\.."), |
| 857 | ntpath.dirname(ABSTFN)) |
| 858 | self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\x"), |
| 859 | ntpath.dirname(ABSTFN) + "\\x") |
| 860 | |
| 861 | os.symlink(ABSTFN + "x", ABSTFN + "y") |
| 862 | self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\" |
| 863 | + ntpath.basename(ABSTFN) + "y"), |
| 864 | ABSTFN + "x") |
| 865 | self.assertRaises( |
| 866 | OSError, ntpath.realpath, |
| 867 | ABSTFN + "1\\..\\" + ntpath.basename(ABSTFN) + "1", |
| 868 | strict=ALLOW_MISSING) |
| 869 | |
| 870 | os.symlink(ntpath.basename(ABSTFN) + "a\\b", ABSTFN + "a") |
| 871 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "a", |
| 872 | strict=ALLOW_MISSING) |
| 873 | |
| 874 | os.symlink("..\\" + ntpath.basename(ntpath.dirname(ABSTFN)) |
| 875 | + "\\" + ntpath.basename(ABSTFN) + "c", ABSTFN + "c") |
| 876 | self.assertRaises(OSError, ntpath.realpath, ABSTFN + "c", |
| 877 | strict=ALLOW_MISSING) |
| 878 | |
| 879 | # Test using relative path as well. |
| 880 | self.assertRaises(OSError, ntpath.realpath, ntpath.basename(ABSTFN), |
| 881 | strict=ALLOW_MISSING) |
| 882 | |
| 883 | @os_helper.skip_unless_symlink |
| 884 | @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname') |
nothing calls this directly
no test coverage detected