-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Allow exceptions to pass into
convert_exception_to_primitives
- Loading branch information
1 parent
6c2702c
commit d574b5a
Showing
2 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import unittest | ||
|
||
from octue.utils.exceptions import convert_exception_to_primitives | ||
|
||
|
||
class TestExceptions(unittest.TestCase): | ||
def test_with_caught_exception(self): | ||
"""Test converting a caught exception (without passing the exception directly).""" | ||
try: | ||
raise ValueError("Deliberately raised for test.") | ||
except Exception: | ||
converted_exception = convert_exception_to_primitives() | ||
|
||
self.assertEqual(converted_exception["type"], "ValueError") | ||
self.assertEqual(converted_exception["message"], "Deliberately raised for test.") | ||
|
||
self.assertIn( | ||
'in test_with_raised_exception\n raise ValueError("Deliberately raised for test.")', | ||
converted_exception["traceback"][0], | ||
) | ||
|
||
def test_with_passed_unraised_exception(self): | ||
"""Test converting an unraised exception passed in to the function.""" | ||
exception = ValueError("Deliberately raised for test.") | ||
converted_exception = convert_exception_to_primitives(exception) | ||
|
||
self.assertEqual(converted_exception["type"], "ValueError") | ||
self.assertEqual(converted_exception["message"], "Deliberately raised for test.") | ||
self.assertIn("in convert_exception_to_primitives\n raise exception", converted_exception["traceback"][0]) |