Skip to content

Commit

Permalink
Subclass exceptions from standard library exceptions (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Nov 1, 2024
1 parent c8cb71e commit 9b0df29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dissect/extfs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ class Error(Exception):
pass


class FileNotFoundError(Error):
class FileNotFoundError(Error, FileNotFoundError):
pass


class NotADirectoryError(Error):
class IsADirectoryError(Error, IsADirectoryError):
pass


class NotADirectoryError(Error, NotADirectoryError):
pass


Expand Down
19 changes: 19 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from dissect.extfs import exceptions


@pytest.mark.parametrize(
"exc, std",
[
(exceptions.FileNotFoundError, FileNotFoundError),
(exceptions.IsADirectoryError, IsADirectoryError),
(exceptions.NotADirectoryError, NotADirectoryError),
],
)
def test_filesystem_error_subclass(exc: exceptions.Error, std: Exception) -> None:
assert issubclass(exc, std)
assert isinstance(exc(), std)

with pytest.raises(std):
raise exc()

0 comments on commit 9b0df29

Please sign in to comment.