Skip to content

Commit fe4bbda

Browse files
authored
Subclass exceptions from standard library exceptions (#18)
1 parent 01cbab3 commit fe4bbda

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

dissect/btrfs/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ class Error(Exception):
22
pass
33

44

5-
class FileNotFoundError(Error):
5+
class FileNotFoundError(Error, FileNotFoundError):
66
pass
77

88

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

1212

13-
class NotADirectoryError(Error):
13+
class NotADirectoryError(Error, NotADirectoryError):
1414
pass
1515

1616

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.btrfs 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)