From a48feba2ed2ea785b626a2718e9d175cfd9045be Mon Sep 17 00:00:00 2001 From: Schamper <1254028+Schamper@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:07:34 +0100 Subject: [PATCH] Subclass exceptions from standard library exceptions --- dissect/ntfs/exceptions.py | 8 ++++++-- tests/test_exceptions.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/test_exceptions.py diff --git a/dissect/ntfs/exceptions.py b/dissect/ntfs/exceptions.py index d5b2371..ae560af 100644 --- a/dissect/ntfs/exceptions.py +++ b/dissect/ntfs/exceptions.py @@ -14,7 +14,7 @@ class FilenameNotAvailableError(Error): pass -class FileNotFoundError(Error): +class FileNotFoundError(Error, FileNotFoundError): pass @@ -22,7 +22,11 @@ class MftNotAvailableError(Error): pass -class NotADirectoryError(Error): +class IsADirectoryError(Error, IsADirectoryError): + pass + + +class NotADirectoryError(Error, NotADirectoryError): pass diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 0000000..6f1d857 --- /dev/null +++ b/tests/test_exceptions.py @@ -0,0 +1,19 @@ +import pytest + +from dissect.ntfs 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()