Skip to content

Commit 5e2c336

Browse files
authored
Subclass exceptions from standard library exceptions (#38)
1 parent a2199c4 commit 5e2c336

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

dissect/xfs/exceptions.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ class UnsupportedDataforkException(Error):
66
pass
77

88

9-
class FileNotFoundError(Error):
9+
class FileNotFoundError(Error, FileNotFoundError):
1010
pass
1111

1212

13-
class NotADirectoryError(Error):
13+
class IsADirectoryError(Error, IsADirectoryError):
14+
pass
15+
16+
17+
class NotADirectoryError(Error, NotADirectoryError):
1418
pass
1519

1620

tests/test_exceptions.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from dissect.xfs 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)