Skip to content
Prev Previous commit
Next Next commit
tests: Expect OSError -- we can get PermissionError instead of IsADir…
…ectoryError
  • Loading branch information
encukou committed Mar 12, 2024
commit 917661909d80d0368e44bf65e0cb94d17610e6f2
14 changes: 9 additions & 5 deletions Lib/test/test_importlib/resources/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ def test_read_text(self):
),
'a resource',
)
with self.assertRaises(IsADirectoryError):
# Use generic OSError, since e.g. attempting to read a directory can
# fail with PermissionError rather than IsADirectoryError
with self.assertRaises(OSError):
importlib.resources.read_text(self.anchor01)
with self.assertRaises(FileNotFoundError):
with self.assertRaises(OSError):
importlib.resources.read_text(self.anchor01, 'no-such-file')
with self.assertRaises(UnicodeDecodeError):
importlib.resources.read_text(self.anchor01, 'utf-16.file')
Expand Down Expand Up @@ -75,9 +77,11 @@ def test_open_text(self):
encoding='utf-8',
) as f:
self.assertEqual(f.read(), 'a resource')
with self.assertRaises(IsADirectoryError):
# Use generic OSError, since e.g. attempting to read a directory can
# fail with PermissionError rather than IsADirectoryError
with self.assertRaises(OSError):
importlib.resources.open_text(self.anchor01)
with self.assertRaises(FileNotFoundError):
with self.assertRaises(OSError):
importlib.resources.open_text(self.anchor01, 'no-such-file')
with importlib.resources.open_text(self.anchor01, 'utf-16.file') as f:
with self.assertRaises(UnicodeDecodeError):
Expand Down Expand Up @@ -128,7 +132,7 @@ def test_contents(self):
set(c),
{'utf-8.file', 'utf-16.file', 'binary.file', 'subdirectory'},
)
with (self.assertRaises(NotADirectoryError),
with (self.assertRaises(OSError),
check_warnings((".*contents.*", DeprecationWarning)),
):
importlib.resources.contents(self.anchor01, 'utf-8.file')
Expand Down