Spaces:
Sleeping
Sleeping
File size: 1,856 Bytes
7c87115 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | """Tests for services.errors module."""
import pytest
from notebooklm_tools.services.errors import (
ServiceError,
ValidationError,
NotFoundError,
CreationError,
ExportError,
)
class TestServiceError:
"""Test the base ServiceError class."""
def test_basic_message(self):
err = ServiceError("something broke")
assert str(err) == "something broke"
assert err.user_message == "something broke"
assert err.debug_code is None
def test_custom_user_message(self):
err = ServiceError(
"Internal: API returned 500",
user_message="Export failed, please try again.",
)
assert str(err) == "Internal: API returned 500"
assert err.user_message == "Export failed, please try again."
def test_debug_code(self):
err = ServiceError(
"fail",
debug_code="EXPORT_NO_URL",
)
assert err.debug_code == "EXPORT_NO_URL"
def test_user_message_defaults_to_message(self):
err = ServiceError("same message")
assert err.user_message == "same message"
class TestErrorHierarchy:
"""Ensure all errors inherit from ServiceError."""
@pytest.mark.parametrize("error_class", [
ValidationError,
NotFoundError,
CreationError,
ExportError,
])
def test_inherits_from_service_error(self, error_class):
err = error_class("test")
assert isinstance(err, ServiceError)
assert isinstance(err, Exception)
@pytest.mark.parametrize("error_class", [
ValidationError,
NotFoundError,
CreationError,
ExportError,
])
def test_subclass_preserves_user_message(self, error_class):
err = error_class("internal", user_message="user-facing")
assert err.user_message == "user-facing"
|