66import sys
77import unittest
88import warnings
9+ from ntpath import ALLOW_MISSING
910from test .support import TestFailed , cpython_only , os_helper
1011from test .support .os_helper import FakePath
1112from test import test_genericpath
@@ -505,15 +506,15 @@ def test_realpath_curdir_strict(self):
505506
506507 def test_realpath_curdir_missing_ok (self ):
507508 expected = ntpath .normpath (os .getcwd ())
508- tester ("ntpath.realpath('.', strict='allow_missing' )" ,
509+ tester ("ntpath.realpath('.', strict=ALLOW_MISSING )" ,
509510 expected )
510- tester ("ntpath.realpath('./.', strict='allow_missing' )" ,
511+ tester ("ntpath.realpath('./.', strict=ALLOW_MISSING )" ,
511512 expected )
512- tester ("ntpath.realpath('/'.join(['.'] * 100), strict='allow_missing' )" ,
513+ tester ("ntpath.realpath('/'.join(['.'] * 100), strict=ALLOW_MISSING )" ,
513514 expected )
514- tester ("ntpath.realpath('.\\ .', strict='allow_missing' )" ,
515+ tester ("ntpath.realpath('.\\ .', strict=ALLOW_MISSING )" ,
515516 expected )
516- tester ("ntpath.realpath('\\ '.join(['.'] * 100), strict='allow_missing' )" ,
517+ tester ("ntpath.realpath('\\ '.join(['.'] * 100), strict=ALLOW_MISSING )" ,
517518 expected )
518519
519520 def test_realpath_pardir (self ):
@@ -542,20 +543,20 @@ def test_realpath_pardir_strict(self):
542543
543544 def test_realpath_pardir_missing_ok (self ):
544545 expected = ntpath .normpath (os .getcwd ())
545- tester ("ntpath.realpath('..', strict='allow_missing' )" ,
546+ tester ("ntpath.realpath('..', strict=ALLOW_MISSING )" ,
546547 ntpath .dirname (expected ))
547- tester ("ntpath.realpath('../..', strict='allow_missing' )" ,
548+ tester ("ntpath.realpath('../..', strict=ALLOW_MISSING )" ,
548549 ntpath .dirname (ntpath .dirname (expected )))
549- tester ("ntpath.realpath('/'.join(['..'] * 50), strict='allow_missing' )" ,
550+ tester ("ntpath.realpath('/'.join(['..'] * 50), strict=ALLOW_MISSING )" ,
550551 ntpath .splitdrive (expected )[0 ] + '\\ ' )
551- tester ("ntpath.realpath('..\\ ..', strict='allow_missing' )" ,
552+ tester ("ntpath.realpath('..\\ ..', strict=ALLOW_MISSING )" ,
552553 ntpath .dirname (ntpath .dirname (expected )))
553- tester ("ntpath.realpath('\\ '.join(['..'] * 50), strict='allow_missing' )" ,
554+ tester ("ntpath.realpath('\\ '.join(['..'] * 50), strict=ALLOW_MISSING )" ,
554555 ntpath .splitdrive (expected )[0 ] + '\\ ' )
555556
556557 @os_helper .skip_unless_symlink
557558 @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
558- @_parameterize ({}, {'strict' : True }, {'strict' : 'allow_missing' })
559+ @_parameterize ({}, {'strict' : True }, {'strict' : ALLOW_MISSING })
559560 def test_realpath_basic (self , kwargs ):
560561 ABSTFN = ntpath .abspath (os_helper .TESTFN )
561562 open (ABSTFN , "wb" ).close ()
@@ -603,38 +604,38 @@ def test_realpath_invalid_paths(self):
603604 self .assertEqual (realpath (path , strict = False ), path )
604605 # gh-106242: Embedded nulls should raise OSError (not ValueError)
605606 self .assertRaises (OSError , realpath , path , strict = True )
606- self .assertRaises (OSError , realpath , path , strict = 'allow_missing' )
607+ self .assertRaises (OSError , realpath , path , strict = ALLOW_MISSING )
607608 path = ABSTFNb + b'\x00 '
608609 self .assertEqual (realpath (path , strict = False ), path )
609610 self .assertRaises (OSError , realpath , path , strict = True )
610- self .assertRaises (OSError , realpath , path , strict = 'allow_missing' )
611+ self .assertRaises (OSError , realpath , path , strict = ALLOW_MISSING )
611612 path = ABSTFN + '\\ nonexistent\\ x\x00 '
612613 self .assertEqual (realpath (path , strict = False ), path )
613614 self .assertRaises (OSError , realpath , path , strict = True )
614- self .assertRaises (OSError , realpath , path , strict = 'allow_missing' )
615+ self .assertRaises (OSError , realpath , path , strict = ALLOW_MISSING )
615616 path = ABSTFNb + b'\\ nonexistent\\ x\x00 '
616617 self .assertEqual (realpath (path , strict = False ), path )
617618 self .assertRaises (OSError , realpath , path , strict = True )
618- self .assertRaises (OSError , realpath , path , strict = 'allow_missing' )
619+ self .assertRaises (OSError , realpath , path , strict = ALLOW_MISSING )
619620 path = ABSTFN + '\x00 \\ ..'
620621 self .assertEqual (realpath (path , strict = False ), os .getcwd ())
621622 self .assertEqual (realpath (path , strict = True ), os .getcwd ())
622- self .assertEqual (realpath (path , strict = 'allow_missing' ), os .getcwd ())
623+ self .assertEqual (realpath (path , strict = ALLOW_MISSING ), os .getcwd ())
623624 path = ABSTFNb + b'\x00 \\ ..'
624625 self .assertEqual (realpath (path , strict = False ), os .getcwdb ())
625626 self .assertEqual (realpath (path , strict = True ), os .getcwdb ())
626- self .assertEqual (realpath (path , strict = 'allow_missing' ), os .getcwdb ())
627+ self .assertEqual (realpath (path , strict = ALLOW_MISSING ), os .getcwdb ())
627628 path = ABSTFN + '\\ nonexistent\\ x\x00 \\ ..'
628629 self .assertEqual (realpath (path , strict = False ), ABSTFN + '\\ nonexistent' )
629630 self .assertRaises (OSError , realpath , path , strict = True )
630- self .assertEqual (realpath (path , strict = 'allow_missing' ), ABSTFN + '\\ nonexistent' )
631+ self .assertEqual (realpath (path , strict = ALLOW_MISSING ), ABSTFN + '\\ nonexistent' )
631632 path = ABSTFNb + b'\\ nonexistent\\ x\x00 \\ ..'
632633 self .assertEqual (realpath (path , strict = False ), ABSTFNb + b'\\ nonexistent' )
633634 self .assertRaises (OSError , realpath , path , strict = True )
634- self .assertEqual (realpath (path , strict = 'allow_missing' ), ABSTFNb + b'\\ nonexistent' )
635+ self .assertEqual (realpath (path , strict = ALLOW_MISSING ), ABSTFNb + b'\\ nonexistent' )
635636
636637 @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
637- @_parameterize ({}, {'strict' : True }, {'strict' : 'allow_missing' })
638+ @_parameterize ({}, {'strict' : True }, {'strict' : ALLOW_MISSING })
638639 def test_realpath_invalid_unicode_paths (self , kwargs ):
639640 realpath = ntpath .realpath
640641 ABSTFN = ntpath .abspath (os_helper .TESTFN )
@@ -654,7 +655,7 @@ def test_realpath_invalid_unicode_paths(self, kwargs):
654655
655656 @os_helper .skip_unless_symlink
656657 @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
657- @_parameterize ({}, {'strict' : True }, {'strict' : 'allow_missing' })
658+ @_parameterize ({}, {'strict' : True }, {'strict' : ALLOW_MISSING })
658659 def test_realpath_relative (self , kwargs ):
659660 ABSTFN = ntpath .abspath (os_helper .TESTFN )
660661 open (ABSTFN , "wb" ).close ()
@@ -815,7 +816,7 @@ def test_realpath_symlink_loops_strict(self):
815816 @os_helper .skip_unless_symlink
816817 @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
817818 def test_realpath_symlink_loops_raise (self ):
818- # Symlink loops raise OSError in 'allow_missing' mode
819+ # Symlink loops raise OSError in ALLOW_MISSING mode
819820 ABSTFN = ntpath .abspath (os_helper .TESTFN )
820821 self .addCleanup (os_helper .unlink , ABSTFN )
821822 self .addCleanup (os_helper .unlink , ABSTFN + "1" )
@@ -826,16 +827,16 @@ def test_realpath_symlink_loops_raise(self):
826827 self .addCleanup (os_helper .unlink , ABSTFN + "x" )
827828
828829 os .symlink (ABSTFN , ABSTFN )
829- self .assertRaises (OSError , ntpath .realpath , ABSTFN , strict = 'allow_missing' )
830+ self .assertRaises (OSError , ntpath .realpath , ABSTFN , strict = ALLOW_MISSING )
830831
831832 os .symlink (ABSTFN + "1" , ABSTFN + "2" )
832833 os .symlink (ABSTFN + "2" , ABSTFN + "1" )
833834 self .assertRaises (OSError , ntpath .realpath , ABSTFN + "1" ,
834- strict = 'allow_missing' )
835+ strict = ALLOW_MISSING )
835836 self .assertRaises (OSError , ntpath .realpath , ABSTFN + "2" ,
836- strict = 'allow_missing' )
837+ strict = ALLOW_MISSING )
837838 self .assertRaises (OSError , ntpath .realpath , ABSTFN + "1\\ x" ,
838- strict = 'allow_missing' )
839+ strict = ALLOW_MISSING )
839840
840841 # Windows eliminates '..' components before resolving links;
841842 # realpath is not expected to raise if this removes the loop.
@@ -851,24 +852,24 @@ def test_realpath_symlink_loops_raise(self):
851852 self .assertRaises (
852853 OSError , ntpath .realpath ,
853854 ABSTFN + "1\\ ..\\ " + ntpath .basename (ABSTFN ) + "1" ,
854- strict = 'allow_missing' )
855+ strict = ALLOW_MISSING )
855856
856857 os .symlink (ntpath .basename (ABSTFN ) + "a\\ b" , ABSTFN + "a" )
857858 self .assertRaises (OSError , ntpath .realpath , ABSTFN + "a" ,
858- strict = 'allow_missing' )
859+ strict = ALLOW_MISSING )
859860
860861 os .symlink ("..\\ " + ntpath .basename (ntpath .dirname (ABSTFN ))
861862 + "\\ " + ntpath .basename (ABSTFN ) + "c" , ABSTFN + "c" )
862863 self .assertRaises (OSError , ntpath .realpath , ABSTFN + "c" ,
863- strict = 'allow_missing' )
864+ strict = ALLOW_MISSING )
864865
865866 # Test using relative path as well.
866867 self .assertRaises (OSError , ntpath .realpath , ntpath .basename (ABSTFN ),
867- strict = 'allow_missing' )
868+ strict = ALLOW_MISSING )
868869
869870 @os_helper .skip_unless_symlink
870871 @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
871- @_parameterize ({}, {'strict' : True }, {'strict' : 'allow_missing' })
872+ @_parameterize ({}, {'strict' : True }, {'strict' : ALLOW_MISSING })
872873 def test_realpath_symlink_prefix (self , kwargs ):
873874 ABSTFN = ntpath .abspath (os_helper .TESTFN )
874875 self .addCleanup (os_helper .unlink , ABSTFN + "3" )
@@ -906,7 +907,7 @@ def test_realpath_nul(self):
906907 tester ("ntpath.realpath('NUL')" , r'\\.\NUL' )
907908 tester ("ntpath.realpath('NUL', strict=False)" , r'\\.\NUL' )
908909 tester ("ntpath.realpath('NUL', strict=True)" , r'\\.\NUL' )
909- tester ("ntpath.realpath('NUL', strict='allow_missing' )" , r'\\.\NUL' )
910+ tester ("ntpath.realpath('NUL', strict=ALLOW_MISSING )" , r'\\.\NUL' )
910911
911912 @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
912913 @unittest .skipUnless (HAVE_GETSHORTPATHNAME , 'need _getshortpathname' )
@@ -930,7 +931,7 @@ def test_realpath_cwd(self):
930931
931932 self .assertPathEqual (test_file_long , ntpath .realpath (test_file_short ))
932933
933- for kwargs in {}, {'strict' : True }, {'strict' : 'allow_missing' }:
934+ for kwargs in {}, {'strict' : True }, {'strict' : ALLOW_MISSING }:
934935 with self .subTest (** kwargs ):
935936 with os_helper .change_cwd (test_dir_long ):
936937 self .assertPathEqual (
0 commit comments