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