@@ -377,6 +377,22 @@ def test_realpath_symlink_loops(self):
377377 self .assertEqual (realpath (ABSTFN + "1" ), ABSTFN + "1" )
378378 self .assertEqual (realpath (ABSTFN + "2" ), ABSTFN + "2" )
379379
380+ self .assertEqual (realpath (ABSTFN + "1/x" ), ABSTFN + "1/x" )
381+ self .assertEqual (realpath (ABSTFN + "1/.." ), dirname (ABSTFN ))
382+ self .assertEqual (realpath (ABSTFN + "1/../x" ), dirname (ABSTFN ) + "/x" )
383+ os .symlink (ABSTFN + "x" , ABSTFN + "y" )
384+ self .assertEqual (realpath (ABSTFN + "1/../" + basename (ABSTFN ) + "y" ),
385+ ABSTFN + "y" )
386+ self .assertEqual (realpath (ABSTFN + "1/../" + basename (ABSTFN ) + "1" ),
387+ ABSTFN + "1" )
388+
389+ os .symlink (basename (ABSTFN ) + "a/b" , ABSTFN + "a" )
390+ self .assertEqual (realpath (ABSTFN + "a" ), ABSTFN + "a/b" )
391+
392+ os .symlink ("../" + basename (dirname (ABSTFN )) + "/" +
393+ basename (ABSTFN ) + "c" , ABSTFN + "c" )
394+ self .assertEqual (realpath (ABSTFN + "c" ), ABSTFN + "c" )
395+
380396 # Test using relative path as well.
381397 os .chdir (dirname (ABSTFN ))
382398 self .assertEqual (realpath (basename (ABSTFN )), ABSTFN )
@@ -385,6 +401,45 @@ def test_realpath_symlink_loops(self):
385401 support .unlink (ABSTFN )
386402 support .unlink (ABSTFN + "1" )
387403 support .unlink (ABSTFN + "2" )
404+ support .unlink (ABSTFN + "y" )
405+ support .unlink (ABSTFN + "c" )
406+
407+ @unittest .skipUnless (hasattr (os , "symlink" ),
408+ "Missing symlink implementation" )
409+ @skip_if_ABSTFN_contains_backslash
410+ def test_realpath_repeated_indirect_symlinks (self ):
411+ # Issue #6975.
412+ try :
413+ os .mkdir (ABSTFN )
414+ os .symlink ('../' + basename (ABSTFN ), ABSTFN + '/self' )
415+ os .symlink ('self/self/self' , ABSTFN + '/link' )
416+ self .assertEqual (realpath (ABSTFN + '/link' ), ABSTFN )
417+ finally :
418+ support .unlink (ABSTFN + '/self' )
419+ support .unlink (ABSTFN + '/link' )
420+ safe_rmdir (ABSTFN )
421+
422+ @unittest .skipUnless (hasattr (os , "symlink" ),
423+ "Missing symlink implementation" )
424+ @skip_if_ABSTFN_contains_backslash
425+ def test_realpath_deep_recursion (self ):
426+ depth = 10
427+ old_path = abspath ('.' )
428+ try :
429+ os .mkdir (ABSTFN )
430+ for i in range (depth ):
431+ os .symlink ('/' .join (['%d' % i ] * 10 ), ABSTFN + '/%d' % (i + 1 ))
432+ os .symlink ('.' , ABSTFN + '/0' )
433+ self .assertEqual (realpath (ABSTFN + '/%d' % depth ), ABSTFN )
434+
435+ # Test using relative path as well.
436+ os .chdir (ABSTFN )
437+ self .assertEqual (realpath ('%d' % depth ), ABSTFN )
438+ finally :
439+ os .chdir (old_path )
440+ for i in range (depth + 1 ):
441+ support .unlink (ABSTFN + '/%d' % i )
442+ safe_rmdir (ABSTFN )
388443
389444 @unittest .skipUnless (hasattr (os , "symlink" ),
390445 "Missing symlink implementation" )
0 commit comments