From 440d8eabd9605fbfbb76a3223830c2081e20c036 Mon Sep 17 00:00:00 2001 From: Kir Chou Date: Mon, 8 Dec 2025 21:51:46 +0900 Subject: [PATCH] Handle more possible Exceptions explicitly. --- Lib/test/test_posixpath.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index a9975b75f7c22b..f54aa1c371fd1b 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -506,13 +506,13 @@ def test_realpath_invalid_paths(self): self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) path = '/nonexistent/x\x00' self.assertRaises(ValueError, realpath, path, strict=False) - self.assertRaises(FileNotFoundError, realpath, path, strict=ALL_BUT_LAST) - self.assertRaises(FileNotFoundError, realpath, path, strict=True) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=ALL_BUT_LAST) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=True) self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) path = b'/nonexistent/x\x00' self.assertRaises(ValueError, realpath, path, strict=False) - self.assertRaises(FileNotFoundError, realpath, path, strict=ALL_BUT_LAST) - self.assertRaises(FileNotFoundError, realpath, path, strict=True) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=ALL_BUT_LAST) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=True) self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) path = '/\x00/..' self.assertRaises(ValueError, realpath, path, strict=False) @@ -527,13 +527,13 @@ def test_realpath_invalid_paths(self): path = '/nonexistent/x\x00/..' self.assertRaises(ValueError, realpath, path, strict=False) - self.assertRaises(FileNotFoundError, realpath, path, strict=ALL_BUT_LAST) - self.assertRaises(FileNotFoundError, realpath, path, strict=True) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=ALL_BUT_LAST) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=True) self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) path = b'/nonexistent/x\x00/..' self.assertRaises(ValueError, realpath, path, strict=False) - self.assertRaises(FileNotFoundError, realpath, path, strict=ALL_BUT_LAST) - self.assertRaises(FileNotFoundError, realpath, path, strict=True) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=ALL_BUT_LAST) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=True) self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) path = '/\udfff' @@ -553,8 +553,8 @@ def test_realpath_invalid_paths(self): else: self.assertRaises(UnicodeEncodeError, realpath, path, strict=False) self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING) - self.assertRaises(FileNotFoundError, realpath, path, strict=ALL_BUT_LAST) - self.assertRaises(FileNotFoundError, realpath, path, strict=True) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=ALL_BUT_LAST) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=True) path = '/\udfff/..' if sys.platform == 'win32': self.assertEqual(realpath(path, strict=False), '/') @@ -572,8 +572,8 @@ def test_realpath_invalid_paths(self): else: self.assertRaises(UnicodeEncodeError, realpath, path, strict=False) self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING) - self.assertRaises(FileNotFoundError, realpath, path, strict=ALL_BUT_LAST) - self.assertRaises(FileNotFoundError, realpath, path, strict=True) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=ALL_BUT_LAST) + self.assertRaises((FileNotFoundError, ValueError), realpath, path, strict=True) path = b'/\xff' if sys.platform == 'win32':