Skip to content

Commit d93263f

Browse files
Unindent tests.
1 parent 0e2484a commit d93263f

File tree

2 files changed

+239
-240
lines changed

2 files changed

+239
-240
lines changed

Lib/test/test_ntpath.py

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -832,130 +832,130 @@ def test_realpath_permission(self):
832832
self.assertPathEqual(test_file, ntpath.realpath(test_file_short))
833833

834834
@os_helper.skip_unless_symlink
835+
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
835836
def test_realpath_mode(self):
836837
realpath = ntpath.realpath
837838
ALL_BUT_LAST = ntpath.ALL_BUT_LAST
838839
ABSTFN = ntpath.abspath(os_helper.TESTFN)
839-
try:
840-
os.mkdir(ABSTFN)
841-
os.mkdir(ABSTFN + "\\dir")
842-
open(ABSTFN + "\\file", "wb").close()
843-
open(ABSTFN + "\\dir\\file2", "wb").close()
844-
os.symlink("file", ABSTFN + "\\link")
845-
os.symlink("dir", ABSTFN + "\\link2")
846-
os.symlink("nonexistent", ABSTFN + "\\broken")
847-
os.symlink("cycle", ABSTFN + "\\cycle")
848-
def check(path, mode, expected, errno=None):
849-
path = path.replace('/', '\\')
850-
if isinstance(expected, str):
851-
assert errno is None
852-
self.assertEqual(realpath(path, strict=mode), ABSTFN + expected.replace('/', '\\'))
853-
else:
854-
with self.assertRaises(expected) as cm:
855-
realpath(path, strict=mode)
856-
if errno is not None:
857-
self.assertEqual(cm.exception.errno, errno)
858-
859-
with os_helper.change_cwd(ABSTFN):
860-
check("file", False, "/file")
861-
check("file", ALL_BUT_LAST, "/file")
862-
check("file", True, "/file")
863-
check("file/", False, "/file")
864-
# check("file/", ALL_BUT_LAST, NotADirectoryError)
865-
# check("file/", True, NotADirectoryError)
866-
check("file/file2", False, "/file/file2")
867-
# check("file/file2", ALL_BUT_LAST, NotADirectoryError)
868-
# check("file/file2", True, NotADirectoryError)
869-
check("file/.", False, "/file")
870-
# check("file/.", ALL_BUT_LAST, NotADirectoryError)
871-
# check("file/.", True, NotADirectoryError)
872-
check("file/../link2", False, "/dir")
873-
check("file/../link2", ALL_BUT_LAST, "/dir")
874-
check("file/../link2", True, "/dir")
875-
876-
check("dir", False, "/dir")
877-
check("dir", ALL_BUT_LAST, "/dir")
878-
check("dir", True, "/dir")
879-
check("dir/", False, "/dir")
880-
check("dir/", ALL_BUT_LAST, "/dir")
881-
check("dir/", True, "/dir")
882-
check("dir/file2", False, "/dir/file2")
883-
check("dir/file2", ALL_BUT_LAST, "/dir/file2")
884-
check("dir/file2", True, "/dir/file2")
885-
886-
check("link", False, "/file")
887-
check("link", ALL_BUT_LAST, "/file")
888-
check("link", True, "/file")
889-
check("link/", False, "/file")
890-
# check("link/", ALL_BUT_LAST, NotADirectoryError)
891-
# check("link/", True, NotADirectoryError)
892-
check("link/file2", False, "/file/file2")
893-
# check("link/file2", ALL_BUT_LAST, NotADirectoryError)
894-
# check("link/file2", True, NotADirectoryError)
895-
check("link/.", False, "/file")
896-
# check("link/.", ALL_BUT_LAST, NotADirectoryError)
897-
# check("link/.", True, NotADirectoryError)
898-
check("link/../link", False, "/file")
899-
check("link/../link", ALL_BUT_LAST, "/file")
900-
check("link/../link", True, "/file")
901-
902-
check("link2", False, "/dir")
903-
check("link2", ALL_BUT_LAST, "/dir")
904-
check("link2", True, "/dir")
905-
check("link2/", False, "/dir")
906-
check("link2/", ALL_BUT_LAST, "/dir")
907-
check("link2/", True, "/dir")
908-
check("link2/file2", False, "/dir/file2")
909-
check("link2/file2", ALL_BUT_LAST, "/dir/file2")
910-
check("link2/file2", True, "/dir/file2")
911-
912-
check("nonexistent", False, "/nonexistent")
913-
check("nonexistent", ALL_BUT_LAST, "/nonexistent")
914-
check("nonexistent", True, FileNotFoundError)
915-
check("nonexistent/", False, "/nonexistent")
916-
check("nonexistent/", ALL_BUT_LAST, "/nonexistent")
917-
check("nonexistent/", True, FileNotFoundError)
918-
check("nonexistent/file", False, "/nonexistent/file")
919-
check("nonexistent/file", ALL_BUT_LAST, FileNotFoundError)
920-
check("nonexistent/file", True, FileNotFoundError)
921-
check("nonexistent/../link", False, "/file")
922-
check("nonexistent/../link", ALL_BUT_LAST, "/file")
923-
check("nonexistent/../link", True, "/file")
924-
925-
check("broken", False, "/nonexistent")
926-
check("broken", ALL_BUT_LAST, "/nonexistent")
927-
check("broken", True, FileNotFoundError)
928-
check("broken/", False, "/nonexistent")
929-
check("broken/", ALL_BUT_LAST, "/nonexistent")
930-
check("broken/", True, FileNotFoundError)
931-
check("broken/file", False, "/nonexistent/file")
932-
check("broken/file", ALL_BUT_LAST, FileNotFoundError)
933-
check("broken/file", True, FileNotFoundError)
934-
check("broken/../link", False, "/file")
935-
check("broken/../link", ALL_BUT_LAST, "/file")
936-
check("broken/../link", True, "/file")
937-
938-
check("cycle", False, "/cycle")
939-
check("cycle", ALL_BUT_LAST, OSError, errno.EINVAL)
940-
check("cycle", True, OSError, errno.EINVAL)
941-
check("cycle/", False, "/cycle")
942-
check("cycle/", ALL_BUT_LAST, OSError, errno.EINVAL)
943-
check("cycle/", True, OSError, errno.EINVAL)
944-
check("cycle/file", False, "/cycle/file")
945-
check("cycle/file", ALL_BUT_LAST, OSError, errno.EINVAL)
946-
check("cycle/file", True, OSError, errno.EINVAL)
947-
check("cycle/../link", False, "/file")
948-
check("cycle/../link", ALL_BUT_LAST, "/file")
949-
check("cycle/../link", True, "/file")
950-
finally:
951-
os_helper.unlink(ABSTFN + "/file")
952-
os_helper.unlink(ABSTFN + "/dir/file2")
953-
os_helper.unlink(ABSTFN + "/link")
954-
os_helper.unlink(ABSTFN + "/link2")
955-
os_helper.unlink(ABSTFN + "/broken")
956-
os_helper.unlink(ABSTFN + "/cycle")
957-
os_helper.rmdir(ABSTFN + "/dir")
958-
os_helper.rmdir(ABSTFN)
840+
self.addCleanup(os_helper.rmdir, ABSTFN)
841+
self.addCleanup(os_helper.rmdir, ABSTFN + "/dir")
842+
self.addCleanup(os_helper.unlink, ABSTFN + "/file")
843+
self.addCleanup(os_helper.unlink, ABSTFN + "/dir/file2")
844+
self.addCleanup(os_helper.unlink, ABSTFN + "/link")
845+
self.addCleanup(os_helper.unlink, ABSTFN + "/link2")
846+
self.addCleanup(os_helper.unlink, ABSTFN + "/broken")
847+
self.addCleanup(os_helper.unlink, ABSTFN + "/cycle")
848+
849+
os.mkdir(ABSTFN)
850+
os.mkdir(ABSTFN + "\\dir")
851+
open(ABSTFN + "\\file", "wb").close()
852+
open(ABSTFN + "\\dir\\file2", "wb").close()
853+
os.symlink("file", ABSTFN + "\\link")
854+
os.symlink("dir", ABSTFN + "\\link2")
855+
os.symlink("nonexistent", ABSTFN + "\\broken")
856+
os.symlink("cycle", ABSTFN + "\\cycle")
857+
def check(path, mode, expected, errno=None):
858+
path = path.replace('/', '\\')
859+
if isinstance(expected, str):
860+
assert errno is None
861+
self.assertEqual(realpath(path, strict=mode), ABSTFN + expected.replace('/', '\\'))
862+
else:
863+
with self.assertRaises(expected) as cm:
864+
realpath(path, strict=mode)
865+
if errno is not None:
866+
self.assertEqual(cm.exception.errno, errno)
867+
868+
self.enterContext(os_helper.change_cwd(ABSTFN))
869+
check("file", False, "/file")
870+
check("file", ALL_BUT_LAST, "/file")
871+
check("file", True, "/file")
872+
check("file/", False, "/file")
873+
# check("file/", ALL_BUT_LAST, NotADirectoryError)
874+
# check("file/", True, NotADirectoryError)
875+
check("file/file2", False, "/file/file2")
876+
# check("file/file2", ALL_BUT_LAST, NotADirectoryError)
877+
# check("file/file2", True, NotADirectoryError)
878+
check("file/.", False, "/file")
879+
# check("file/.", ALL_BUT_LAST, NotADirectoryError)
880+
# check("file/.", True, NotADirectoryError)
881+
check("file/../link2", False, "/dir")
882+
check("file/../link2", ALL_BUT_LAST, "/dir")
883+
check("file/../link2", True, "/dir")
884+
885+
check("dir", False, "/dir")
886+
check("dir", ALL_BUT_LAST, "/dir")
887+
check("dir", True, "/dir")
888+
check("dir/", False, "/dir")
889+
check("dir/", ALL_BUT_LAST, "/dir")
890+
check("dir/", True, "/dir")
891+
check("dir/file2", False, "/dir/file2")
892+
check("dir/file2", ALL_BUT_LAST, "/dir/file2")
893+
check("dir/file2", True, "/dir/file2")
894+
895+
check("link", False, "/file")
896+
check("link", ALL_BUT_LAST, "/file")
897+
check("link", True, "/file")
898+
check("link/", False, "/file")
899+
# check("link/", ALL_BUT_LAST, NotADirectoryError)
900+
# check("link/", True, NotADirectoryError)
901+
check("link/file2", False, "/file/file2")
902+
# check("link/file2", ALL_BUT_LAST, NotADirectoryError)
903+
# check("link/file2", True, NotADirectoryError)
904+
check("link/.", False, "/file")
905+
# check("link/.", ALL_BUT_LAST, NotADirectoryError)
906+
# check("link/.", True, NotADirectoryError)
907+
check("link/../link", False, "/file")
908+
check("link/../link", ALL_BUT_LAST, "/file")
909+
check("link/../link", True, "/file")
910+
911+
check("link2", False, "/dir")
912+
check("link2", ALL_BUT_LAST, "/dir")
913+
check("link2", True, "/dir")
914+
check("link2/", False, "/dir")
915+
check("link2/", ALL_BUT_LAST, "/dir")
916+
check("link2/", True, "/dir")
917+
check("link2/file2", False, "/dir/file2")
918+
check("link2/file2", ALL_BUT_LAST, "/dir/file2")
919+
check("link2/file2", True, "/dir/file2")
920+
921+
check("nonexistent", False, "/nonexistent")
922+
check("nonexistent", ALL_BUT_LAST, "/nonexistent")
923+
check("nonexistent", True, FileNotFoundError)
924+
check("nonexistent/", False, "/nonexistent")
925+
check("nonexistent/", ALL_BUT_LAST, "/nonexistent")
926+
check("nonexistent/", True, FileNotFoundError)
927+
check("nonexistent/file", False, "/nonexistent/file")
928+
check("nonexistent/file", ALL_BUT_LAST, FileNotFoundError)
929+
check("nonexistent/file", True, FileNotFoundError)
930+
check("nonexistent/../link", False, "/file")
931+
check("nonexistent/../link", ALL_BUT_LAST, "/file")
932+
check("nonexistent/../link", True, "/file")
933+
934+
check("broken", False, "/nonexistent")
935+
check("broken", ALL_BUT_LAST, "/nonexistent")
936+
check("broken", True, FileNotFoundError)
937+
check("broken/", False, "/nonexistent")
938+
check("broken/", ALL_BUT_LAST, "/nonexistent")
939+
check("broken/", True, FileNotFoundError)
940+
check("broken/file", False, "/nonexistent/file")
941+
check("broken/file", ALL_BUT_LAST, FileNotFoundError)
942+
check("broken/file", True, FileNotFoundError)
943+
check("broken/../link", False, "/file")
944+
check("broken/../link", ALL_BUT_LAST, "/file")
945+
check("broken/../link", True, "/file")
946+
947+
check("cycle", False, "/cycle")
948+
check("cycle", ALL_BUT_LAST, OSError, errno.EINVAL)
949+
check("cycle", True, OSError, errno.EINVAL)
950+
check("cycle/", False, "/cycle")
951+
check("cycle/", ALL_BUT_LAST, OSError, errno.EINVAL)
952+
check("cycle/", True, OSError, errno.EINVAL)
953+
check("cycle/file", False, "/cycle/file")
954+
check("cycle/file", ALL_BUT_LAST, OSError, errno.EINVAL)
955+
check("cycle/file", True, OSError, errno.EINVAL)
956+
check("cycle/../link", False, "/file")
957+
check("cycle/../link", ALL_BUT_LAST, "/file")
958+
check("cycle/../link", True, "/file")
959959

960960
def test_expandvars(self):
961961
with os_helper.EnvironmentVarGuard() as env:

0 commit comments

Comments
 (0)