File tree 2 files changed +44
-0
lines changed 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,49 @@ def write_files_without_closing():
194
194
# restore CWD
195
195
os .chdir (curdir )
196
196
197
+ # test error cases with long paths
198
+ if sys .platform == "win32" :
199
+ # Windows doesn't let you change into a directory whose full path is too
200
+ # long, so this cannot be tested.
201
+ def testlongpath ():
202
+ return True
203
+
204
+ else :
205
+
206
+ def testlongpath ():
207
+ longname = 62 * "long"
208
+ for n in range (300 ):
209
+ os .mkdir (longname )
210
+ os .chdir (longname )
211
+ try :
212
+ os .getcwd ()
213
+ except OSError as e :
214
+ # expecting ERANGE from getcwd() after a few iterations, then we
215
+ # are in the situation to be tested
216
+ if e .errno == 34 :
217
+ break
218
+ else :
219
+ print ("getcwd():" , repr (e ))
220
+ return False
221
+
222
+ try :
223
+ print (os .VfsPosix ("something" ))
224
+ except OSError as e :
225
+ # expecting ERANGE
226
+ if e .errno != 34 :
227
+ print ("VfsPosix():" , repr (e ))
228
+ return False
229
+
230
+ # clean up
231
+ for i in range (n + 1 ):
232
+ os .chdir (".." )
233
+ os .rmdir (longname )
234
+
235
+ return True
236
+
237
+
238
+ print ("testlongpath():" , testlongpath ())
239
+
197
240
# rmdir
198
241
os .rmdir (temp_dir )
199
242
print (temp_dir in os .listdir ())
Original file line number Diff line number Diff line change @@ -35,5 +35,6 @@ chdir("/mnt/dir"): None
35
35
getcwd(): /mnt/dir
36
36
chdir(".."): None
37
37
getcwd(): /mnt
38
+ testlongpath(): True
38
39
False
39
40
rmdir OSError
You can’t perform that action at this time.
0 commit comments