Skip to content
Prev Previous commit
Next Next commit
Fix Windows test_ntpath failures.
  • Loading branch information
Yhg1s committed Jun 3, 2025
commit 1d242c380458af86560ada05d2c83d5352459a41
37 changes: 19 additions & 18 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ntpath
import os
import string
import subprocess
import sys
import unittest
import warnings
Expand Down Expand Up @@ -485,20 +486,20 @@ def test_realpath_strict(self):
# gh-106242: Embedded nulls should raise OSError (not ValueError)
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "\0spam", strict=True)

self.assertRaises(OSError, realpath, path, strict=True)
self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
self.assertRaises(OSError, ntpath.realpath, path, strict=True)
self.assertRaises(OSError, ntpath.realpath, path, strict=ALLOW_MISSING)
path = ABSTFNb + b'\x00'
self.assertEqual(realpath(path, strict=False), path)
self.assertRaises(OSError, realpath, path, strict=True)
self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
self.assertRaises(OSError, ntpath.realpath, path, strict=True)
self.assertRaises(OSError, ntpath.realpath, path, strict=ALLOW_MISSING)
path = ABSTFN + '\\nonexistent\\x\x00'
self.assertEqual(realpath(path, strict=False), path)
self.assertRaises(OSError, realpath, path, strict=True)
self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
self.assertRaises(OSError, ntpath.realpath, path, strict=True)
self.assertRaises(OSError, ntpath.realpath, path, strict=ALLOW_MISSING)
path = ABSTFNb + b'\\nonexistent\\x\x00'
self.assertEqual(realpath(path, strict=False), path)
self.assertRaises(OSError, realpath, path, strict=True)
self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
self.assertRaises(OSError, ntpath.realpath, path, strict=True)
self.assertRaises(OSError, ntpath.realpath, path, strict=ALLOW_MISSING)
path = ABSTFN + '\x00\\..'
self.assertEqual(realpath(path, strict=False), os.getcwd())
self.assertEqual(realpath(path, strict=True), os.getcwd())
Expand All @@ -509,11 +510,11 @@ def test_realpath_strict(self):
self.assertEqual(realpath(path, strict=ALLOW_MISSING), os.getcwdb())
path = ABSTFN + '\\nonexistent\\x\x00\\..'
self.assertEqual(realpath(path, strict=False), ABSTFN + '\\nonexistent')
self.assertRaises(OSError, realpath, path, strict=True)
self.assertRaises(OSError, ntpath.realpath, path, strict=True)
self.assertEqual(realpath(path, strict=ALLOW_MISSING), ABSTFN + '\\nonexistent')
path = ABSTFNb + b'\\nonexistent\\x\x00\\..'
self.assertEqual(realpath(path, strict=False), ABSTFNb + b'\\nonexistent')
self.assertRaises(OSError, realpath, path, strict=True)
self.assertRaises(OSError, ntpath.realpath, path, strict=True)
self.assertEqual(realpath(path, strict=ALLOW_MISSING), ABSTFNb + b'\\nonexistent')

@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
Expand All @@ -523,17 +524,17 @@ def test_realpath_invalid_unicode_paths(self, kwargs):
ABSTFN = ntpath.abspath(os_helper.TESTFN)
ABSTFNb = os.fsencode(ABSTFN)
path = ABSTFNb + b'\xff'
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)
path = ABSTFNb + b'\\nonexistent\\\xff'
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)
path = ABSTFNb + b'\xff\\..'
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)
path = ABSTFNb + b'\\nonexistent\\\xff\\..'
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)
self.assertRaises(UnicodeDecodeError, ntpath.realpath, path, **kwargs)

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
Expand Down