-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_legacy_exceptions.py
More file actions
78 lines (66 loc) · 2.81 KB
/
test_legacy_exceptions.py
File metadata and controls
78 lines (66 loc) · 2.81 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Tests for legacy exception import compatibility."""
from __future__ import annotations
def test_legacy_exception_imports():
"""Test that exceptions can be imported from replicate.exceptions."""
# Test importing individual exceptions from replicate.exceptions
# All imports are intentionally kept to test that they can be imported
# Test that imported exceptions are the same as the ones from replicate
import replicate
from replicate.exceptions import (
APIError,
ModelError,
ConflictError, # noqa: F401 # pyright: ignore[reportUnusedImport]
NotFoundError,
APIStatusError, # noqa: F401 # pyright: ignore[reportUnusedImport]
RateLimitError,
ReplicateError,
APITimeoutError,
BadRequestError,
APIConnectionError,
AuthenticationError,
InternalServerError,
PermissionDeniedError, # noqa: F401 # pyright: ignore[reportUnusedImport]
UnprocessableEntityError, # noqa: F401 # pyright: ignore[reportUnusedImport]
APIResponseValidationError, # noqa: F401 # pyright: ignore[reportUnusedImport]
)
assert ModelError is replicate._exceptions.ModelError
assert APIError is replicate.APIError
assert ReplicateError is replicate.ReplicateError
assert BadRequestError is replicate.BadRequestError
assert AuthenticationError is replicate.AuthenticationError
assert NotFoundError is replicate.NotFoundError
assert RateLimitError is replicate.RateLimitError
assert InternalServerError is replicate.InternalServerError
assert APIConnectionError is replicate.APIConnectionError
assert APITimeoutError is replicate.APITimeoutError
def test_readme_example_import():
"""Test that the import pattern shown in README works correctly."""
# This is the exact import pattern shown in the README
import replicate
from replicate.exceptions import ModelError
# Verify ModelError is the correct class
assert ModelError is replicate._exceptions.ModelError
def test_exception_module_all_exports():
"""Test that replicate.exceptions.__all__ contains all expected exceptions."""
import replicate.exceptions
expected_exceptions = [
"APIConnectionError",
"APIError",
"APIResponseValidationError",
"APIStatusError",
"APITimeoutError",
"AuthenticationError",
"BadRequestError",
"ConflictError",
"InternalServerError",
"ModelError",
"NotFoundError",
"PermissionDeniedError",
"RateLimitError",
"ReplicateError",
"UnprocessableEntityError",
]
assert set(replicate.exceptions.__all__) == set(expected_exceptions)
# Also verify they can all be accessed
for exc_name in expected_exceptions:
assert hasattr(replicate.exceptions, exc_name)