PageIndex/tests/test_errors.py

30 lines
893 B
Python
Raw Normal View History

from pageindex.errors import (
PageIndexError,
2026-05-11 21:06:23 +08:00
PageIndexAPIError,
CollectionNotFoundError,
DocumentNotFoundError,
IndexingError,
CloudAPIError,
FileTypeError,
)
def test_all_errors_inherit_from_base():
2026-05-11 21:06:23 +08:00
for cls in [PageIndexAPIError, CollectionNotFoundError, DocumentNotFoundError, IndexingError, CloudAPIError, FileTypeError]:
assert issubclass(cls, PageIndexError)
assert issubclass(cls, Exception)
2026-05-11 21:06:23 +08:00
assert issubclass(CloudAPIError, PageIndexAPIError)
def test_error_message():
err = FileTypeError("Unsupported: .docx")
assert str(err) == "Unsupported: .docx"
def test_catch_base_catches_all():
2026-05-11 21:06:23 +08:00
for cls in [PageIndexAPIError, CollectionNotFoundError, DocumentNotFoundError, IndexingError, CloudAPIError, FileTypeError]:
try:
raise cls("test")
except PageIndexError:
pass # expected