Skip to content

Commit

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


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


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


class NotADirectoryError(Error):
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.btrfs 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 fe4bbda

Please sign in to comment.