Skip to content

Commit

Permalink
Subclass exceptions from standard library exceptions (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Nov 1, 2024
1 parent d021f6b commit 16bc3de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dissect/squashfs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ class Error(Exception):
pass


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


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


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


class FileNotFoundError(Error):
class NotAFileError(Error):
pass


class NotASymlinkError(Error):
pass
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.squashfs 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 16bc3de

Please sign in to comment.