@@ -487,27 +487,35 @@ def test_realpath_strict(self):
487487 def test_realpath_invalid_paths (self ):
488488 path = '/\x00 '
489489 self .assertRaises (ValueError , realpath , path , strict = False )
490+ self .assertRaises (ValueError , realpath , path , strict = ALL_BUT_LAST )
490491 self .assertRaises (ValueError , realpath , path , strict = True )
491492 path = b'/\x00 '
492493 self .assertRaises (ValueError , realpath , path , strict = False )
494+ self .assertRaises (ValueError , realpath , path , strict = ALL_BUT_LAST )
493495 self .assertRaises (ValueError , realpath , path , strict = True )
494496 path = '/nonexistent/x\x00 '
495497 self .assertRaises (ValueError , realpath , path , strict = False )
498+ self .assertRaises (FileNotFoundError , realpath , path , strict = ALL_BUT_LAST )
496499 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
497500 path = b'/nonexistent/x\x00 '
498501 self .assertRaises (ValueError , realpath , path , strict = False )
502+ self .assertRaises (FileNotFoundError , realpath , path , strict = ALL_BUT_LAST )
499503 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
500504 path = '/\x00 /..'
501505 self .assertRaises (ValueError , realpath , path , strict = False )
506+ self .assertRaises (ValueError , realpath , path , strict = ALL_BUT_LAST )
502507 self .assertRaises (ValueError , realpath , path , strict = True )
503508 path = b'/\x00 /..'
504509 self .assertRaises (ValueError , realpath , path , strict = False )
510+ self .assertRaises (ValueError , realpath , path , strict = ALL_BUT_LAST )
505511 self .assertRaises (ValueError , realpath , path , strict = True )
506512 path = '/nonexistent/x\x00 /..'
507513 self .assertRaises (ValueError , realpath , path , strict = False )
514+ self .assertRaises (FileNotFoundError , realpath , path , strict = ALL_BUT_LAST )
508515 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
509516 path = b'/nonexistent/x\x00 /..'
510517 self .assertRaises (ValueError , realpath , path , strict = False )
518+ self .assertRaises (FileNotFoundError , realpath , path , strict = ALL_BUT_LAST )
511519 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
512520
513521 path = '/\udfff '
@@ -516,25 +524,29 @@ def test_realpath_invalid_paths(self):
516524 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
517525 else :
518526 self .assertRaises (UnicodeEncodeError , realpath , path , strict = False )
527+ self .assertRaises (UnicodeEncodeError , realpath , path , strict = ALL_BUT_LAST )
519528 self .assertRaises (UnicodeEncodeError , realpath , path , strict = True )
520529 path = '/nonexistent/\udfff '
521530 if sys .platform == 'win32' :
522531 self .assertEqual (realpath (path , strict = False ), path )
523532 else :
524533 self .assertRaises (UnicodeEncodeError , realpath , path , strict = False )
534+ self .assertRaises (FileNotFoundError , realpath , path , strict = ALL_BUT_LAST )
525535 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
526536 path = '/\udfff /..'
527537 if sys .platform == 'win32' :
528538 self .assertEqual (realpath (path , strict = False ), '/' )
529539 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
530540 else :
531541 self .assertRaises (UnicodeEncodeError , realpath , path , strict = False )
542+ self .assertRaises (UnicodeEncodeError , realpath , path , strict = ALL_BUT_LAST )
532543 self .assertRaises (UnicodeEncodeError , realpath , path , strict = True )
533544 path = '/nonexistent/\udfff /..'
534545 if sys .platform == 'win32' :
535546 self .assertEqual (realpath (path , strict = False ), '/nonexistent' )
536547 else :
537548 self .assertRaises (UnicodeEncodeError , realpath , path , strict = False )
549+ self .assertRaises (FileNotFoundError , realpath , path , strict = ALL_BUT_LAST )
538550 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
539551
540552 path = b'/\xff '
@@ -543,6 +555,7 @@ def test_realpath_invalid_paths(self):
543555 self .assertRaises (UnicodeDecodeError , realpath , path , strict = True )
544556 else :
545557 self .assertEqual (realpath (path , strict = False ), path )
558+ self .assertEqual (realpath (path , strict = ALL_BUT_LAST ), path )
546559 if support .is_wasi :
547560 self .assertRaises (OSError , realpath , path , strict = True )
548561 else :
@@ -553,8 +566,10 @@ def test_realpath_invalid_paths(self):
553566 else :
554567 self .assertEqual (realpath (path , strict = False ), path )
555568 if support .is_wasi :
569+ self .assertRaises (OSError , realpath , path , strict = ALL_BUT_LAST )
556570 self .assertRaises (OSError , realpath , path , strict = True )
557571 else :
572+ self .assertRaises (FileNotFoundError , realpath , path , strict = ALL_BUT_LAST )
558573 self .assertRaises (FileNotFoundError , realpath , path , strict = True )
559574
560575 @os_helper .skip_unless_symlink
@@ -623,30 +638,48 @@ def test_realpath_symlink_loops_strict(self):
623638 # strict mode.
624639 try :
625640 os .symlink (ABSTFN , ABSTFN )
641+ self .assertRaises (OSError , realpath , ABSTFN , strict = ALL_BUT_LAST )
626642 self .assertRaises (OSError , realpath , ABSTFN , strict = True )
627643
628644 os .symlink (ABSTFN + "1" , ABSTFN + "2" )
629645 os .symlink (ABSTFN + "2" , ABSTFN + "1" )
646+ self .assertRaises (OSError , realpath , ABSTFN + "1" , strict = ALL_BUT_LAST )
630647 self .assertRaises (OSError , realpath , ABSTFN + "1" , strict = True )
648+ self .assertRaises (OSError , realpath , ABSTFN + "2" , strict = ALL_BUT_LAST )
631649 self .assertRaises (OSError , realpath , ABSTFN + "2" , strict = True )
632650
651+ self .assertRaises (OSError , realpath , ABSTFN + "1/x" , strict = ALL_BUT_LAST )
633652 self .assertRaises (OSError , realpath , ABSTFN + "1/x" , strict = True )
653+ self .assertRaises (OSError , realpath , ABSTFN + "1/.." , strict = ALL_BUT_LAST )
634654 self .assertRaises (OSError , realpath , ABSTFN + "1/.." , strict = True )
655+ self .assertRaises (OSError , realpath , ABSTFN + "1/../x" , strict = ALL_BUT_LAST )
635656 self .assertRaises (OSError , realpath , ABSTFN + "1/../x" , strict = True )
636657 os .symlink (ABSTFN + "x" , ABSTFN + "y" )
637658 self .assertRaises (OSError , realpath ,
638- ABSTFN + "1/../" + basename (ABSTFN ) + "y" , strict = True )
659+ ABSTFN + "1/../" + basename (ABSTFN ) + "y" ,
660+ strict = ALL_BUT_LAST )
639661 self .assertRaises (OSError , realpath ,
640- ABSTFN + "1/../" + basename (ABSTFN ) + "1" , strict = True )
662+ ABSTFN + "1/../" + basename (ABSTFN ) + "y" ,
663+ strict = True )
664+ self .assertRaises (OSError , realpath ,
665+ ABSTFN + "1/../" + basename (ABSTFN ) + "1" ,
666+ strict = ALL_BUT_LAST )
667+ self .assertRaises (OSError , realpath ,
668+ ABSTFN + "1/../" + basename (ABSTFN ) + "1" ,
669+ strict = True )
641670
642671 os .symlink (basename (ABSTFN ) + "a/b" , ABSTFN + "a" )
672+ self .assertRaises (OSError , realpath , ABSTFN + "a" , strict = ALL_BUT_LAST )
643673 self .assertRaises (OSError , realpath , ABSTFN + "a" , strict = True )
644674
645675 os .symlink ("../" + basename (dirname (ABSTFN )) + "/" +
646676 basename (ABSTFN ) + "c" , ABSTFN + "c" )
677+ self .assertRaises (OSError , realpath , ABSTFN + "c" , strict = ALL_BUT_LAST )
647678 self .assertRaises (OSError , realpath , ABSTFN + "c" , strict = True )
648679
649680 # Test using relative path as well.
681+ with os_helper .change_cwd (dirname (ABSTFN )):
682+ self .assertRaises (OSError , realpath , basename (ABSTFN ), strict = ALL_BUT_LAST )
650683 with os_helper .change_cwd (dirname (ABSTFN )):
651684 self .assertRaises (OSError , realpath , basename (ABSTFN ), strict = True )
652685 finally :
@@ -768,6 +801,8 @@ def test_realpath_unreadable_symlink(self):
768801 self .assertEqual (realpath (ABSTFN + '/foo' ), ABSTFN + '/foo' )
769802 self .assertEqual (realpath (ABSTFN + '/../foo' ), dirname (ABSTFN ) + '/foo' )
770803 self .assertEqual (realpath (ABSTFN + '/foo/..' ), ABSTFN )
804+ with self .assertRaises (PermissionError ):
805+ realpath (ABSTFN , strict = ALL_BUT_LAST )
771806 with self .assertRaises (PermissionError ):
772807 realpath (ABSTFN , strict = True )
773808 finally :
@@ -780,14 +815,19 @@ def test_realpath_nonterminal_file(self):
780815 with open (ABSTFN , 'w' ) as f :
781816 f .write ('test_posixpath wuz ere' )
782817 self .assertEqual (realpath (ABSTFN , strict = False ), ABSTFN )
818+ self .assertEqual (realpath (ABSTFN , strict = ALL_BUT_LAST ), ABSTFN )
783819 self .assertEqual (realpath (ABSTFN , strict = True ), ABSTFN )
784820 self .assertEqual (realpath (ABSTFN + "/" , strict = False ), ABSTFN )
821+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/" , strict = ALL_BUT_LAST )
785822 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/" , strict = True )
786823 self .assertEqual (realpath (ABSTFN + "/." , strict = False ), ABSTFN )
824+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/." , strict = ALL_BUT_LAST )
787825 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/." , strict = True )
788826 self .assertEqual (realpath (ABSTFN + "/.." , strict = False ), dirname (ABSTFN ))
827+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/.." , strict = ALL_BUT_LAST )
789828 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/.." , strict = True )
790829 self .assertEqual (realpath (ABSTFN + "/subdir" , strict = False ), ABSTFN + "/subdir" )
830+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/subdir" , strict = ALL_BUT_LAST )
791831 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/subdir" , strict = True )
792832 finally :
793833 os_helper .unlink (ABSTFN )
@@ -800,14 +840,19 @@ def test_realpath_nonterminal_symlink_to_file(self):
800840 f .write ('test_posixpath wuz ere' )
801841 os .symlink (ABSTFN + "1" , ABSTFN )
802842 self .assertEqual (realpath (ABSTFN , strict = False ), ABSTFN + "1" )
843+ self .assertEqual (realpath (ABSTFN , strict = ALL_BUT_LAST ), ABSTFN + "1" )
803844 self .assertEqual (realpath (ABSTFN , strict = True ), ABSTFN + "1" )
804845 self .assertEqual (realpath (ABSTFN + "/" , strict = False ), ABSTFN + "1" )
846+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/" , strict = ALL_BUT_LAST )
805847 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/" , strict = True )
806848 self .assertEqual (realpath (ABSTFN + "/." , strict = False ), ABSTFN + "1" )
849+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/." , strict = ALL_BUT_LAST )
807850 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/." , strict = True )
808851 self .assertEqual (realpath (ABSTFN + "/.." , strict = False ), dirname (ABSTFN ))
852+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/.." , strict = ALL_BUT_LAST )
809853 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/.." , strict = True )
810854 self .assertEqual (realpath (ABSTFN + "/subdir" , strict = False ), ABSTFN + "1/subdir" )
855+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/subdir" , strict = ALL_BUT_LAST )
811856 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/subdir" , strict = True )
812857 finally :
813858 os_helper .unlink (ABSTFN )
@@ -822,22 +867,26 @@ def test_realpath_nonterminal_symlink_to_symlinks_to_file(self):
822867 os .symlink (ABSTFN + "2" , ABSTFN + "1" )
823868 os .symlink (ABSTFN + "1" , ABSTFN )
824869 self .assertEqual (realpath (ABSTFN , strict = False ), ABSTFN + "2" )
870+ self .assertEqual (realpath (ABSTFN , strict = ALL_BUT_LAST ), ABSTFN + "2" )
825871 self .assertEqual (realpath (ABSTFN , strict = True ), ABSTFN + "2" )
826872 self .assertEqual (realpath (ABSTFN + "/" , strict = False ), ABSTFN + "2" )
873+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/" , strict = ALL_BUT_LAST )
827874 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/" , strict = True )
828875 self .assertEqual (realpath (ABSTFN + "/." , strict = False ), ABSTFN + "2" )
876+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/." , strict = ALL_BUT_LAST )
829877 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/." , strict = True )
830878 self .assertEqual (realpath (ABSTFN + "/.." , strict = False ), dirname (ABSTFN ))
879+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/.." , strict = ALL_BUT_LAST )
831880 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/.." , strict = True )
832881 self .assertEqual (realpath (ABSTFN + "/subdir" , strict = False ), ABSTFN + "2/subdir" )
882+ self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/subdir" , strict = ALL_BUT_LAST )
833883 self .assertRaises (NotADirectoryError , realpath , ABSTFN + "/subdir" , strict = True )
834884 finally :
835885 os_helper .unlink (ABSTFN )
836886 os_helper .unlink (ABSTFN + "1" )
837887 os_helper .unlink (ABSTFN + "2" )
838888
839889 @os_helper .skip_unless_symlink
840- # @skip_if_ABSTFN_contains_backslash
841890 def test_realpath_mode (self ):
842891 self .addCleanup (os_helper .rmdir , ABSTFN )
843892 self .addCleanup (os_helper .rmdir , ABSTFN + "/dir" )
0 commit comments