Co-authored-by: Alexander Whitestone <alexander@alexanderwhitestone.com> Co-committed-by: Alexander Whitestone <alexander@alexanderwhitestone.com>
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
"""
|
|
Tests for error classification (#752).
|
|
"""
|
|
|
|
import pytest
|
|
from tools.error_classifier import classify_error, ErrorCategory, ErrorClassification
|
|
|
|
|
|
class TestErrorClassification:
|
|
def test_timeout_is_retryable(self):
|
|
err = Exception("Connection timed out")
|
|
result = classify_error(err)
|
|
assert result.category == ErrorCategory.RETRYABLE
|
|
assert result.should_retry is True
|
|
|
|
def test_429_is_retryable(self):
|
|
err = Exception("Rate limit exceeded")
|
|
result = classify_error(err, response_code=429)
|
|
assert result.category == ErrorCategory.RETRYABLE
|
|
assert result.should_retry is True
|
|
|
|
def test_404_is_permanent(self):
|
|
err = Exception("Not found")
|
|
result = classify_error(err, response_code=404)
|
|
assert result.category == ErrorCategory.PERMANENT
|
|
assert result.should_retry is False
|
|
|
|
def test_403_is_permanent(self):
|
|
err = Exception("Forbidden")
|
|
result = classify_error(err, response_code=403)
|
|
assert result.category == ErrorCategory.PERMANENT
|
|
assert result.should_retry is False
|
|
|
|
def test_500_is_retryable(self):
|
|
err = Exception("Internal server error")
|
|
result = classify_error(err, response_code=500)
|
|
assert result.category == ErrorCategory.RETRYABLE
|
|
assert result.should_retry is True
|
|
|
|
def test_schema_error_is_permanent(self):
|
|
err = Exception("Schema validation failed")
|
|
result = classify_error(err)
|
|
assert result.category == ErrorCategory.PERMANENT
|
|
assert result.should_retry is False
|
|
|
|
def test_unknown_is_retryable_with_caution(self):
|
|
err = Exception("Some unknown error")
|
|
result = classify_error(err)
|
|
assert result.category == ErrorCategory.UNKNOWN
|
|
assert result.should_retry is True
|
|
assert result.max_retries == 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__])
|