|
1 | | -try: |
2 | | - from . import generic as g |
3 | | -except BaseException: |
4 | | - import generic as g |
5 | | - |
6 | | - |
7 | | -class ExceptionsTest(g.unittest.TestCase): |
8 | | - def test_module(self): |
9 | | - # create an ExceptionWrapper |
10 | | - try: |
11 | | - raise ValueError("nah") |
12 | | - except BaseException as E: |
13 | | - em = g.trimesh.exceptions.ExceptionWrapper(E) |
14 | | - |
15 | | - # checking isinstance should always return false |
16 | | - # and NOT raise the error |
17 | | - assert not isinstance(em, dict) |
18 | | - |
19 | | - try: |
20 | | - # should re-raise `ValueError('nah')` |
21 | | - em.hi() |
22 | | - # if we're here raise an error we don't catch |
23 | | - raise NameError("should not have worked!!") |
24 | | - except ValueError: |
25 | | - # should have re-raised ValueError |
26 | | - pass |
| 1 | +def test_exception_wrapper(): |
| 2 | + # check our exception wrapping behavior |
| 3 | + from trimesh.exceptions import ExceptionWrapper |
| 4 | + |
| 5 | + try: |
| 6 | + # create a wrapper around a ValueError |
| 7 | + raise ValueError("This should be wrapped!") |
| 8 | + except BaseException as E: |
| 9 | + wrapper = ExceptionWrapper(E) |
| 10 | + |
| 11 | + # `isinstance` should NOT raise the error that's been wrapped |
| 12 | + assert not isinstance(wrapper, dict) |
| 13 | + |
| 14 | + # but we should be able to tell that it is wrapping something |
| 15 | + assert isinstance(wrapper, ExceptionWrapper) |
| 16 | + |
| 17 | + try: |
| 18 | + # check the __getattribute__ path |
| 19 | + wrapper.hi() |
| 20 | + |
| 21 | + # we wrapped something incorrectly if we got here! |
| 22 | + raise NameError("__getattribute__ should have raised a ValueError!") |
| 23 | + except ValueError: |
| 24 | + # should have re-raised ValueError |
| 25 | + pass |
| 26 | + |
| 27 | + try: |
| 28 | + # check the __call__ path |
| 29 | + wrapper() |
| 30 | + |
| 31 | + # we wrapped something incorrectly if we got here! |
| 32 | + raise NameError("__call__ should have raised a ValueError!") |
| 33 | + |
| 34 | + except ValueError: |
| 35 | + # this is correct |
| 36 | + pass |
27 | 37 |
|
28 | 38 |
|
29 | 39 | if __name__ == "__main__": |
30 | | - g.trimesh.util.attach_to_log() |
31 | | - g.unittest.main() |
| 40 | + test_exception_wrapper() |
0 commit comments