Skip to content

Commit f839db0

Browse files
committed
Add tests
1 parent bf3a3f7 commit f839db0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Lib/test/test_ntpath.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ def test_realpath_basic(self):
269269
self.assertPathEqual(ntpath.realpath(os.fsencode(ABSTFN + "1")),
270270
os.fsencode(ABSTFN))
271271

272+
@unittest.skipUnless(hasattr(os, "symlink"),
273+
"Missing symlink implementation")
274+
@skip_if_ABSTFN_contains_backslash
275+
def test_realpath_strict(self):
276+
# Bug #43757: raise FileNotFoundError in strict mode if we encounter
277+
# a path that does not exist.
278+
ABSTFN = ntpath.abspath(os_helper.TESTFN)
279+
os.symlink(ABSTFN + "1", ABSTFN)
280+
self.addCleanup(os_helper.unlink, ABSTFN)
281+
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN, strict=True)
282+
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN + "2", strict=True)
283+
272284
@os_helper.skip_unless_symlink
273285
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
274286
def test_realpath_relative(self):

Lib/test/test_posixpath.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,19 @@ def test_realpath_basic(self):
355355
finally:
356356
os_helper.unlink(ABSTFN)
357357

358+
@unittest.skipUnless(hasattr(os, "symlink"),
359+
"Missing symlink implementation")
360+
@skip_if_ABSTFN_contains_backslash
361+
def test_realpath_strict(self):
362+
# Bug #43757: raise FileNotFoundError in strict mode if we encounter
363+
# a path that does not exist.
364+
try:
365+
os.symlink(ABSTFN+"1", ABSTFN)
366+
self.assertRaises(FileNotFoundError, realpath, ABSTFN, strict=True)
367+
self.assertRaises(FileNotFoundError, realpath, ABSTFN + "2", strict=True)
368+
finally:
369+
os_helper.unlink(ABSTFN)
370+
358371
@unittest.skipUnless(hasattr(os, "symlink"),
359372
"Missing symlink implementation")
360373
@skip_if_ABSTFN_contains_backslash

0 commit comments

Comments
 (0)