|
| 1 | +"""Tests for UiPath trigger error classes.""" |
| 2 | + |
| 3 | +from uipath.core.errors import ( |
| 4 | + ErrorCategory, |
| 5 | + UiPathFaultedTriggerError, |
| 6 | + UiPathPendingTriggerError, |
| 7 | +) |
| 8 | + |
| 9 | + |
| 10 | +class TestUiPathFaultedTriggerError: |
| 11 | + """Test UiPathFaultedTriggerError constructor and behavior.""" |
| 12 | + |
| 13 | + def test_init_with_detail(self) -> None: |
| 14 | + """Test that category, message, and detail are stored and str includes both.""" |
| 15 | + err = UiPathFaultedTriggerError( |
| 16 | + category=ErrorCategory.USER, |
| 17 | + message="Something failed", |
| 18 | + detail="missing input", |
| 19 | + ) |
| 20 | + assert err.category == ErrorCategory.USER |
| 21 | + assert err.message == "Something failed" |
| 22 | + assert err.detail == "missing input" |
| 23 | + assert str(err) == "Something failed: missing input" |
| 24 | + |
| 25 | + def test_init_without_detail(self) -> None: |
| 26 | + """Test that detail defaults to empty string and str is just the message.""" |
| 27 | + err = UiPathFaultedTriggerError( |
| 28 | + category=ErrorCategory.SYSTEM, |
| 29 | + message="Internal error", |
| 30 | + ) |
| 31 | + assert err.category == ErrorCategory.SYSTEM |
| 32 | + assert err.message == "Internal error" |
| 33 | + assert err.detail == "" |
| 34 | + assert str(err) == "Internal error" |
| 35 | + |
| 36 | + def test_is_exception(self) -> None: |
| 37 | + """Test that the error can be raised and caught as an Exception.""" |
| 38 | + with __import__("pytest").raises(UiPathFaultedTriggerError, match="boom"): |
| 39 | + raise UiPathFaultedTriggerError( |
| 40 | + category=ErrorCategory.DEPLOYMENT, |
| 41 | + message="boom", |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +class TestUiPathPendingTriggerError: |
| 46 | + """Test UiPathPendingTriggerError inherits correctly.""" |
| 47 | + |
| 48 | + def test_inherits_faulted_trigger_error(self) -> None: |
| 49 | + """Test that PendingTriggerError is a subclass of FaultedTriggerError.""" |
| 50 | + err = UiPathPendingTriggerError( |
| 51 | + category=ErrorCategory.UNKNOWN, |
| 52 | + message="Pending", |
| 53 | + detail="waiting for response", |
| 54 | + ) |
| 55 | + assert isinstance(err, UiPathFaultedTriggerError) |
| 56 | + assert err.category == ErrorCategory.UNKNOWN |
| 57 | + assert str(err) == "Pending: waiting for response" |
| 58 | + |
| 59 | + def test_catchable_as_faulted(self) -> None: |
| 60 | + """Test that PendingTriggerError can be caught as FaultedTriggerError.""" |
| 61 | + with __import__("pytest").raises(UiPathFaultedTriggerError): |
| 62 | + raise UiPathPendingTriggerError( |
| 63 | + category=ErrorCategory.USER, |
| 64 | + message="still pending", |
| 65 | + ) |
0 commit comments