Skip to content

Commit c03cf4b

Browse files
Add more tests.
1 parent 91338d6 commit c03cf4b

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

Lib/test/test_ntpath.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,6 @@ def test_realpath_permission(self):
10191019
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
10201020
def test_realpath_mode(self):
10211021
realpath = ntpath.realpath
1022-
ALL_BUT_LAST = ntpath.ALL_BUT_LAST
10231022
ABSTFN = ntpath.abspath(os_helper.TESTFN)
10241023
self.addCleanup(os_helper.rmdir, ABSTFN)
10251024
self.addCleanup(os_helper.rmdir, ABSTFN + "/dir")
@@ -1052,93 +1051,121 @@ def check(path, mode, expected, errno=None):
10521051

10531052
self.enterContext(os_helper.change_cwd(ABSTFN))
10541053
check("file", False, "/file")
1054+
check("file", ALLOW_MISSING, "/file")
10551055
check("file", ALL_BUT_LAST, "/file")
10561056
check("file", True, "/file")
10571057
check("file/", False, "/file")
1058+
check("file/", ALLOW_MISSING, "/file")
10581059
check("file/", ALL_BUT_LAST, "/file")
10591060
check("file/", True, "/file")
10601061
check("file/file2", False, "/file/file2")
1062+
check("file/file2", ALLOW_MISSING, FileNotFoundError)
10611063
check("file/file2", ALL_BUT_LAST, FileNotFoundError)
10621064
check("file/file2", True, FileNotFoundError)
10631065
check("file/.", False, "/file")
1066+
check("file/.", ALLOW_MISSING, "/file")
10641067
check("file/.", ALL_BUT_LAST, "/file")
10651068
check("file/.", True, "/file")
10661069
check("file/../link2", False, "/dir")
1070+
check("file/../link2", ALLOW_MISSING, "/dir")
10671071
check("file/../link2", ALL_BUT_LAST, "/dir")
10681072
check("file/../link2", True, "/dir")
10691073

10701074
check("dir", False, "/dir")
1075+
check("dir", ALLOW_MISSING, "/dir")
10711076
check("dir", ALL_BUT_LAST, "/dir")
10721077
check("dir", True, "/dir")
10731078
check("dir/", False, "/dir")
1079+
check("dir/", ALLOW_MISSING, "/dir")
10741080
check("dir/", ALL_BUT_LAST, "/dir")
10751081
check("dir/", True, "/dir")
10761082
check("dir/file2", False, "/dir/file2")
1083+
check("dir/file2", ALLOW_MISSING, "/dir/file2")
10771084
check("dir/file2", ALL_BUT_LAST, "/dir/file2")
10781085
check("dir/file2", True, "/dir/file2")
10791086

10801087
check("link", False, "/file")
1088+
check("link", ALLOW_MISSING, "/file")
10811089
check("link", ALL_BUT_LAST, "/file")
10821090
check("link", True, "/file")
10831091
check("link/", False, "/file")
1092+
check("link/", ALLOW_MISSING, "/file")
10841093
check("link/", ALL_BUT_LAST, "/file")
10851094
check("link/", True, "/file")
10861095
check("link/file2", False, "/file/file2")
1096+
check("link/file2", ALLOW_MISSING, FileNotFoundError)
10871097
check("link/file2", ALL_BUT_LAST, FileNotFoundError)
10881098
check("link/file2", True, FileNotFoundError)
10891099
check("link/.", False, "/file")
1100+
check("link/.", ALLOW_MISSING, "/file")
10901101
check("link/.", ALL_BUT_LAST, "/file")
10911102
check("link/.", True, "/file")
10921103
check("link/../link", False, "/file")
1104+
check("link/../link", ALLOW_MISSING, "/file")
10931105
check("link/../link", ALL_BUT_LAST, "/file")
10941106
check("link/../link", True, "/file")
10951107

10961108
check("link2", False, "/dir")
1109+
check("link2", ALLOW_MISSING, "/dir")
10971110
check("link2", ALL_BUT_LAST, "/dir")
10981111
check("link2", True, "/dir")
10991112
check("link2/", False, "/dir")
1113+
check("link2/", ALLOW_MISSING, "/dir")
11001114
check("link2/", ALL_BUT_LAST, "/dir")
11011115
check("link2/", True, "/dir")
11021116
check("link2/file2", False, "/dir/file2")
1117+
check("link2/file2", ALLOW_MISSING, "/dir/file2")
11031118
check("link2/file2", ALL_BUT_LAST, "/dir/file2")
11041119
check("link2/file2", True, "/dir/file2")
11051120

11061121
check("nonexistent", False, "/nonexistent")
1122+
check("nonexistent", ALLOW_MISSING, "/nonexistent")
11071123
check("nonexistent", ALL_BUT_LAST, "/nonexistent")
11081124
check("nonexistent", True, FileNotFoundError)
11091125
check("nonexistent/", False, "/nonexistent")
1126+
check("nonexistent/", ALLOW_MISSING, "/nonexistent")
11101127
check("nonexistent/", ALL_BUT_LAST, "/nonexistent")
11111128
check("nonexistent/", True, FileNotFoundError)
11121129
check("nonexistent/file", False, "/nonexistent/file")
1130+
check("nonexistent/file", ALLOW_MISSING, "/nonexistent/file")
11131131
check("nonexistent/file", ALL_BUT_LAST, FileNotFoundError)
11141132
check("nonexistent/file", True, FileNotFoundError)
11151133
check("nonexistent/../link", False, "/file")
1134+
check("nonexistent/../link", ALLOW_MISSING, "/file")
11161135
check("nonexistent/../link", ALL_BUT_LAST, "/file")
11171136
check("nonexistent/../link", True, "/file")
11181137

11191138
check("broken", False, "/nonexistent")
1139+
check("broken", ALLOW_MISSING, "/nonexistent")
11201140
check("broken", ALL_BUT_LAST, "/nonexistent")
11211141
check("broken", True, FileNotFoundError)
11221142
check("broken/", False, "/nonexistent")
1143+
check("broken/", ALLOW_MISSING, "/nonexistent")
11231144
check("broken/", ALL_BUT_LAST, "/nonexistent")
11241145
check("broken/", True, FileNotFoundError)
11251146
check("broken/file", False, "/nonexistent/file")
1147+
check("broken/file", ALLOW_MISSING, "/nonexistent/file")
11261148
check("broken/file", ALL_BUT_LAST, FileNotFoundError)
11271149
check("broken/file", True, FileNotFoundError)
11281150
check("broken/../link", False, "/file")
1151+
check("broken/../link", ALLOW_MISSING, "/file")
11291152
check("broken/../link", ALL_BUT_LAST, "/file")
11301153
check("broken/../link", True, "/file")
11311154

11321155
check("cycle", False, "/cycle")
1156+
check("cycle", ALLOW_MISSING, OSError, errno.EINVAL)
11331157
check("cycle", ALL_BUT_LAST, OSError, errno.EINVAL)
11341158
check("cycle", True, OSError, errno.EINVAL)
11351159
check("cycle/", False, "/cycle")
1160+
check("cycle/", ALLOW_MISSING, OSError, errno.EINVAL)
11361161
check("cycle/", ALL_BUT_LAST, OSError, errno.EINVAL)
11371162
check("cycle/", True, OSError, errno.EINVAL)
11381163
check("cycle/file", False, "/cycle/file")
1164+
check("cycle/file", ALLOW_MISSING, OSError, errno.EINVAL)
11391165
check("cycle/file", ALL_BUT_LAST, OSError, errno.EINVAL)
11401166
check("cycle/file", True, OSError, errno.EINVAL)
11411167
check("cycle/../link", False, "/file")
1168+
check("cycle/../link", ALLOW_MISSING, "/file")
11421169
check("cycle/../link", ALL_BUT_LAST, "/file")
11431170
check("cycle/../link", True, "/file")
11441171

Lib/test/test_posixpath.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,93 +1057,121 @@ def check(path, mode, expected, errno=None):
10571057

10581058
self.enterContext(os_helper.change_cwd(ABSTFN))
10591059
check("file", False, "/file")
1060+
check("file", ALLOW_MISSING, "/file")
10601061
check("file", ALL_BUT_LAST, "/file")
10611062
check("file", True, "/file")
10621063
check("file/", False, "/file")
1064+
check("file/", ALLOW_MISSING, NotADirectoryError)
10631065
check("file/", ALL_BUT_LAST, NotADirectoryError)
10641066
check("file/", True, NotADirectoryError)
10651067
check("file/file2", False, "/file/file2")
1068+
check("file/file2", ALLOW_MISSING, NotADirectoryError)
10661069
check("file/file2", ALL_BUT_LAST, NotADirectoryError)
10671070
check("file/file2", True, NotADirectoryError)
10681071
check("file/.", False, "/file")
1072+
check("file/.", ALLOW_MISSING, NotADirectoryError)
10691073
check("file/.", ALL_BUT_LAST, NotADirectoryError)
10701074
check("file/.", True, NotADirectoryError)
10711075
check("file/../link2", False, "/dir")
1076+
check("file/../link2", ALLOW_MISSING, NotADirectoryError)
10721077
check("file/../link2", ALL_BUT_LAST, NotADirectoryError)
10731078
check("file/../link2", True, NotADirectoryError)
10741079

10751080
check("dir", False, "/dir")
1081+
check("dir", ALLOW_MISSING, "/dir")
10761082
check("dir", ALL_BUT_LAST, "/dir")
10771083
check("dir", True, "/dir")
10781084
check("dir/", False, "/dir")
1085+
check("dir/", ALLOW_MISSING, "/dir")
10791086
check("dir/", ALL_BUT_LAST, "/dir")
10801087
check("dir/", True, "/dir")
10811088
check("dir/file2", False, "/dir/file2")
1089+
check("dir/file2", ALLOW_MISSING, "/dir/file2")
10821090
check("dir/file2", ALL_BUT_LAST, "/dir/file2")
10831091
check("dir/file2", True, "/dir/file2")
10841092

10851093
check("link", False, "/file")
1094+
check("link", ALLOW_MISSING, "/file")
10861095
check("link", ALL_BUT_LAST, "/file")
10871096
check("link", True, "/file")
10881097
check("link/", False, "/file")
1098+
check("link/", ALLOW_MISSING, NotADirectoryError)
10891099
check("link/", ALL_BUT_LAST, NotADirectoryError)
10901100
check("link/", True, NotADirectoryError)
10911101
check("link/file2", False, "/file/file2")
1102+
check("link/file2", ALLOW_MISSING, NotADirectoryError)
10921103
check("link/file2", ALL_BUT_LAST, NotADirectoryError)
10931104
check("link/file2", True, NotADirectoryError)
10941105
check("link/.", False, "/file")
1106+
check("link/.", ALLOW_MISSING, NotADirectoryError)
10951107
check("link/.", ALL_BUT_LAST, NotADirectoryError)
10961108
check("link/.", True, NotADirectoryError)
10971109
check("link/../link", False, "/file")
1110+
check("link/../link", ALLOW_MISSING, NotADirectoryError)
10981111
check("link/../link", ALL_BUT_LAST, NotADirectoryError)
10991112
check("link/../link", True, NotADirectoryError)
11001113

11011114
check("link2", False, "/dir")
1115+
check("link2", ALLOW_MISSING, "/dir")
11021116
check("link2", ALL_BUT_LAST, "/dir")
11031117
check("link2", True, "/dir")
11041118
check("link2/", False, "/dir")
1119+
check("link2/", ALLOW_MISSING, "/dir")
11051120
check("link2/", ALL_BUT_LAST, "/dir")
11061121
check("link2/", True, "/dir")
11071122
check("link2/file2", False, "/dir/file2")
1123+
check("link2/file2", ALLOW_MISSING, "/dir/file2")
11081124
check("link2/file2", ALL_BUT_LAST, "/dir/file2")
11091125
check("link2/file2", True, "/dir/file2")
11101126

11111127
check("nonexistent", False, "/nonexistent")
1128+
check("nonexistent", ALLOW_MISSING, "/nonexistent")
11121129
check("nonexistent", ALL_BUT_LAST, "/nonexistent")
11131130
check("nonexistent", True, FileNotFoundError)
11141131
check("nonexistent/", False, "/nonexistent")
1132+
check("nonexistent/", ALLOW_MISSING, "/nonexistent")
11151133
check("nonexistent/", ALL_BUT_LAST, "/nonexistent")
11161134
check("nonexistent/", True, FileNotFoundError)
11171135
check("nonexistent/file", False, "/nonexistent/file")
1136+
check("nonexistent/file", ALLOW_MISSING, "/nonexistent/file")
11181137
check("nonexistent/file", ALL_BUT_LAST, FileNotFoundError)
11191138
check("nonexistent/file", True, FileNotFoundError)
11201139
check("nonexistent/../link", False, "/file")
1140+
check("nonexistent/../link", ALLOW_MISSING, "/file")
11211141
check("nonexistent/../link", ALL_BUT_LAST, FileNotFoundError)
11221142
check("nonexistent/../link", True, FileNotFoundError)
11231143

11241144
check("broken", False, "/nonexistent")
1145+
check("broken", ALLOW_MISSING, "/nonexistent")
11251146
check("broken", ALL_BUT_LAST, "/nonexistent")
11261147
check("broken", True, FileNotFoundError)
11271148
check("broken/", False, "/nonexistent")
1149+
check("broken/", ALLOW_MISSING, "/nonexistent")
11281150
check("broken/", ALL_BUT_LAST, "/nonexistent")
11291151
check("broken/", True, FileNotFoundError)
11301152
check("broken/file", False, "/nonexistent/file")
1153+
check("broken/file", ALLOW_MISSING, "/nonexistent/file")
11311154
check("broken/file", ALL_BUT_LAST, FileNotFoundError)
11321155
check("broken/file", True, FileNotFoundError)
11331156
check("broken/../link", False, "/file")
1157+
check("broken/../link", ALLOW_MISSING, "/file")
11341158
check("broken/../link", ALL_BUT_LAST, FileNotFoundError)
11351159
check("broken/../link", True, FileNotFoundError)
11361160

11371161
check("cycle", False, "/cycle")
1162+
check("cycle", ALLOW_MISSING, OSError, errno.ELOOP)
11381163
check("cycle", ALL_BUT_LAST, OSError, errno.ELOOP)
11391164
check("cycle", True, OSError, errno.ELOOP)
11401165
check("cycle/", False, "/cycle")
1166+
check("cycle/", ALLOW_MISSING, OSError, errno.ELOOP)
11411167
check("cycle/", ALL_BUT_LAST, OSError, errno.ELOOP)
11421168
check("cycle/", True, OSError, errno.ELOOP)
11431169
check("cycle/file", False, "/cycle/file")
1170+
check("cycle/file", ALLOW_MISSING, OSError, errno.ELOOP)
11441171
check("cycle/file", ALL_BUT_LAST, OSError, errno.ELOOP)
11451172
check("cycle/file", True, OSError, errno.ELOOP)
11461173
check("cycle/../link", False, "/file")
1174+
check("cycle/../link", ALLOW_MISSING, OSError, errno.ELOOP)
11471175
check("cycle/../link", ALL_BUT_LAST, OSError, errno.ELOOP)
11481176
check("cycle/../link", True, OSError, errno.ELOOP)
11491177

0 commit comments

Comments
 (0)