@@ -350,65 +350,6 @@ def test_realpath_strict(self):
350
350
self .assertRaises (FileNotFoundError , ntpath .realpath , ABSTFN , strict = True )
351
351
self .assertRaises (FileNotFoundError , ntpath .realpath , ABSTFN + "2" , strict = True )
352
352
353
- @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
354
- def test_realpath_invalid_paths (self ):
355
- realpath = ntpath .realpath
356
- ABSTFN = ntpath .abspath (os_helper .TESTFN )
357
- ABSTFNb = os .fsencode (ABSTFN )
358
- path = ABSTFN + '\x00 '
359
- # gh-106242: Embedded nulls and non-strict fallback to abspath
360
- self .assertEqual (realpath (path , strict = False ), path )
361
- # gh-106242: Embedded nulls should raise OSError (not ValueError)
362
- self .assertRaises (OSError , ntpath .realpath , path , strict = True )
363
- self .assertRaises (OSError , ntpath .realpath , path , strict = ALLOW_MISSING )
364
- path = ABSTFNb + b'\x00 '
365
- self .assertEqual (realpath (path , strict = False ), path )
366
- self .assertRaises (OSError , ntpath .realpath , path , strict = True )
367
- self .assertRaises (OSError , ntpath .realpath , path , strict = ALLOW_MISSING )
368
- path = ABSTFN + '\\ nonexistent\\ x\x00 '
369
- self .assertEqual (realpath (path , strict = False ), path )
370
- self .assertRaises (OSError , ntpath .realpath , path , strict = True )
371
- self .assertRaises (OSError , ntpath .realpath , path , strict = ALLOW_MISSING )
372
- path = ABSTFNb + b'\\ nonexistent\\ x\x00 '
373
- self .assertEqual (realpath (path , strict = False ), path )
374
- self .assertRaises (OSError , ntpath .realpath , path , strict = True )
375
- self .assertRaises (OSError , ntpath .realpath , path , strict = ALLOW_MISSING )
376
- path = ABSTFN + '\x00 \\ ..'
377
- self .assertEqual (realpath (path , strict = False ), os .getcwd ())
378
- self .assertEqual (realpath (path , strict = True ), os .getcwd ())
379
- self .assertEqual (realpath (path , strict = ALLOW_MISSING ), os .getcwd ())
380
- path = ABSTFNb + b'\x00 \\ ..'
381
- self .assertEqual (realpath (path , strict = False ), os .getcwdb ())
382
- self .assertEqual (realpath (path , strict = True ), os .getcwdb ())
383
- self .assertEqual (realpath (path , strict = ALLOW_MISSING ), os .getcwdb ())
384
- path = ABSTFN + '\\ nonexistent\\ x\x00 \\ ..'
385
- self .assertEqual (realpath (path , strict = False ), ABSTFN + '\\ nonexistent' )
386
- self .assertRaises (OSError , ntpath .realpath , path , strict = True )
387
- self .assertEqual (realpath (path , strict = ALLOW_MISSING ), ABSTFN + '\\ nonexistent' )
388
- path = ABSTFNb + b'\\ nonexistent\\ x\x00 \\ ..'
389
- self .assertEqual (realpath (path , strict = False ), ABSTFNb + b'\\ nonexistent' )
390
- self .assertRaises (OSError , ntpath .realpath , path , strict = True )
391
- self .assertEqual (realpath (path , strict = ALLOW_MISSING ), ABSTFNb + b'\\ nonexistent' )
392
-
393
- @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
394
- @_parameterize ({}, {'strict' : True }, {'strict' : ALLOW_MISSING })
395
- def test_realpath_invalid_unicode_paths (self , kwargs ):
396
- realpath = ntpath .realpath
397
- ABSTFN = ntpath .abspath (os_helper .TESTFN )
398
- ABSTFNb = os .fsencode (ABSTFN )
399
- path = ABSTFNb + b'\xff '
400
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
401
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
402
- path = ABSTFNb + b'\\ nonexistent\\ \xff '
403
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
404
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
405
- path = ABSTFNb + b'\xff \\ ..'
406
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
407
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
408
- path = ABSTFNb + b'\\ nonexistent\\ \xff \\ ..'
409
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
410
- self .assertRaises (UnicodeDecodeError , ntpath .realpath , path , ** kwargs )
411
-
412
353
@os_helper .skip_unless_symlink
413
354
@unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
414
355
@_parameterize ({}, {'strict' : True }, {'strict' : ALLOW_MISSING })
@@ -702,51 +643,6 @@ def test_realpath_cwd(self):
702
643
test_file_long ,
703
644
ntpath .realpath ("file.txt" , ** kwargs ))
704
645
705
- @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
706
- def test_realpath_permission (self ):
707
- # Test whether python can resolve the real filename of a
708
- # shortened file name even if it does not have permission to access it.
709
- ABSTFN = ntpath .realpath (os_helper .TESTFN )
710
-
711
- os_helper .unlink (ABSTFN )
712
- os_helper .rmtree (ABSTFN )
713
- os .mkdir (ABSTFN )
714
- self .addCleanup (os_helper .rmtree , ABSTFN )
715
-
716
- test_file = ntpath .join (ABSTFN , "LongFileName123.txt" )
717
- test_file_short = ntpath .join (ABSTFN , "LONGFI~1.TXT" )
718
-
719
- with open (test_file , "wb" ) as f :
720
- f .write (b"content" )
721
- # Automatic generation of short names may be disabled on
722
- # NTFS volumes for the sake of performance.
723
- # They're not supported at all on ReFS and exFAT.
724
- p = subprocess .run (
725
- # Try to set the short name manually.
726
- ['fsutil.exe' , 'file' , 'setShortName' , test_file , 'LONGFI~1.TXT' ],
727
- creationflags = subprocess .DETACHED_PROCESS
728
- )
729
-
730
- if p .returncode :
731
- raise unittest .SkipTest ('failed to set short name' )
732
-
733
- try :
734
- self .assertPathEqual (test_file , ntpath .realpath (test_file_short ))
735
- except AssertionError :
736
- raise unittest .SkipTest ('the filesystem seems to lack support for short filenames' )
737
-
738
- # Deny the right to [S]YNCHRONIZE on the file to
739
- # force nt._getfinalpathname to fail with ERROR_ACCESS_DENIED.
740
- p = subprocess .run (
741
- ['icacls.exe' , test_file , '/deny' , '*S-1-5-32-545:(S)' ],
742
- creationflags = subprocess .DETACHED_PROCESS
743
- )
744
-
745
- if p .returncode :
746
- raise unittest .SkipTest ('failed to deny access to the test file' )
747
-
748
- self .assertPathEqual (test_file , ntpath .realpath (test_file_short ))
749
-
750
646
def test_expandvars (self ):
751
647
with os_helper .EnvironmentVarGuard () as env :
752
648
env .clear ()
0 commit comments