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

Method test_realpath_symlink_loops_strict

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

Source from the content-addressed store, hash-verified

766 @os_helper.skip_unless_symlink
767 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
768 def test_realpath_symlink_loops_strict(self):
769 # Symlink loops raise OSError in strict mode
770 ABSTFN = ntpath.abspath(os_helper.TESTFN)
771 self.addCleanup(os_helper.unlink, ABSTFN)
772 self.addCleanup(os_helper.unlink, ABSTFN + "1")
773 self.addCleanup(os_helper.unlink, ABSTFN + "2")
774 self.addCleanup(os_helper.unlink, ABSTFN + "y")
775 self.addCleanup(os_helper.unlink, ABSTFN + "c")
776 self.addCleanup(os_helper.unlink, ABSTFN + "a")
777
778 os.symlink(ABSTFN, ABSTFN)
779 self.assertRaises(OSError, ntpath.realpath, ABSTFN, strict=ALL_BUT_LAST)
780 self.assertRaises(OSError, ntpath.realpath, ABSTFN, strict=True)
781
782 os.symlink(ABSTFN + "1", ABSTFN + "2")
783 os.symlink(ABSTFN + "2", ABSTFN + "1")
784 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1", strict=ALL_BUT_LAST)
785 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1", strict=True)
786 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2", strict=ALL_BUT_LAST)
787 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2", strict=True)
788 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x", strict=ALL_BUT_LAST)
789 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x", strict=True)
790 # Windows eliminates '..' components before resolving links, so the
791 # following call is not expected to raise.
792 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..", strict=ALL_BUT_LAST),
793 ntpath.dirname(ABSTFN))
794 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..", strict=True),
795 ntpath.dirname(ABSTFN))
796 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\x", strict=ALL_BUT_LAST),
797 ntpath.dirname(ABSTFN) + "\\x")
798 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\x", strict=True)
799 os.symlink(ABSTFN + "x", ABSTFN + "y")
800 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\"
801 + ntpath.basename(ABSTFN) + "y",
802 strict=ALL_BUT_LAST),
803 ABSTFN + "x")
804 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\"
805 + ntpath.basename(ABSTFN) + "y",
806 strict=True)
807 self.assertRaises(OSError, ntpath.realpath,
808 ABSTFN + "1\\..\\" + ntpath.basename(ABSTFN) + "1",
809 strict=ALL_BUT_LAST)
810 self.assertRaises(OSError, ntpath.realpath,
811 ABSTFN + "1\\..\\" + ntpath.basename(ABSTFN) + "1",
812 strict=True)
813
814 os.symlink(ntpath.basename(ABSTFN) + "a\\b", ABSTFN + "a")
815 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "a", strict=ALL_BUT_LAST)
816 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "a", strict=True)
817
818 os.symlink("..\\" + ntpath.basename(ntpath.dirname(ABSTFN))
819 + "\\" + ntpath.basename(ABSTFN) + "c", ABSTFN + "c")
820 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "c", strict=ALL_BUT_LAST)
821 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "c", strict=True)
822
823 # Test using relative path as well.
824 self.assertRaises(OSError, ntpath.realpath, ntpath.basename(ABSTFN),
825 strict=ALL_BUT_LAST)

Callers

nothing calls this directly

Calls 7

addCleanupMethod · 0.80
abspathMethod · 0.45
assertRaisesMethod · 0.45
assertPathEqualMethod · 0.45
realpathMethod · 0.45
dirnameMethod · 0.45
basenameMethod · 0.45

Tested by

no test coverage detected