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 6046474 commit 13e1c48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dissect/vmfs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ class InvalidHeader(Error):
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.vmfs 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 13e1c48

Please sign in to comment.