Skip to content

Commit fe9d7dc

Browse files
authored
Subclass exceptions from standard library exceptions (#29)
1 parent 522bd7c commit fe9d7dc

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

dissect/fat/exceptions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ class InvalidDirectoryError(Error):
3030
pass
3131

3232

33-
class FileNotFoundError(Error):
33+
class FileNotFoundError(Error, FileNotFoundError):
3434
pass
3535

3636

37-
class NotADirectoryError(Error):
37+
class IsADirectoryError(Error, IsADirectoryError):
38+
pass
39+
40+
41+
class NotADirectoryError(Error, NotADirectoryError):
3842
pass

tests/test_exceptions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from dissect.fat import exceptions
4+
5+
6+
@pytest.mark.parametrize(
7+
"exc, std",
8+
[
9+
(exceptions.FileNotFoundError, FileNotFoundError),
10+
(exceptions.IsADirectoryError, IsADirectoryError),
11+
(exceptions.NotADirectoryError, NotADirectoryError),
12+
],
13+
)
14+
def test_filesystem_error_subclass(exc: exceptions.Error, std: Exception) -> None:
15+
assert issubclass(exc, std)
16+
assert isinstance(exc(), std)
17+
18+
with pytest.raises(std):
19+
raise exc()

0 commit comments

Comments
 (0)